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 c892bfe0ab781a3cebd80512ee3abbbfe775af7b
Author: Matt Juntunen <[email protected]>
AuthorDate: Wed Jul 11 00:04:54 2018 -0400

    GEOMETRY-7: changing polar/spherical azimuth convention from (-pi, +pi] 
range to [0, 2pi) range in order to match S1Point and S2Point conventions
---
 .../org/apache/commons/geometry/core/Geometry.java |  7 ++++--
 .../apache/commons/geometry/core/GeometryTest.java |  2 ++
 .../euclidean/threed/SphericalCoordinates.java     | 10 ++++-----
 .../geometry/euclidean/twod/PolarCoordinates.java  | 24 ++++++++++-----------
 .../geometry/euclidean/threed/Cartesian3DTest.java |  4 ++--
 .../euclidean/threed/SphericalCoordinatesTest.java | 18 ++++++++--------
 .../geometry/euclidean/twod/Cartesian2DTest.java   |  6 +++---
 .../euclidean/twod/PolarCoordinatesTest.java       | 25 +++++++++++-----------
 .../commons/geometry/spherical/oned/S1Point.java   |  3 +--
 .../commons/geometry/spherical/twod/S2Point.java   | 10 ++-------
 .../geometry/spherical/twod/S2PointTest.java       | 12 +----------
 11 files changed, 54 insertions(+), 67 deletions(-)

diff --git 
a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Geometry.java
 
b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Geometry.java
index efe797d..d227755 100644
--- 
a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Geometry.java
+++ 
b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Geometry.java
@@ -32,12 +32,15 @@ public class Geometry {
     /** Constant value for {@code -2*pi}. */
     public static final double MINUS_TWO_PI = -2.0 * Math.PI;
 
-    /** Constant value for {@code pi / 2}. */
+    /** Constant value for {@code pi/2}. */
     public static final double HALF_PI = 0.5 * Math.PI;
 
-    /** Constant value for {@code - pi / 2}. */
+    /** Constant value for {@code - pi/2}. */
     public static final double MINUS_HALF_PI = - 0.5 * Math.PI;
 
+    /** Constant value for {@code  3*pi/2}. */
+    public static final double THREE_HALVES_PI = 1.5 * Math.PI;
+
     /** Private constructor */
     private Geometry() {}
 }
diff --git 
a/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/GeometryTest.java
 
b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/GeometryTest.java
index 88533eb..61fc872 100644
--- 
a/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/GeometryTest.java
+++ 
b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/GeometryTest.java
@@ -35,6 +35,8 @@ public class GeometryTest {
 
         Assert.assertEquals(Math.PI / 2.0, Geometry.HALF_PI, 0.0);
         Assert.assertEquals(-Math.PI / 2.0, Geometry.MINUS_HALF_PI, eps);
+
+        Assert.assertEquals((3.0 * Math.PI) / 2.0, Geometry.THREE_HALVES_PI, 
eps);
     }
 
     @Test
diff --git 
a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SphericalCoordinates.java
 
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SphericalCoordinates.java
index 37d7ea8..5be957d 100644
--- 
a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SphericalCoordinates.java
+++ 
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SphericalCoordinates.java
@@ -62,7 +62,7 @@ import org.apache.commons.numbers.angle.PlaneAngleRadians;
  *
  * <p>In order to ensure the uniqueness of coordinate sets, coordinate values
  * are normalized so that {@code radius} is in the range {@code [0, 
+Infinity)},
- * {@code azimuth} is in the range {@code (-pi, pi]}, and {@code polar} is in 
the
+ * {@code azimuth} is in the range {@code [0, 2pi)}, and {@code polar} is in 
the
  * range {@code [0, pi]}.</p>
  *
  * @see <a 
