GEOMETRY-86: fixing incorrect computation in Point2S.antipodal()
diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Point2S.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Point2S.java
index 80a6999..b23b65f 100644
--- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Point2S.java
+++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Point2S.java
@@ -18,7 +18,6 @@
import java.util.Comparator;
-import org.apache.commons.numbers.angle.PlaneAngleRadians;
import org.apache.commons.geometry.core.Point;
import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
import org.apache.commons.geometry.core.precision.DoublePrecisionContext;
@@ -152,7 +151,7 @@
* @return the point exactly opposite this point on the sphere
*/
public Point2S antipodal() {
- return new Point2S(-azimuth, PlaneAngleRadians.PI - polar, vector.negate());
+ return from(vector.negate());
}
/** {@inheritDoc} */
diff --git a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/Point2STest.java b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/Point2STest.java
index afc37ff..89e973f 100644
--- a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/Point2STest.java
+++ b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/Point2STest.java
@@ -19,11 +19,11 @@
import java.util.Comparator;
-import org.apache.commons.numbers.angle.PlaneAngleRadians;
import org.apache.commons.geometry.core.precision.DoublePrecisionContext;
import org.apache.commons.geometry.core.precision.EpsilonDoublePrecisionContext;
import org.apache.commons.geometry.euclidean.threed.Vector3D;
import org.apache.commons.geometry.spherical.SphericalTestUtils;
+import org.apache.commons.numbers.angle.PlaneAngleRadians;
import org.junit.Assert;
import org.junit.Test;
@@ -215,6 +215,13 @@
// assert
Assert.assertEquals(PlaneAngleRadians.PI, pt.distance(result), TEST_EPS);
+
+ // check that the azimuth and polar components of the point are correct by creating a
+ // new point and checking the distance
+ Assert.assertEquals(PlaneAngleRadians.PI,
+ Point2S.of(result.getAzimuth(), result.getPolar()).distance(pt), TEST_EPS);
+
+ // check that the vectors point in opposite directions
Assert.assertEquals(-1, pt.getVector().dot(result.getVector()), TEST_EPS);
}
}