You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kw...@apache.org on 2017/09/15 06:20:24 UTC
lucene-solr:master: LUCENE-7955: Add tests for nearest path distance,
degenerate path.
Repository: lucene-solr
Updated Branches:
refs/heads/master 8cb64ed92 -> ab965d506
LUCENE-7955: Add tests for nearest path distance, degenerate path.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ab965d50
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ab965d50
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ab965d50
Branch: refs/heads/master
Commit: ab965d506cdc49b7c038b3c6b99623006409bf89
Parents: 8cb64ed
Author: Karl Wright <Da...@gmail.com>
Authored: Fri Sep 15 02:20:11 2017 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Fri Sep 15 02:20:11 2017 -0400
----------------------------------------------------------------------
.../lucene/spatial3d/geom/GeoPathTest.java | 73 ++++++++++++++++++++
1 file changed, 73 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ab965d50/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
index 3aada9a..922617d 100755
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
@@ -304,4 +304,77 @@ public class GeoPathTest {
assertTrue(solid.isWithin(point));
}
+ @Test
+ public void testInterpolation() {
+ final double lat = 52.51607;
+ final double lon = 13.37698;
+ final double[] pathLats = new double[] {52.5355,52.54,52.5626,52.5665,52.6007,52.6135,52.6303,52.6651,52.7074};
+ final double[] pathLons = new double[] {13.3634,13.3704,13.3307,13.3076,13.2806,13.2484,13.2406,13.241,13.1926};
+
+ // Set up a point in the right way
+ final GeoPoint carPoint = new GeoPoint(PlanetModel.SPHERE, toRadians(lat), toRadians(lon));
+ // Create the path, but use a tiny width (e.g. zero)
+ final GeoPoint[] pathPoints = new GeoPoint[pathLats.length];
+ for (int i = 0; i < pathPoints.length; i++) {
+ pathPoints[i] = new GeoPoint(PlanetModel.SPHERE, toRadians(pathLats[i]), toRadians(pathLons[i]));
+ }
+ // Construct a path with no width
+ final GeoPath thisPath = GeoPathFactory.makeGeoPath(PlanetModel.SPHERE, 0.0, pathPoints);
+ // Construct a path with a width
+ final GeoPath legacyPath = GeoPathFactory.makeGeoPath(PlanetModel.SPHERE, 1e-6, pathPoints);
+ // Compute the inside distance to the atPoint using zero-width path
+ final double distance = thisPath.computeNearestDistance(DistanceStyle.ARC, carPoint);
+ // Compute the inside distance using legacy path
+ final double legacyDistance = legacyPath.computeNearestDistance(DistanceStyle.ARC, carPoint);
+ // Compute the inside distance using the legacy formula
+ final double oldFormulaDistance = thisPath.computeDistance(DistanceStyle.ARC, carPoint);
+ // Compute the inside distance using the legacy formula with the legacy shape
+ final double oldFormulaLegacyDistance = legacyPath.computeDistance(DistanceStyle.ARC, carPoint);
+
+ // These should be about the same
+ assertEquals(legacyDistance, distance, 1e-12);
+ assertEquals(oldFormulaLegacyDistance, oldFormulaDistance, 1e-12);
+ // This isn't true because example search center is off of the path.
+ //assertEquals(oldFormulaDistance, distance, 1e-12);
+
+ }
+
+ @Test
+ public void testInterpolation2() {
+ final double lat = 52.5665;
+ final double lon = 13.3076;
+ final double[] pathLats = new double[] {52.5355,52.54,52.5626,52.5665,52.6007,52.6135,52.6303,52.6651,52.7074};
+ final double[] pathLons = new double[] {13.3634,13.3704,13.3307,13.3076,13.2806,13.2484,13.2406,13.241,13.1926};
+
+ final GeoPoint carPoint = new GeoPoint(PlanetModel.SPHERE, toRadians(lat), toRadians(lon));
+ final GeoPoint[] pathPoints = new GeoPoint[pathLats.length];
+ for (int i = 0; i < pathPoints.length; i++) {
+ pathPoints[i] = new GeoPoint(PlanetModel.SPHERE, toRadians(pathLats[i]), toRadians(pathLons[i]));
+ }
+
+ // Construct a path with no width
+ final GeoPath thisPath = GeoPathFactory.makeGeoPath(PlanetModel.SPHERE, 0.0, pathPoints);
+ // Construct a path with a width
+ final GeoPath legacyPath = GeoPathFactory.makeGeoPath(PlanetModel.SPHERE, 1e-6, pathPoints);
+
+ // Compute the inside distance to the atPoint using zero-width path
+ final double distance = thisPath.computeNearestDistance(DistanceStyle.ARC, carPoint);
+ // Compute the inside distance using legacy path
+ final double legacyDistance = legacyPath.computeNearestDistance(DistanceStyle.ARC, carPoint);
+
+ // Compute the inside distance using the legacy formula
+ final double oldFormulaDistance = thisPath.computeDistance(DistanceStyle.ARC, carPoint);
+ // Compute the inside distance using the legacy formula with the legacy shape
+ final double oldFormulaLegacyDistance = legacyPath.computeDistance(DistanceStyle.ARC, carPoint);
+
+ // These should be about the same
+ assertEquals(legacyDistance, distance, 1e-12);
+
+ assertEquals(oldFormulaLegacyDistance, oldFormulaDistance, 1e-12);
+
+ // Since the point we picked is actually on the path, this should also be true
+ assertEquals(oldFormulaDistance, distance, 1e-12);
+
+ }
+
}