Adapt to new API ("Commons Numbers").

This commit is contained in:
Gilles Sadowski 2021-06-03 18:27:25 +02:00
parent 536ee3f645
commit 7ef0099c9e
4 changed files with 11 additions and 12 deletions

View File

@ -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) },

View File

@ -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)

View File

@ -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;

View File

@ -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);
}
/**