href="https://en.wikipedia.org/wiki/Spherical_coordinate_system";>Spherical 
Coordinate System</a>
@@ -117,7 +117,7 @@ public final class SphericalCoordinates implements Spatial, 
Serializable {
     }
 
     /** Return the azimuth angle in radians. This is the angle in the x-y 
plane measured counter-clockwise from
-     * the positive x axis. The angle is in the range {@code (-pi, pi]}.
+     * the positive x axis. The angle is in the range {@code [0, 2pi)}.
      * @return the azimuth angle in radians
      */
     public double getAzimuth() {
@@ -233,7 +233,7 @@ public final class SphericalCoordinates implements Spatial, 
Serializable {
 
     /** Return a new instance with the given spherical coordinate values. The 
values are normalized
      * so that {@code radius} lies in the range {@code [0, +Infinity)}, {@code 
azimuth} lies in the range
-     * {@code (-pi, +pi]}, and {@code polar} lies in the range {@code [0, 
+pi]}.
+     * {@code [0, 2pi)}, and {@code polar} lies in the range {@code [0, +pi]}.
      * @param radius the length of the line segment from the origin to the 
coordinate point.
      * @param azimuth the angle in the x-y plane, measured in radians 
counter-clockwise
      *      from the positive x-axis.
@@ -273,10 +273,10 @@ public final class SphericalCoordinates implements 
Spatial, Serializable {
         return SimpleCoordinateFormat.getPointFormat().parse(input, FACTORY);
     }
 
-    /** Normalize an azimuth value to be within the range {@code (-pi, +pi]}. 
This
+    /** Normalize an azimuth value to be within the range {@code [0, 2pi)}. 
This
      * is exactly equivalent to {@link 
PolarCoordinates#normalizeAzimuth(double)}.
      * @param azimuth azimuth value in radians
-     * @return equivalent azimuth value in the range {@code (-pi, +pi]}.
+     * @return equivalent azimuth value in the range {@code [0, 2pi)}.
      * @see PolarCoordinates#normalizeAzimuth(double)
      */
     public static double normalizeAzimuth(double azimuth) {
diff --git 
a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/PolarCoordinates.java
 
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/PolarCoordinates.java
index 3ea6779..9dbbfa1 100644
--- 
a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/PolarCoordinates.java
+++ 
b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/PolarCoordinates.java
@@ -46,7 +46,7 @@ import org.apache.commons.numbers.angle.PlaneAngleRadians;
  * </p>
  * <p>In order to ensure the uniqueness of coordinate sets, coordinate values
  * are normalized so that {@code radius} is in the range {@code [0, +Infinity)}
- * and {@code azimuth} is in the range {@code (-pi, pi]}.</p>
+ * and {@code azimuth} is in the range {@code [0, 2pi)}.</p>
  *
  * @see <a href="https://en.wikipedia.org/wiki/Polar_coordinate_system";>Polar 
Coordinate System</a>
  */
@@ -94,7 +94,7 @@ public final class PolarCoordinates implements Spatial, 
Serializable {
     }
 
     /** Return the azimuth angle in radians. The value will be
-     * in the range {@code (-pi, pi]}.
+     * in the range {@code [0, 2pi)}.
      * @return azimuth value in radians.
      */
     public double getAzimuth() {
@@ -203,8 +203,8 @@ public final class PolarCoordinates implements Spatial, 
Serializable {
     }
 
     /** Return a new instance with the given polar coordinate values.
-     * The values are normalized so that {@code radius} lies in the range 
{@code [0, +infinity)}
-     * and {@code azimuth} in the range {@code (-pi, pi]}.
+     * The values are normalized so that {@code radius} lies in the range 
{@code [0, +Infinity)}
+     * and {@code azimuth} in the range {@code [0, 2pi)}.
      * @param radius Radius value.
      * @param azimuth Azimuth angle in radians.
      * @return new {@link PolarCoordinates} instance
@@ -236,18 +236,18 @@ public final class PolarCoordinates implements Spatial, 
Serializable {
         return SimpleCoordinateFormat.getPointFormat().parse(input, FACTORY);
     }
 
-    /** Normalize an azimuth value to be within the range {@code (-pi, +pi]}.
+    /** Normalize an azimuth value to be within the range {@code [0, 2pi)}.
      * @param azimuth azimuth value in radians
-     * @return equivalent azimuth value in the range {@code (-pi, +pi]}.
+     * @return equivalent azimuth value in the range {@code [0, 2pi)}.
      */
     public static double normalizeAzimuth(double azimuth) {
-        if (Double.isFinite(azimuth) && (azimuth <= Geometry.MINUS_PI || 
azimuth > Geometry.PI)) {
-            azimuth = PlaneAngleRadians.normalizeBetweenMinusPiAndPi(azimuth);
+        if (Double.isFinite(azimuth) && (azimuth < 0.0 || azimuth >= 
Geometry.TWO_PI)) {
+            azimuth = PlaneAngleRadians.normalizeBetweenZeroAndTwoPi(azimuth);
 
-            // azimuth is now in the range [-pi, pi] but we want it to be in 
the range
-            // (-pi, pi] in order to have completely unique coordinates
-            if (azimuth <= -Geometry.PI) {
-                azimuth += Geometry.TWO_PI;
+            // azimuth is now in the range [0, 2pi] but we want it to be in 
the range
+            // [0, 2pi) in order to have completely unique coordinates
+            if (azimuth >= Geometry.TWO_PI) {
+                azimuth -= Geometry.TWO_PI;
             }
         }
 
diff --git 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Cartesian3DTest.java
 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Cartesian3DTest.java
index 88547a9..6326f5e 100644
--- 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Cartesian3DTest.java
+++ 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Cartesian3DTest.java
@@ -47,13 +47,13 @@ public class Cartesian3DTest {
         checkSpherical(new StubCartesian3D(-0.1, 0, 0).toSpherical(), 0.1, 
Geometry.PI, Geometry.HALF_PI);
 
         checkSpherical(new StubCartesian3D(0, 0.1, 0).toSpherical(), 0.1, 
Geometry.HALF_PI, Geometry.HALF_PI);
-        checkSpherical(new StubCartesian3D(0, -0.1, 0).toSpherical(), 0.1, 
Geometry.MINUS_HALF_PI, Geometry.HALF_PI);
+        checkSpherical(new StubCartesian3D(0, -0.1, 0).toSpherical(), 0.1, 
Geometry.PI + Geometry.HALF_PI, Geometry.HALF_PI);
 
         checkSpherical(new StubCartesian3D(0, 0, 0.1).toSpherical(), 0.1, 0, 
0);
         checkSpherical(new StubCartesian3D(0, 0, -0.1).toSpherical(), 0.1, 0, 
Geometry.PI);
 
         checkSpherical(new StubCartesian3D(1, 1, 1).toSpherical(), sqrt3, 0.25 
* Geometry.PI, Math.acos(1 / sqrt3));
-        checkSpherical(new StubCartesian3D(-1, -1, -1).toSpherical(), sqrt3, 
-0.75 * Geometry.PI, Math.acos(-1 / sqrt3));
+        checkSpherical(new StubCartesian3D(-1, -1, -1).toSpherical(), sqrt3, 
1.25 * Geometry.PI, Math.acos(-1 / sqrt3));
     }
 
     @Test
diff --git 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/SphericalCoordinatesTest.java
 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/SphericalCoordinatesTest.java
index 241093a..11057ed 100644
--- 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/SphericalCoordinatesTest.java
+++ 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/SphericalCoordinatesTest.java
@@ -41,7 +41,7 @@ public class SphericalCoordinatesTest {
         checkSpherical(SphericalCoordinates.of(1, Geometry.HALF_PI, 
Geometry.PI),
                 1, Geometry.HALF_PI, Geometry.PI);
         checkSpherical(SphericalCoordinates.of(1, Geometry.MINUS_HALF_PI, 
Geometry.HALF_PI),
-                1, Geometry.MINUS_HALF_PI, Geometry.HALF_PI);
+                1, Geometry.THREE_HALVES_PI, Geometry.HALF_PI);
     }
 
     @Test
@@ -50,7 +50,7 @@ public class SphericalCoordinatesTest {
         checkSpherical(SphericalCoordinates.of(2, Geometry.TWO_PI, 0), 2, 0, 
0);
         checkSpherical(SphericalCoordinates.of(2, Geometry.HALF_PI + 
Geometry.TWO_PI, 0), 2, Geometry.HALF_PI, 0);
         checkSpherical(SphericalCoordinates.of(2, -Geometry.PI, 0), 2, 
Geometry.PI, 0);
-        checkSpherical(SphericalCoordinates.of(2, Geometry.PI * 1.5, 0), 2, 
Geometry.MINUS_HALF_PI, 0);
+        checkSpherical(SphericalCoordinates.of(2, Geometry.THREE_HALVES_PI, 
0), 2, Geometry.THREE_HALVES_PI, 0);
     }
 
     @Test
@@ -95,10 +95,10 @@ public class SphericalCoordinatesTest {
         checkSpherical(SphericalCoordinates.of(-2, 0, 0), 2, Geometry.PI, 
Geometry.PI);
         checkSpherical(SphericalCoordinates.of(-2, Geometry.PI, Geometry.PI), 
2, 0, 0);
 
-        checkSpherical(SphericalCoordinates.of(-3, Geometry.HALF_PI, 
QUARTER_PI), 3, Geometry.MINUS_HALF_PI, THREE_QUARTER_PI);
+        checkSpherical(SphericalCoordinates.of(-3, Geometry.HALF_PI, 
QUARTER_PI), 3, Geometry.THREE_HALVES_PI, THREE_QUARTER_PI);
         checkSpherical(SphericalCoordinates.of(-3, Geometry.MINUS_HALF_PI, 
THREE_QUARTER_PI), 3, Geometry.HALF_PI, QUARTER_PI);
 
-        checkSpherical(SphericalCoordinates.of(-4, QUARTER_PI, 
Geometry.HALF_PI), 4, MINUS_THREE_QUARTER_PI, Geometry.HALF_PI);
+        checkSpherical(SphericalCoordinates.of(-4, QUARTER_PI, 
Geometry.HALF_PI), 4, Geometry.PI + QUARTER_PI, Geometry.HALF_PI);
         checkSpherical(SphericalCoordinates.of(-4, MINUS_THREE_QUARTER_PI, 
Geometry.HALF_PI), 4, QUARTER_PI, Geometry.HALF_PI);
     }
 
@@ -125,13 +125,13 @@ public class SphericalCoordinatesTest {
         checkSpherical(SphericalCoordinates.ofCartesian(-0.1, 0, 0), 0.1, 
Geometry.PI, Geometry.HALF_PI);
 
         checkSpherical(SphericalCoordinates.ofCartesian(0, 0.1, 0), 0.1, 
Geometry.HALF_PI, Geometry.HALF_PI);
-        checkSpherical(SphericalCoordinates.ofCartesian(0, -0.1, 0), 0.1, 
Geometry.MINUS_HALF_PI, Geometry.HALF_PI);
+        checkSpherical(SphericalCoordinates.ofCartesian(0, -0.1, 0), 0.1, 
Geometry.THREE_HALVES_PI, Geometry.HALF_PI);
 
         checkSpherical(SphericalCoordinates.ofCartesian(0, 0, 0.1), 0.1, 0, 0);
         checkSpherical(SphericalCoordinates.ofCartesian(0, 0, -0.1), 0.1, 0, 
Geometry.PI);
 
         checkSpherical(SphericalCoordinates.ofCartesian(1, 1, 1), sqrt3, 
QUARTER_PI, Math.acos(1 / sqrt3));
-        checkSpherical(SphericalCoordinates.ofCartesian(-1, -1, -1), sqrt3, 
MINUS_THREE_QUARTER_PI, Math.acos(-1 / sqrt3));
+        checkSpherical(SphericalCoordinates.ofCartesian(-1, -1, -1), sqrt3, 
1.25 * Geometry.PI, Math.acos(-1 / sqrt3));
     }
 
     @Test
@@ -343,7 +343,7 @@ public class SphericalCoordinatesTest {
     public void testParse() {
         // act/assert
         checkSpherical(SphericalCoordinates.parse("(1, 2, 3)"), 1, 2, 3);
-        checkSpherical(SphericalCoordinates.parse("(  -2.0 , 1 , -5e-1)"), 2, 
1 - Geometry.PI, Geometry.PI - 0.5);
+        checkSpherical(SphericalCoordinates.parse("(  -2.0 , 1 , -5e-1)"), 2, 
1 + Geometry.PI, Geometry.PI - 0.5);
         checkSpherical(SphericalCoordinates.parse("(NaN,Infinity,-Infinity)"), 
Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY);
     }
 
@@ -360,10 +360,10 @@ public class SphericalCoordinatesTest {
 
         
Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(Geometry.HALF_PI), 
Geometry.HALF_PI, EPS);
         
Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(Geometry.PI), 
Geometry.PI, EPS);
-        Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(Geometry.PI 
+ Geometry.HALF_PI), Geometry.MINUS_HALF_PI, EPS);
+        
Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(Geometry.THREE_HALVES_PI),
 Geometry.THREE_HALVES_PI, EPS);
         
Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(Geometry.TWO_PI), 
0.0, EPS);
 
-        
Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(Geometry.MINUS_HALF_PI),
 Geometry.MINUS_HALF_PI, EPS);
+        
Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(Geometry.MINUS_HALF_PI),
 Geometry.THREE_HALVES_PI, EPS);
         
Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(-Geometry.PI), 
Geometry.PI, EPS);
         Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(-Geometry.PI 
- Geometry.HALF_PI), Geometry.HALF_PI, EPS);
         
