commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [commons-geometry] 01/03: GEOMETRY-86: fixing incorrect computation in Point2S.antipodal()
Date Wed, 08 Jan 2020 13:25:23 GMT
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-geometry.git

commit 1ba86d5ae952309c852be9d7a78bf3d02ffe5448
Author: Matt Juntunen <matt.juntunen@hotmail.com>
AuthorDate: Tue Jan 7 21:54:54 2020 -0500

    GEOMETRY-86: fixing incorrect computation in Point2S.antipodal()
---
 .../java/org/apache/commons/geometry/spherical/twod/Point2S.java | 3 +--
 .../org/apache/commons/geometry/spherical/twod/Point2STest.java  | 9 ++++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

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 @@ package org.apache.commons.geometry.spherical.twod;
 
 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 @@ public final class Point2S implements Point<Point2S> {
      * @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 @@ package org.apache.commons.geometry.spherical.twod;
 
 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 @@ public class Point2STest {
 
                 // 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);
             }
         }


Mime
View raw message