apache / apache/lucene

Revamp spatial APIs that use primitives (or arrays of primitives) in their args/results so that they use strongly typed objects [LUCENE-3610]

Open
#4,684 5 comments 0 reactions 0 assignees View on GitHub
legacy-jira-priority:Minor module:spatial type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

My "spatial awareness" is pretty meek, but #4673 seems like a prime example of the types of mistakes that are probably really easy to make with all of the Spatial related APIs that deal with arrays (or sequences) of doubles where specific indexes of those arrays (or sequences) have significant meaning: mainly latitude vs longitude.

We should probably reconsider any method that takes in double[] or multiple doubles to express latlon pairs and rewrite them to use the existing LatLng class – or if people think that class is too heavyweight, then add a new lightweight class to handle the strong typing of a basic latlon point instead of just passing around a double[2] or two doubles called "x" and "y" ...

```Java
public static final class SimpleLatLonPointInRadians {
public double latitude;
public double longitude;
}
```

...then all those various methods that expect lat+lon pairs in radians (like DistanceUtils.haversine, DistanceUtils.normLat, DistanceUtils.normLng, DistanceUtils.pointOnBearing, DistanceUtils.latLonCorner, etc...) can start having APIs that don't make your eyes bleed when you start trying to understand what order the args go in.

---
Migrated from [LUCENE-3610](https://issues.apache.org/jira/browse/LUCENE-3610) by Chris M. Hostetter (@hossman), updated May 01 2014

Contributor guide

Open the contributing guide

Research direction

Start by inventorying the spatial APIs named in the issue, including DistanceUtils.haversine, normLat, normLng, pointOnBearing, and latLonCorner, and inspect the existing LatLng class. Identify affected callers and tests before defining the scope; done means the selected APIs use strongly typed latitude/longitude objects rather than ambiguous primitive pairs, with corresponding callers and tests updated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.