Assert.assertEquals(SphericalCoordinates.normalizeAzimuth(-Geometry.TWO_PI), 
0.0, EPS);
diff --git 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Cartesian2DTest.java
 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Cartesian2DTest.java
index 379269f..261ad09 100644
--- 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Cartesian2DTest.java
+++ 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Cartesian2DTest.java
@@ -81,12 +81,12 @@ public class Cartesian2DTest {
         checkPolar(new StubCartesian2D(-1, 0).toPolar(), 1, Geometry.PI);
 
         checkPolar(new StubCartesian2D(0, 2).toPolar(), 2, Geometry.HALF_PI);
-        checkPolar(new StubCartesian2D(0, -2).toPolar(), 2, 
Geometry.MINUS_HALF_PI);
+        checkPolar(new StubCartesian2D(0, -2).toPolar(), 2, 
Geometry.THREE_HALVES_PI);
 
         checkPolar(new StubCartesian2D(sqrt2, sqrt2).toPolar(), 2, 0.25 * 
Geometry.PI);
         checkPolar(new StubCartesian2D(-sqrt2, sqrt2).toPolar(), 2, 0.75 * 
Geometry.PI);
-        checkPolar(new StubCartesian2D(sqrt2, -sqrt2).toPolar(), 2, -0.25 * 
Geometry.PI);
-        checkPolar(new StubCartesian2D(-sqrt2, -sqrt2).toPolar(), 2, -0.75 * 
Geometry.PI);
+        checkPolar(new StubCartesian2D(sqrt2, -sqrt2).toPolar(), 2, 1.75 * 
Geometry.PI);
+        checkPolar(new StubCartesian2D(-sqrt2, -sqrt2).toPolar(), 2, 1.25 * 
Geometry.PI);
     }
 
     @Test
