|
21 | 21 | import java.util.List; |
22 | 22 |
|
23 | 23 | import com.javadocmd.simplelatlng.LatLng; |
24 | | -import com.javadocmd.simplelatlng.LatLngTool; |
25 | 24 | import com.javadocmd.simplelatlng.util.LatLngConfig; |
26 | 25 | import com.javadocmd.simplelatlng.util.LengthUnit; |
27 | 26 |
|
| 27 | +import static com.javadocmd.simplelatlng.LatLngTool.distanceInRadians; |
| 28 | + |
28 | 29 | /** |
29 | 30 | * <p> |
30 | 31 | * A circular window. Has the benefit of performing well around poles and |
@@ -105,30 +106,34 @@ public <E> void filterCopySort(Collection<E> source, Collection<E> destination, |
105 | 106 | } |
106 | 107 | } |
107 | 108 |
|
| 109 | + private long toDegreesInternal(Double radians) { |
| 110 | + // When converting a radian distance to the internal degrees representation |
| 111 | + // for the sake of comparison, rounding the result seems to be appropriate. |
| 112 | + return Math.round(Math.toDegrees(radians) / LatLngConfig.DEGREE_TOLERANCE); |
| 113 | + } |
| 114 | + |
108 | 115 | /** |
109 | 116 | * A specialized implementation of the {@link #contains(LatLng)} check which |
110 | 117 | * returns the distance from the center of the window if the window contains |
111 | 118 | * the point and null if it does not. Used in |
112 | 119 | * {@link #filterCopySort(Collection, Collection, FilterHelper)}. |
113 | 120 | */ |
114 | 121 | private Double containsForSort(LatLng point) { |
115 | | - double d = Math.toDegrees(LatLngTool.distanceInRadians(center, point)); |
116 | | - if (LatLngConfig.doubleToLong(d) <= radius) |
| 122 | + double d = distanceInRadians(center, point); |
| 123 | + if (toDegreesInternal(d) <= radius) |
117 | 124 | return d; |
118 | 125 | else |
119 | 126 | return null; |
120 | 127 | } |
121 | 128 |
|
122 | 129 | @Override |
123 | 130 | public boolean contains(LatLng point) { |
124 | | - return LatLngConfig |
125 | | - .doubleToLong(Math.toDegrees(LatLngTool.distanceInRadians(center, point))) <= radius; |
| 131 | + return toDegreesInternal(distanceInRadians(center, point)) <= radius; |
126 | 132 | } |
127 | 133 |
|
128 | 134 | @Override |
129 | 135 | public boolean overlaps(CircularWindow window) { |
130 | | - long angle = LatLngConfig.doubleToLong(Math.toDegrees(LatLngTool.distanceInRadians( |
131 | | - this.center, window.getCenter()))); |
| 136 | + long angle = toDegreesInternal(distanceInRadians(this.center, window.getCenter())); |
132 | 137 | return angle <= (this.radius + window.radius); |
133 | 138 | } |
134 | 139 |
|
|
0 commit comments