apache / lucene

Apache Lucene open-source search software
https://lucene.apache.org/
Apache License 2.0
2.6k stars 1.01k forks source link

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

Open asfimport opened 12 years ago

asfimport commented 12 years ago

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" ...

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 by Chris M. Hostetter (@hossman), updated May 01 2014

asfimport commented 12 years ago

Yonik Seeley (@yonik) (migrated from JIRA)

I think we should just avoid using "x" and "y", and use "lat" and "lon". The error was in parameter naming only, but was never apparent to me because when I saw "x", I thought "first parameter" which is "lat" in a lat,lon pair (and this is why the params were always passed correctly... it didn't cause confusion until someone with more geo experience looked at it).

asfimport commented 12 years ago

Chris M. Hostetter (@hossman) (migrated from JIRA)

That's one example ... some of the other methods i was mentioned deal with (either as an argument or as a result) two element arrays of doubles ... which one comes first in the array? ... you can't fix that by renaming the variable.

in either case: is there really any downside against having a simple object that wraps the latlon pair so you always know which one is which? is the RAM/GC overhead of an object like i described really significant compared to a double[2] ?

asfimport commented 12 years ago

Yonik Seeley (@yonik) (migrated from JIRA)

in either case: is there really any downside against having a simple object that wraps the latlon pair so you always know which one is which?

We should always do lat first (and I believe we do).

is the RAM/GC overhead of an object like i described really significant compared to a double[2] ?

The object (compared to a double[]) could actually be better - no array bounds checks. If you're only talking about replacing double[2] w/ an object, I'm all for it. Otherwise, it's case by case - it depends if it's going to be used in an inner loop.

asfimport commented 11 years ago

Steven Rowe (@sarowe) (migrated from JIRA)

Bulk move 4.4 issues to 4.5 and 5.0

asfimport commented 10 years ago

Uwe Schindler (@uschindler) (migrated from JIRA)

Move issue to Lucene 4.9.