Skip to content

Apache Lucene open-source search software

LUCENE-6487: Geo3D with WGS84 patch from Karl: fix bug in GeoPoint.getLongitude with test from https://reviews.apache.org/r/34744/diff/raw/

David Wayne Smiley97a5295f075d
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPoint.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPoint.java
index 335c6db877c..520db18d9cf 100755
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPoint.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPoint.java
@@ -91,7 +91,7 @@ public class GeoPoint extends Vector {
public double getLongitude() {
if (Math.abs(x) < MINIMUM_RESOLUTION && Math.abs(y) < MINIMUM_RESOLUTION)
return 0.0;
- return Math.atan2(y,z);
+ return Math.atan2(y,x);
}
/** Compute the linear magnitude of the point.
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPointTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPointTest.java
new file mode 100644
index 00000000000..71fc9a3fdce
--- /dev/null
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPointTest.java
@@ -0,0 +1,44 @@
+package org.apache.lucene.spatial.spatial4j.geo3d;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test basic GeoPoint functionality.
+ */
+public class GeoPointTest {
+
+ @Test
+ public void testConversion() {
+ final double pLat = 0.123;
+ final double pLon = -0.456;
+ final GeoPoint p1 = new GeoPoint(PlanetModel.SPHERE, pLat, pLon);
+ assertEquals(pLat, p1.getLatitude(), 1e-12);
+ assertEquals(pLon, p1.getLongitude(), 1e-12);
+ final GeoPoint p2 = new GeoPoint(PlanetModel.WGS84, pLat, pLon);
+ assertEquals(pLat, p2.getLatitude(), 1e-12);
+ assertEquals(pLon, p2.getLongitude(), 1e-12);
+
+ }
+
+}
+
+