View Javadoc
1   package au.gov.amsa.navigation;
2   
3   import com.google.common.base.Preconditions;
4   
5   public class Region {
6   
7   	private final double topLeftLat, topLeftLon, bottomRightLat, bottomRightLon;
8   
9   	public Region(double topLeftLat, double topLeftLon, double bottomLeftLat,
10  			double bottomRightLon) {
11  		Preconditions.checkArgument(bottomLeftLat <= topLeftLat);
12  		Preconditions.checkArgument(topLeftLon <= bottomRightLon);
13  		this.topLeftLat = topLeftLat;
14  		this.topLeftLon = topLeftLon;
15  		this.bottomRightLat = bottomLeftLat;
16  		this.bottomRightLon = bottomRightLon;
17  	}
18  
19  	public double topLeftLat() {
20  		return topLeftLat;
21  	}
22  
23  	public double topLeftLon() {
24  		return topLeftLon;
25  	}
26  
27  	public double bottomRightLat() {
28  		return bottomRightLat;
29  	}
30  
31  	public double bottomRightLon() {
32  		return bottomRightLon;
33  	}
34  
35  	public boolean inRegion(double lat, double lon) {
36  		return lat >= bottomRightLat && lat <= topLeftLat && lon >= topLeftLon
37  				&& lon <= bottomRightLon;
38  	}
39  
40  	@Override
41  	public int hashCode() {
42  		final int prime = 31;
43  		int result = 1;
44  		long temp;
45  		temp = Double.doubleToLongBits(bottomRightLat);
46  		result = prime * result + (int) (temp ^ (temp >>> 32));
47  		temp = Double.doubleToLongBits(bottomRightLon);
48  		result = prime * result + (int) (temp ^ (temp >>> 32));
49  		temp = Double.doubleToLongBits(topLeftLat);
50  		result = prime * result + (int) (temp ^ (temp >>> 32));
51  		temp = Double.doubleToLongBits(topLeftLon);
52  		result = prime * result + (int) (temp ^ (temp >>> 32));
53  		return result;
54  	}
55  
56  	@Override
57  	public boolean equals(Object obj) {
58  		if (this == obj)
59  			return true;
60  		if (obj == null)
61  			return false;
62  		if (getClass() != obj.getClass())
63  			return false;
64  		Region other = (Region) obj;
65  		if (Double.doubleToLongBits(bottomRightLat) != Double
66  				.doubleToLongBits(other.bottomRightLat))
67  			return false;
68  		if (Double.doubleToLongBits(bottomRightLon) != Double
69  				.doubleToLongBits(other.bottomRightLon))
70  			return false;
71  		if (Double.doubleToLongBits(topLeftLat) != Double
72  				.doubleToLongBits(other.topLeftLat))
73  			return false;
74  		if (Double.doubleToLongBits(topLeftLon) != Double
75  				.doubleToLongBits(other.topLeftLon))
76  			return false;
77  		return true;
78  	}
79  	
80  }