diff --git 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/PolarCoordinatesTest.java
 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/PolarCoordinatesTest.java
index d8636f0..ce74382 100644
--- 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/PolarCoordinatesTest.java
+++ 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/PolarCoordinatesTest.java
@@ -35,7 +35,7 @@ public class PolarCoordinatesTest {
         checkPolar(PolarCoordinates.of(2, 0), 2, 0);
         checkPolar(PolarCoordinates.of(2, Geometry.HALF_PI), 2, 
Geometry.HALF_PI);
         checkPolar(PolarCoordinates.of(2, Geometry.PI), 2, Geometry.PI);
-        checkPolar(PolarCoordinates.of(2, Geometry.MINUS_HALF_PI), 2, 
Geometry.MINUS_HALF_PI);
+        checkPolar(PolarCoordinates.of(2, Geometry.MINUS_HALF_PI), 2, 
Geometry.THREE_HALVES_PI);
     }
 
     @Test
@@ -44,7 +44,7 @@ public class PolarCoordinatesTest {
         checkPolar(PolarCoordinates.of(2, Geometry.TWO_PI), 2, 0);
         checkPolar(PolarCoordinates.of(2, Geometry.HALF_PI + Geometry.TWO_PI), 
2, Geometry.HALF_PI);
         checkPolar(PolarCoordinates.of(2, -Geometry.PI), 2, Geometry.PI);
-        checkPolar(PolarCoordinates.of(2, Geometry.PI * 1.5), 2, 
Geometry.MINUS_HALF_PI);
+        checkPolar(PolarCoordinates.of(2, -Geometry.PI * 1.5), 2, 
Geometry.HALF_PI);
     }
 
     @Test
