You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/06/03 16:28:59 UTC

[commons-math] branch master updated: Adapt to new API ("Commons Numbers").

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-math.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ef0099  Adapt to new API ("Commons Numbers").
7ef0099 is described below

commit 7ef0099c9eae8a1a7fc91dfd0f7f23b02b3be285
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Thu Jun 3 18:27:25 2021 +0200

    Adapt to new API ("Commons Numbers").
---
 .../analysis/interpolation/InterpolatingMicrosphere2D.java     |  4 ++--
 .../commons/math4/legacy/fitting/HarmonicCurveFitterTest.java  | 10 +++++-----
 .../math4/legacy/fitting/leastsquares/CircleProblem.java       |  6 +++---
 .../fitting/leastsquares/RandomCirclePointGenerator.java       |  3 +--
 4 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java
index e0db5d6..eaca3ca 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/interpolation/InterpolatingMicrosphere2D.java
@@ -17,7 +17,6 @@
 package org.apache.commons.math4.legacy.analysis.interpolation;
 
 import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
-import org.apache.commons.numbers.angle.PlaneAngleRadians;
 
 /**
  * Utility class for the {@link MicrosphereProjectionInterpolator} algorithm.
@@ -57,8 +56,9 @@ public class InterpolatingMicrosphere2D extends InterpolatingMicrosphere {
         super(DIMENSION, size, maxDarkFraction, darkThreshold, background);
 
         // Generate the microsphere normals.
+        final double twopi = 2 * Math.PI;
         for (int i = 0; i < size; i++) {
-            final double angle = i * PlaneAngleRadians.TWO_PI / size;
+            final double angle = i * twopi / size;
 
             add(new double[] { AccurateMath.cos(angle),
                                AccurateMath.sin(angle) },
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitterTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitterTest.java
index 99b80da..30b05cd 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitterTest.java
+++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/HarmonicCurveFitterTest.java
@@ -20,7 +20,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
 
-import org.apache.commons.numbers.angle.PlaneAngleRadians;
+import org.apache.commons.numbers.angle.Angle;
 import org.apache.commons.math4.legacy.analysis.function.HarmonicOscillator;
 import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
 import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
@@ -53,7 +53,7 @@ public class HarmonicCurveFitterTest {
         final double[] fitted = fitter.fit(points.toList());
         Assert.assertEquals(a, fitted[0], 1.0e-13);
         Assert.assertEquals(w, fitted[1], 1.0e-13);
-        Assert.assertEquals(p, PlaneAngleRadians.normalizer(p).applyAsDouble(fitted[2]), 1e-13);
+        Assert.assertEquals(p, Angle.Rad.WITHIN_0_AND_2PI.apply(Angle.Rad.of(fitted[2])).getAsDouble(), 1e-13);
 
         final HarmonicOscillator ff = new HarmonicOscillator(fitted[0], fitted[1], fitted[2]);
         for (double x = -1.0; x < 1.0; x += 0.01) {
@@ -78,7 +78,7 @@ public class HarmonicCurveFitterTest {
         final double[] fitted = fitter.fit(points.toList());
         Assert.assertEquals(a, fitted[0], 7.6e-4);
         Assert.assertEquals(w, fitted[1], 2.7e-3);
-        Assert.assertEquals(p, PlaneAngleRadians.normalizer(p).applyAsDouble(fitted[2]), 1.3e-2);
+        Assert.assertEquals(p, Angle.Rad.WITHIN_0_AND_2PI.apply(Angle.Rad.of(fitted[2])).getAsDouble(), 1.3e-2);
     }
 
     @Test
@@ -115,7 +115,7 @@ public class HarmonicCurveFitterTest {
         final double[] fitted = fitter.fit(points.toList());
         Assert.assertEquals(a, fitted[0], 1.2e-3);
         Assert.assertEquals(w, fitted[1], 3.3e-3);
-        Assert.assertEquals(p, PlaneAngleRadians.normalizer(p).applyAsDouble(fitted[2]), 1.7e-2);
+        Assert.assertEquals(p, Angle.Rad.WITHIN_0_AND_2PI.apply(Angle.Rad.of(fitted[2])).getAsDouble(), 1.7e-2);
     }
 
     @Test
@@ -157,7 +157,7 @@ public class HarmonicCurveFitterTest {
         final double[] fitted = fitter.fit(points.toList());
         Assert.assertEquals(a, fitted[0], 7.6e-4);
         Assert.assertEquals(w, fitted[1], 3.5e-3);
-        Assert.assertEquals(p, PlaneAngleRadians.normalizer(p).applyAsDouble(fitted[2]), 1.5e-2);
+        Assert.assertEquals(p, Angle.Rad.WITHIN_0_AND_2PI.apply(Angle.Rad.of(fitted[2])).getAsDouble(), 1.5e-2);
     }
 
     @Test(expected=MathIllegalStateException.class)
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/leastsquares/CircleProblem.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/leastsquares/CircleProblem.java
index d18672e..8970f15 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/leastsquares/CircleProblem.java
+++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/leastsquares/CircleProblem.java
@@ -21,7 +21,6 @@ import java.util.ArrayList;
 import org.apache.commons.math4.legacy.analysis.MultivariateMatrixFunction;
 import org.apache.commons.math4.legacy.analysis.MultivariateVectorFunction;
 import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
-import org.apache.commons.numbers.angle.PlaneAngleRadians;
 
 /**
  * Class that models a circle.
@@ -111,7 +110,8 @@ class CircleProblem {
 
                 final double[] model = new double[points.size() * 2];
 
-                final double deltaTheta = PlaneAngleRadians.TWO_PI / resolution;
+                final double twopi = 2 * Math.PI;
+                final double deltaTheta = twopi / resolution;
                 for (int i = 0; i < points.size(); i++) {
                     final double[] p = points.get(i);
                     final double px = p[0];
@@ -124,7 +124,7 @@ class CircleProblem {
                     // Find the angle for which the circle passes closest to the
                     // current point (using a resolution of 100 points along the
                     // circumference).
-                    for (double theta = 0; theta <= PlaneAngleRadians.TWO_PI; theta += deltaTheta) {
+                    for (double theta = 0; theta <= twopi; theta += deltaTheta) {
                         final double currentX = cx + r * AccurateMath.cos(theta);
                         final double currentY = cy + r * AccurateMath.sin(theta);
                         final double dX = currentX - px;
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/leastsquares/RandomCirclePointGenerator.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/leastsquares/RandomCirclePointGenerator.java
index 11ea8e9..7414935 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/leastsquares/RandomCirclePointGenerator.java
+++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/fitting/leastsquares/RandomCirclePointGenerator.java
@@ -23,7 +23,6 @@ import org.apache.commons.statistics.distribution.UniformContinuousDistribution;
 import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.rng.simple.RandomSource;
 import org.apache.commons.math4.legacy.core.jdkmath.AccurateMath;
-import org.apache.commons.numbers.angle.PlaneAngleRadians;
 
 /**
  * Factory for generating a cloud of points that approximate a circle.
@@ -55,7 +54,7 @@ public class RandomCirclePointGenerator {
         this.radius = radius;
         cX = new NormalDistribution(x, xSigma).createSampler(rng);
         cY = new NormalDistribution(y, ySigma).createSampler(rng);
-        tP = new UniformContinuousDistribution(0, PlaneAngleRadians.TWO_PI).createSampler(rng);
+        tP = new UniformContinuousDistribution(0, 2 * Math.PI).createSampler(rng);
     }
 
     /**