X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FDoubleRange.java;h=3f252eed6cd2bcfe00bcdc272c2f1f82404dcbba;hb=326f489e36aa7f235bc19409a57bf4955cd50f24;hp=f241d4d13470eb1b5e1feb60cdab5d22b686d5b8;hpb=d3679d647d57c2ee7376ddbf6def2d5b23c04307;p=GpsPrune.git diff --git a/tim/prune/data/DoubleRange.java b/tim/prune/data/DoubleRange.java index f241d4d..3f252ee 100644 --- a/tim/prune/data/DoubleRange.java +++ b/tim/prune/data/DoubleRange.java @@ -10,6 +10,20 @@ public class DoubleRange private double _min = 0.0, _max = 0.0; + /** Empty constructor, cleared to zeroes */ + public DoubleRange() {} + + /** + * Constructor giving two initial values + * @param inValue1 first value + * @param inValue2 second value + */ + public DoubleRange(double inValue1, double inValue2) + { + addValue(inValue1); + addValue(inValue2); + } + /** * Clear for a new calculation */ @@ -31,6 +45,18 @@ public class DoubleRange _empty = false; } + /** + * Combine this range with another one + * @param inOtherRange other range to add to this one + */ + public void combine(DoubleRange inOtherRange) + { + if (inOtherRange != null && inOtherRange.getRange() > 1.0) + { + addValue(inOtherRange.getMinimum()); + addValue(inOtherRange.getMaximum()); + } + } /** * @return true if data values were found @@ -57,4 +83,30 @@ public class DoubleRange { return _max; } + + /** + * @return range, as maximum - minimum + */ + public double getRange() + { + return _max - _min; + } + + /** + * @return mid value, halfway between min and max + */ + public double getMidValue() + { + return (_max + _min) / 2.0; + } + + /** + * Copy this range into a new object, which can then be modified without changing this one + * @return deep copy of this object + */ + public DoubleRange copy() + { + if (_empty) return new DoubleRange(); + return new DoubleRange(_min, _max); + } }