File: LatLonRectangle.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (50 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
	}
}