@@ -58,9 +58,8 @@ public class PolarCoordinatesTest {
         checkAzimuthWrapAround(2, Geometry.PI - delta);
         checkAzimuthWrapAround(2, Geometry.PI);
 
-        checkAzimuthWrapAround(2, 0);
-        checkAzimuthWrapAround(2, -delta);
-        checkAzimuthWrapAround(2, delta - Geometry.PI);
+        checkAzimuthWrapAround(2, Geometry.THREE_HALVES_PI);
+        checkAzimuthWrapAround(2, Geometry.TWO_PI - delta);
     }
 
     private void checkAzimuthWrapAround(double radius, double azimuth) {
@@ -79,7 +78,7 @@ public class PolarCoordinatesTest {
     public void testOf_negativeRadius() {
         // act/assert
         checkPolar(PolarCoordinates.of(-1, 0), 1, Geometry.PI);
-        checkPolar(PolarCoordinates.of(-1e-6, Geometry.HALF_PI), 1e-6, 
Geometry.MINUS_HALF_PI);
+        checkPolar(PolarCoordinates.of(-1e-6, Geometry.HALF_PI), 1e-6, 
Geometry.THREE_HALVES_PI);
         checkPolar(PolarCoordinates.of(-2, Geometry.PI), 2, 0);
         checkPolar(PolarCoordinates.of(-3, Geometry.MINUS_HALF_PI), 3, 
Geometry.HALF_PI);
     }
@@ -110,10 +109,10 @@ public class PolarCoordinatesTest {
 
         checkPolar(PolarCoordinates.ofCartesian(-1, 1), sqrt2, 0.75 * 
Geometry.PI);
         checkPolar(PolarCoordinates.ofCartesian(-1, 0), 1, Geometry.PI);
-        checkPolar(PolarCoordinates.ofCartesian(-1, -1), sqrt2, - 0.75 * 
Geometry.PI);
+        checkPolar(PolarCoordinates.ofCartesian(-1, -1), sqrt2, 1.25 * 
Geometry.PI);
 
-        checkPolar(PolarCoordinates.ofCartesian(0, -1), 1, 
Geometry.MINUS_HALF_PI);
-        checkPolar(PolarCoordinates.ofCartesian(1, -1), sqrt2, -0.25 * 
Geometry.PI);
+        checkPolar(PolarCoordinates.ofCartesian(0, -1), 1, 1.5 * Geometry.PI);
+        checkPolar(PolarCoordinates.ofCartesian(1, -1), sqrt2, 1.75 * 
Geometry.PI);
     }
 
     @Test
@@ -333,7 +332,7 @@ public class PolarCoordinatesTest {
     public void testParse() {
         // act/assert
         checkPolar(PolarCoordinates.parse("(1, 2)"), 1, 2);
-        checkPolar(PolarCoordinates.parse("( -1 , 0.5 )"), 1, 0.5 - 
Geometry.PI);
+        checkPolar(PolarCoordinates.parse("( -1 , 0.5 )"), 1, 0.5 + 
Geometry.PI);
         checkPolar(PolarCoordinates.parse("(NaN,-Infinity)"), Double.NaN, 
Double.NEGATIVE_INFINITY);
     }
 
@@ -350,10 +349,10 @@ public class PolarCoordinatesTest {
 
         
Assert.assertEquals(PolarCoordinates.normalizeAzimuth(Geometry.HALF_PI), 
Geometry.HALF_PI, EPS);
         Assert.assertEquals(PolarCoordinates.normalizeAzimuth(Geometry.PI), 
Geometry.PI, EPS);
-        Assert.assertEquals(PolarCoordinates.normalizeAzimuth(Geometry.PI + 
Geometry.HALF_PI), Geometry.MINUS_HALF_PI, EPS);
+        
Assert.assertEquals(PolarCoordinates.normalizeAzimuth(Geometry.THREE_HALVES_PI),
 Geometry.THREE_HALVES_PI, EPS);
         
Assert.assertEquals(PolarCoordinates.normalizeAzimuth(Geometry.TWO_PI), 0.0, 
EPS);
 
-        
Assert.assertEquals(PolarCoordinates.normalizeAzimuth(Geometry.MINUS_HALF_PI), 
Geometry.MINUS_HALF_PI, EPS);
+        
Assert.assertEquals(PolarCoordinates.normalizeAzimuth(Geometry.MINUS_HALF_PI), 
Geometry.THREE_HALVES_PI, EPS);
         Assert.assertEquals(PolarCoordinates.normalizeAzimuth(-Geometry.PI), 
Geometry.PI, EPS);
         Assert.assertEquals(PolarCoordinates.normalizeAzimuth(-Geometry.PI - 
Geometry.HALF_PI), Geometry.HALF_PI, EPS);
         
Assert.assertEquals(PolarCoordinates.normalizeAzimuth(-Geometry.TWO_PI), 0.0, 
EPS);
@@ -373,7 +372,7 @@ public class PolarCoordinatesTest {
         Coordinates.Factory2D<PolarCoordinates> factory = 
PolarCoordinates.getFactory();
 
         // assert
-        checkPolar(factory.create(-1, Geometry.HALF_PI), 1, 
Geometry.MINUS_HALF_PI);
+        checkPolar(factory.create(-1, Geometry.HALF_PI), 1, 
Geometry.THREE_HALVES_PI);
     }
 
     private void checkPolar(PolarCoordinates polar, double radius, double 
azimuth) {
diff --git 
a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/S1Point.java
 
b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/S1Point.java
index 4d3f87e..20602e7 100644
--- 
a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/S1Point.java
+++ 
b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/S1Point.java
@@ -23,7 +23,6 @@ import org.apache.commons.geometry.core.util.Coordinates;
 import org.apache.commons.geometry.core.util.SimpleCoordinateFormat;
 import org.apache.commons.geometry.euclidean.twod.PolarCoordinates;
 import org.apache.commons.geometry.euclidean.twod.Vector2D;
-import org.apache.commons.numbers.angle.PlaneAngleRadians;
 
 /** This class represents a point on the 1-sphere.
  * <p>Instances of this class are guaranteed to be immutable.</p>
@@ -59,7 +58,7 @@ public final class S1Point implements Point<S1Point>, 
Serializable {
      * @param vector corresponding vector
      */
     private S1Point(final double azimuth) {
-        this.azimuth  = 
PlaneAngleRadians.normalizeBetweenZeroAndTwoPi(azimuth);
+        this.azimuth  = PolarCoordinates.normalizeAzimuth(azimuth);
         this.vector = Double.isFinite(azimuth) ? Vector2D.ofPolar(1.0, 
azimuth) : Vector2D.NaN;
     }
 
diff --git 
a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/S2Point.java
 
b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/S2Point.java
index 1b67205..0b3b191 100644
--- 
a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/S2Point.java
+++ 
b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/S2Point.java
@@ -79,11 +79,10 @@ public final class S2Point implements Point<S2Point>, 
Serializable {
      * @param azimuth azimuthal angle in the x-y plane
      * @param polar polar angle
      * @param vector corresponding vector; if null, the vector is computed
-     * @throws IllegalArgumentException
      */
     private S2Point(final double azimuth, final double polar, final Vector3D 
vector) {
-        this.azimuth = azimuth;
-        this.polar = polar;
+        this.azimuth = SphericalCoordinates.normalizeAzimuth(azimuth);
+        this.polar = SphericalCoordinates.normalizePolar(polar);
         this.vector = (vector != null) ? vector : Vector3D.ofSpherical(1.0, 
azimuth, polar);
     }
 
@@ -213,13 +212,8 @@ public final class S2Point implements Point<S2Point>, 
Serializable {
      * @return point instance with the given coordinates
      * @see #getAzimuth()
      * @see #getPolar()
-     * @exception IllegalArgumentException if polar is not in the {@code [0, 
+pi]} range
      */
     public static S2Point of(final double azimuth, final double polar) throws 
IllegalArgumentException {
-        if (polar < 0 || polar > Math.PI) {
-            throw new IllegalArgumentException(polar + " is out of [" + 0 + ", 
" + Math.PI + "] range");
-        }
-
         return new S2Point(azimuth, polar, null);
     }
 
diff --git 
a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/S2PointTest.java
 
b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/S2PointTest.java
index 78f9097..462b0dd 100644
--- 
a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/S2PointTest.java
+++ 
b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/S2PointTest.java
@@ -30,7 +30,7 @@ public class S2PointTest {
     public void testS2Point() {
         for (int k = -2; k < 3; ++k) {
             S2Point p = S2Point.of(1.0 + k * Geometry.TWO_PI, 1.4);
-            Assert.assertEquals(1.0 + k * Geometry.TWO_PI, p.getAzimuth(), 
EPS);
+            Assert.assertEquals(1.0, p.getAzimuth(), EPS);
             Assert.assertEquals(1.4, p.getPolar(), EPS);
             Assert.assertEquals(Math.cos(1.0) * Math.sin(1.4), 
p.getVector().getX(), EPS);
             Assert.assertEquals(Math.sin(1.0) * Math.sin(1.4), 
p.getVector().getY(), EPS);
@@ -39,16 +39,6 @@ public class S2PointTest {
         }
     }
 
-    @Test(expected=IllegalArgumentException.class)
-    public void testNegativePolarAngle() {
-        S2Point.of(1.0, -1.0);
-    }
-
-    @Test(expected=IllegalArgumentException.class)
-    public void testTooLargePolarAngle() {
-        S2Point.of(1.0, 3.5);
-    }
-
     @Test
     public void testNaN() {
         Assert.assertTrue(S2Point.NaN.isNaN());

Reply via email to