]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/LatLonRectangle.java
Version 6, October 2008
[GpsPrune.git] / tim / prune / data / LatLonRectangle.java
1 package tim.prune.data;
2
3 /**
4  * Class to hold a rectangle of latitude/longitude
5  * with minimum and maximum values for each
6  */
7 public class LatLonRectangle
8 {
9         private DoubleRange _latRange = null;
10         private DoubleRange _lonRange = null;
11
12
13         /**
14          * Constructor
15          * @param inLatRange latitude range
16          * @param inLonRange longitude range
17          */
18         public LatLonRectangle(DoubleRange inLatRange, DoubleRange inLonRange)
19         {
20                 _latRange = inLatRange;
21                 _lonRange = inLonRange;
22                 // TODO: Expand range by certain percentage
23         }
24
25         /**
26          * @return true if the range is empty
27          */
28         public boolean isEmpty()
29         {
30                 return _latRange == null || _lonRange == null
31                         || !_latRange.hasData() || !_lonRange.hasData();
32         }
33
34         /**
35          * Check if a point is within the rectangle
36          * @param inPoint point to check
37          * @return true if point within rectangle
38          */
39         public boolean containsPoint(DataPoint inPoint)
40         {
41                 if (inPoint != null && !isEmpty())
42                 {
43                         double pointLat = inPoint.getLatitude().getDouble();
44                         double pointLon = inPoint.getLongitude().getDouble();
45                         return (pointLat >= _latRange.getMinimum() && pointLat <= _latRange.getMaximum()
46                                 && pointLon >= _lonRange.getMinimum() && pointLon <= _lonRange.getMaximum());
47                 }
48                 return false;
49         }
50 }