diff --git a/src/main/java/org/apache/commons/math4/util/MathUtils.java b/src/main/java/org/apache/commons/math4/util/MathUtils.java index e42f44943..303146597 100644 --- a/src/main/java/org/apache/commons/math4/util/MathUtils.java +++ b/src/main/java/org/apache/commons/math4/util/MathUtils.java @@ -85,29 +85,6 @@ public final class MathUtils { return Arrays.hashCode(value); } - /** - * Normalize an angle in a 2π wide interval around a center value. - *

This method has three main uses:

- * - *

Note that due to numerical accuracy and since π cannot be represented - * exactly, the result interval is closed, it cannot be half-closed - * as would be more satisfactory in a purely mathematical view.

- * @param a angle to normalize - * @param center center of the desired 2π interval for the result - * @return a-2kπ with integer k and center-π <= a-2kπ <= center+π - * @since 1.2 - */ - public static double normalizeAngle(double a, double center) { - return a - TWO_PI * FastMath.floor((a + FastMath.PI - center) / TWO_PI); - } - /** Find the maximum of two field elements. * @param the type of the field elements * @param e1 first element diff --git a/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java b/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java index 2e116a2ce..2536f8480 100644 --- a/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java +++ b/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java @@ -13,6 +13,7 @@ */ package org.apache.commons.math4.util; +import org.apache.commons.numbers.angle.PlaneAngleRadians; import org.apache.commons.math4.distribution.RealDistribution; import org.apache.commons.math4.distribution.UniformRealDistribution; import org.apache.commons.math4.exception.MathArithmeticException; @@ -153,19 +154,6 @@ public final class MathUtilsTest { Assert.assertEquals((short)(-1), MathUtils.copySign((short)1, (short)(-2))); } - @Test - public void testNormalizeAngle() { - for (double a = -15.0; a <= 15.0; a += 0.1) { - for (double b = -15.0; b <= 15.0; b += 0.2) { - double c = MathUtils.normalizeAngle(a, b); - Assert.assertTrue((b - FastMath.PI) <= c); - Assert.assertTrue(c <= (b + FastMath.PI)); - double twoK = FastMath.rint((a - c) / FastMath.PI); - Assert.assertEquals(c, a - twoK * FastMath.PI, 1.0e-14); - } - } - } - @Test public void testReduce() { final double period = -12.222; @@ -220,15 +208,15 @@ public final class MathUtilsTest { } @Test - public void testReduceComparedWithNormalizeAngle() { - final double tol = Math.ulp(1d); + public void testReduceComparedWithNormalize() { final double period = 2 * Math.PI; for (double a = -15; a <= 15; a += 0.5) { for (double center = -15; center <= 15; center += 1) { - final double nA = MathUtils.normalizeAngle(a, center); + final double nA = PlaneAngleRadians.normalize(a, center); final double offset = center - Math.PI; - final double r = MathUtils.reduce(a, period, offset); - Assert.assertEquals(nA, r + offset, tol); + final double r = MathUtils.reduce(a, period, offset) + offset; + Assert.assertEquals("a=" + a + " center=" + center, + nA, r, 52 * Math.ulp(nA)); } } }