X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fdata%2FTrackExtents.java;fp=src%2Ftim%2Fprune%2Fdata%2FTrackExtents.java;h=0bf308172ceee02763bfe79f1a8f837db130bdd5;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/data/TrackExtents.java b/src/tim/prune/data/TrackExtents.java new file mode 100644 index 0000000..0bf3081 --- /dev/null +++ b/src/tim/prune/data/TrackExtents.java @@ -0,0 +1,103 @@ +package tim.prune.data; + +/** + * Class to hold the extents of a track, in 2d and in 3d, + * and to calculate a square area with a default border + */ +public class TrackExtents +{ + /** Track object */ + private Track _track = null; + /** X and Y ranges */ + private DoubleRange _xRange = null, _yRange = null; + + /** Border multiplier */ + private static final double BORDER_MULTIPLIER = 1.1; // 10% border + + /** + * Constructor + * @param inTrack track object to take extents from + */ + public TrackExtents(Track inTrack) + { + _track = inTrack; + _xRange = inTrack.getXRange().copy(); + _yRange = inTrack.getYRange().copy(); + } + + + /** + * Make the x and y ranges square with a default border around + */ + public void applySquareBorder() + { + // Find the middle of the x and y + final double midXvalue = _xRange.getMidValue(); + final double midYvalue = _yRange.getMidValue(); + // Find x and y range, take maximum + double xyRange = Math.max(_xRange.getRange(), _yRange.getRange()) * BORDER_MULTIPLIER; + if (getHorizontalDistanceMetres() < 10.0) + { + // all the points are near enough on the same spot, expand scale to avoid dividing by zero + xyRange = 0.1; + } + + // Apply these new min and max to the ranges + _xRange.addValue(midXvalue - xyRange / 2.0); + _xRange.addValue(midXvalue + xyRange / 2.0); + _yRange.addValue(midYvalue - xyRange / 2.0); + _yRange.addValue(midYvalue + xyRange / 2.0); + } + + /** @return x range */ + public DoubleRange getXRange() { + return _xRange; + } + + /** @return y range */ + public DoubleRange getYRange() { + return _yRange; + } + + /** @return altitude range */ + public DoubleRange getAltitudeRange() + { + final int numPoints = _track.getNumPoints(); + DoubleRange altRange = new DoubleRange(); + for (int i=0; i