X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fdata%2FLatLonRectangle.java;fp=src%2Ftim%2Fprune%2Fdata%2FLatLonRectangle.java;h=0aeb1c8565ab1d2bc9a483dd24e190a4629d23e6;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/data/LatLonRectangle.java b/src/tim/prune/data/LatLonRectangle.java new file mode 100644 index 0000000..0aeb1c8 --- /dev/null +++ b/src/tim/prune/data/LatLonRectangle.java @@ -0,0 +1,50 @@ +package tim.prune.data; + +/** + * Class to hold a rectangle of latitude/longitude + * with minimum and maximum values for each + */ +public class LatLonRectangle +{ + private DoubleRange _latRange = null; + private DoubleRange _lonRange = null; + + + /** + * Constructor + * @param inLatRange latitude range + * @param inLonRange longitude range + */ + public LatLonRectangle(DoubleRange inLatRange, DoubleRange inLonRange) + { + _latRange = inLatRange; + _lonRange = inLonRange; + // MAYBE: Expand range by certain percentage + } + + /** + * @return true if the range is empty + */ + public boolean isEmpty() + { + return _latRange == null || _lonRange == null + || !_latRange.hasData() || !_lonRange.hasData(); + } + + /** + * Check if a point is within the rectangle + * @param inPoint point to check + * @return true if point within rectangle + */ + public boolean containsPoint(DataPoint inPoint) + { + if (inPoint != null && !isEmpty()) + { + double pointLat = inPoint.getLatitude().getDouble(); + double pointLon = inPoint.getLongitude().getDouble(); + return (pointLat >= _latRange.getMinimum() && pointLat <= _latRange.getMaximum() + && pointLon >= _lonRange.getMinimum() && pointLon <= _lonRange.getMaximum()); + } + return false; + } +}