Skip to content

Commit 0adc2ef

Browse files
Copilotanidotnet
andcommitted
Add comprehensive documentation linking to issue #1126
- Enhanced JavaDoc in GeodesicUtils explaining auto-detection limitations - Added references to issue #1126 for future enhancements - Documented known limitations (false positives, auto-detection ambiguity) - Added TODO comments for two-pass filtering improvement - Clarified that this is an interim solution pending full #1126 implementation Co-authored-by: anidotnet <[email protected]>
1 parent 00bbff4 commit 0adc2ef

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

nitrite-spatial/src/main/java/org/dizitart/no2/spatial/GeodesicUtils.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
* Utility class for geodesic distance calculations on Earth's surface.
2525
* This class handles the conversion between meters and degrees of latitude/longitude,
2626
* accounting for the curvature of the Earth using the WGS84 ellipsoid model.
27+
*
28+
* <p><strong>Note:</strong> This is an interim implementation. A future enhancement
29+
* (see <a href="https://github.com/nitrite/nitrite-java/issues/1126">issue #1126</a>)
30+
* will introduce explicit GeoPoint types and separate GeoNearFilter to provide better
31+
* type safety and avoid the ambiguity of auto-detection.</p>
2732
*
2833
* @since 4.0
2934
* @author Anindya Chatterjee
@@ -36,6 +41,17 @@ class GeodesicUtils {
3641
* This is a heuristic check based on valid lat/long ranges:
3742
* - Latitude: -90 to 90
3843
* - Longitude: -180 to 180
44+
*
45+
* <p><strong>Limitation:</strong> This heuristic may incorrectly classify:</p>
46+
* <ul>
47+
* <li>Cartesian coordinates that happen to fall within ±90°/±180° range
48+
* (e.g., game world or CAD coordinates)</li>
49+
* <li>Invalid geographic coordinates (e.g., lat=0, lon=200 would pass the check
50+
* but lon=200, lat=0 would fail)</li>
51+
* </ul>
52+
*
53+
* <p>A future enhancement will use explicit GeoPoint types to avoid this ambiguity.
54+
* See <a href="https://github.com/nitrite/nitrite-java/issues/1126">issue #1126</a>.</p>
3955
*
4056
* @param center the coordinate to check
4157
* @return true if the coordinate appears to be geographic, false otherwise
@@ -53,6 +69,14 @@ static boolean isGeographic(Coordinate center) {
5369
* Calculates the approximate radius in degrees for a given distance in meters
5470
* at a specific geographic coordinate. This accounts for the fact that one degree
5571
* of longitude varies with latitude.
72+
*
73+
* <p><strong>Accuracy Note:</strong> This method returns the maximum of the
74+
* latitude and longitude degree differences to ensure circular coverage. This
75+
* means the resulting bounding box may be slightly larger than necessary,
76+
* potentially including some points outside the actual geodesic circle.</p>
77+
*
78+
* <p>A future enhancement (see <a href="https://github.com/nitrite/nitrite-java/issues/1126">issue #1126</a>,
79+
* Task 4) will implement two-pass query execution to eliminate these false positives.</p>
5680
*
5781
* @param center the center coordinate (longitude, latitude)
5882
* @param radiusMeters the radius in meters
@@ -75,6 +99,7 @@ static double metersToDegreesRadius(Coordinate center, double radiusMeters) {
7599

76100
// Use the maximum of the two to ensure we cover the full circle
77101
// This creates a slightly larger search area but ensures we don't miss points
102+
// TODO: Consider two-pass filtering to eliminate false positives (see issue #1126, Task 4)
78103
return Math.max(lonDiff, latDiff);
79104
}
80105
}

nitrite-spatial/src/main/java/org/dizitart/no2/spatial/NearFilter.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@
2222
import org.locationtech.jts.util.GeometricShapeFactory;
2323

2424
/**
25+
* A spatial filter that finds geometries near a point within a specified distance.
26+
*
27+
* <p>This filter automatically detects whether the coordinates are geographic (latitude/longitude)
28+
* or Cartesian, and applies the appropriate distance calculation:</p>
29+
* <ul>
30+
* <li><strong>Geographic coordinates</strong> (within ±90° lat, ±180° lon): Uses geodesic distance
31+
* on Earth's WGS84 ellipsoid, with distance specified in meters.</li>
32+
* <li><strong>Cartesian coordinates</strong> (outside those bounds): Uses simple Euclidean distance,
33+
* with distance in the same units as the coordinates.</li>
34+
* </ul>
35+
*
36+
* <p><strong>Future Enhancement:</strong> A future version will introduce explicit
37+
* {@code GeoNearFilter} and {@code GeoPoint} types for better type safety and to avoid
38+
* auto-detection ambiguity. See <a href="https://github.com/nitrite/nitrite-java/issues/1126">issue #1126</a>
39+
* (Tasks 1-2) for details.</p>
40+
*
41+
* <p><strong>Known Limitations:</strong></p>
42+
* <ul>
43+
* <li>Auto-detection may misclassify Cartesian coordinates in the range ±90/±180</li>
44+
* <li>May return some false positives (points slightly outside the geodesic circle but
45+
* within its bounding box) - see issue #1126, Task 4</li>
46+
* </ul>
47+
*
2548
* @since 4.0
2649
* @author Anindya Chatterjee
2750
*/

0 commit comments

Comments
 (0)