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 37b158c4eaa8789681a35554b629c7598c92407c Author: Matt Juntunen <[email protected]> AuthorDate: Mon Sep 3 00:08:22 2018 -0400 removing overloading of 'of' method for points and vectors; this allows those methods to be used directly as method references and removes the need for internal factory objects, which simplifies the code --- .../geometry/enclosing/WelzlEncloser3DTest.java | 4 +- .../threed/enclosing/SphereGeneratorTest.java | 4 +- .../twod/enclosing/DiskGeneratorTest.java | 4 +- .../commons/geometry/euclidean/oned/Point1D.java | 21 +----- .../commons/geometry/euclidean/oned/Vector1D.java | 15 +---- .../commons/geometry/euclidean/threed/Point3D.java | 25 +------ .../euclidean/threed/SphericalCoordinates.java | 16 +---- .../geometry/euclidean/threed/Vector3D.java | 17 +---- .../commons/geometry/euclidean/twod/Point2D.java | 25 +------ .../geometry/euclidean/twod/PolarCoordinates.java | 16 +---- .../commons/geometry/euclidean/twod/Vector2D.java | 17 +---- .../geometry/euclidean/oned/Point1DTest.java | 12 ---- .../geometry/euclidean/threed/Point3DTest.java | 21 ++---- .../euclidean/threed/SphericalCoordinatesTest.java | 2 +- .../geometry/euclidean/threed/Vector3DTest.java | 10 +-- .../geometry/euclidean/twod/Point2DTest.java | 19 ++---- .../euclidean/twod/PolarCoordinatesTest.java | 4 +- .../geometry/euclidean/twod/Vector2DTest.java | 10 +-- .../commons/geometry/spherical/oned/S1Point.java | 13 +--- .../commons/geometry/spherical/twod/Circle.java | 4 +- .../commons/geometry/spherical/twod/Edge.java | 6 +- .../spherical/twod/PropertiesComputer.java | 2 +- .../commons/geometry/spherical/twod/S2Point.java | 15 +---- .../spherical/twod/SphericalPolygonsSet.java | 14 ++-- .../geometry/spherical/twod/CircleTest.java | 28 ++++---- .../spherical/twod/SphericalPolygonsSetTest.java | 76 +++++++++++----------- 26 files changed, 118 insertions(+), 282 deletions(-) diff --git a/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/enclosing/WelzlEncloser3DTest.java b/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/enclosing/WelzlEncloser3DTest.java index b7fc5e0..8d5e3d2 100644 --- a/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/enclosing/WelzlEncloser3DTest.java +++ b/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/enclosing/WelzlEncloser3DTest.java @@ -109,13 +109,13 @@ public class WelzlEncloser3DTest { // define the reference sphere we want to compute double d = 25 * random.nextDouble(); double refRadius = 10 * random.nextDouble(); - Point3D refCenter = Point3D.vectorCombination(d, Point3D.of(sr.nextVector())); + Point3D refCenter = Point3D.vectorCombination(d, Point3D.ofArray(sr.nextVector())); // set up a large sample inside the reference sphere int nbPoints = random.nextInt(1000); List<Point3D> points = new ArrayList<>(); for (int i = 0; i < nbPoints; ++i) { double r = refRadius * random.nextDouble(); - points.add(Point3D.vectorCombination(1.0, refCenter, r, Point3D.of(sr.nextVector()))); + points.add(Point3D.vectorCombination(1.0, refCenter, r, Point3D.ofArray(sr.nextVector()))); } // test we find a sphere at most as large as the one used for random drawings diff --git a/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/euclidean/threed/enclosing/SphereGeneratorTest.java b/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/euclidean/threed/enclosing/SphereGeneratorTest.java index b65d726..8ab75e4 100644 --- a/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/euclidean/threed/enclosing/SphereGeneratorTest.java +++ b/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/euclidean/threed/enclosing/SphereGeneratorTest.java @@ -139,10 +139,10 @@ public class SphereGeneratorTest { for (int i = 0; i < 100; ++i) { double d = 25 * random.nextDouble(); double refRadius = 10 * random.nextDouble(); - Point3D refCenter = Point3D.vectorCombination(d, Point3D.of(sr.nextVector())); + Point3D refCenter = Point3D.vectorCombination(d, Point3D.ofArray(sr.nextVector())); List<Point3D> support = new ArrayList<>(); for (int j = 0; j < 5; ++j) { - support.add(Point3D.vectorCombination(1.0, refCenter, refRadius, Point3D.of(sr.nextVector()))); + support.add(Point3D.vectorCombination(1.0, refCenter, refRadius, Point3D.ofArray(sr.nextVector()))); } EnclosingBall<Point3D> sphere = new SphereGenerator().ballOnSupport(support); Assert.assertEquals(0.0, refCenter.distance(sphere.getCenter()), 4e-7 * refRadius); diff --git a/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/euclidean/twod/enclosing/DiskGeneratorTest.java b/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/euclidean/twod/enclosing/DiskGeneratorTest.java index 8770b6b..e5972e5 100644 --- a/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/euclidean/twod/enclosing/DiskGeneratorTest.java +++ b/commons-geometry-enclosing/src/test/java/org/apache/commons/geometry/euclidean/twod/enclosing/DiskGeneratorTest.java @@ -106,10 +106,10 @@ public class DiskGeneratorTest { for (int i = 0; i < 500; ++i) { double d = 25 * random.nextDouble(); double refRadius = 10 * random.nextDouble(); - Point2D refCenter = Point2D.vectorCombination(d, Point2D.of(sr.nextVector())); + Point2D refCenter = Point2D.vectorCombination(d, Point2D.ofArray(sr.nextVector())); List<Point2D> support = new ArrayList<>(); for (int j = 0; j < 3; ++j) { - support.add(Point2D.vectorCombination(1.0, refCenter, refRadius, Point2D.of(sr.nextVector()))); + support.add(Point2D.vectorCombination(1.0, refCenter, refRadius, Point2D.ofArray(sr.nextVector()))); } EnclosingBall<Point2D> disk = new DiskGenerator().ballOnSupport(support); Assert.assertEquals(0.0, refCenter.distance(disk.getCenter()), 3e-9 * refRadius); diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Point1D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Point1D.java index b304014..800f157 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Point1D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Point1D.java @@ -16,7 +16,6 @@ */ package org.apache.commons.geometry.euclidean.oned; -import org.apache.commons.geometry.core.internal.DoubleFunction1N; import org.apache.commons.geometry.core.internal.SimpleTupleFormat; import org.apache.commons.geometry.euclidean.EuclideanPoint; import org.apache.commons.numbers.arrays.LinearCombination; @@ -51,16 +50,6 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D /** Serializable UID. */ private static final long serialVersionUID = 20180710L; - /** Factory for delegating instance creation. */ - private static DoubleFunction1N<Point1D> FACTORY = new DoubleFunction1N<Point1D>() { - - /** {@inheritDoc} */ - @Override - public Point1D apply(double n) { - return new Point1D(n); - } - }; - /** Simple constructor. * @param x abscissa (coordinate value) */ @@ -162,14 +151,6 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D return new Point1D(x); } - /** Returns a point instance with the given coordinate value. - * @param value point coordinate - * @return point instance - */ - public static Point1D of(Cartesian1D value) { - return new Point1D(value.getX()); - } - /** Parses the given string and returns a new point instance. The expected string * format is the same as that returned by {@link #toString()}. * @param str the string to parse @@ -177,7 +158,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D * @throws IllegalArgumentException if the given string has an invalid format */ public static Point1D parse(String str) throws IllegalArgumentException { - return SimpleTupleFormat.getDefault().parse(str, FACTORY); + return SimpleTupleFormat.getDefault().parse(str, Point1D::new); } /** Linearly interpolates between the two given points. This methods simply diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java index dea8636..be97a91 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java @@ -16,7 +16,6 @@ */ package org.apache.commons.geometry.euclidean.oned; -import org.apache.commons.geometry.core.internal.DoubleFunction1N; import org.apache.commons.geometry.core.internal.SimpleTupleFormat; import org.apache.commons.geometry.core.util.Vectors; import org.apache.commons.geometry.euclidean.EuclideanVector; @@ -55,16 +54,6 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point /** Error message when a norm is zero. */ private static final String ZERO_NORM_MSG = "Norm is zero"; - /** Factory for delegating instance creation. */ - private static DoubleFunction1N<Vector1D> FACTORY = new DoubleFunction1N<Vector1D>() { - - /** {@inheritDoc} */ - @Override - public Vector1D apply(double n) { - return new Vector1D(n); - } - }; - /** Simple constructor. * @param x abscissa (coordinate value) */ @@ -75,7 +64,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public Point1D asPoint() { - return Point1D.of(this); + return Point1D.of(getX()); } /** {@inheritDoc} */ @@ -284,7 +273,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point * @throws IllegalArgumentException if the given string has an invalid format */ public static Vector1D parse(String str) throws IllegalArgumentException { - return SimpleTupleFormat.getDefault().parse(str, FACTORY); + return SimpleTupleFormat.getDefault().parse(str, Vector1D::new); } /** Linearly interpolates between the two given vectors. This methods simply diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Point3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Point3D.java index f8146a5..52c574b 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Point3D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Point3D.java @@ -17,7 +17,6 @@ package org.apache.commons.geometry.euclidean.threed; -import org.apache.commons.geometry.core.internal.DoubleFunction3N; import org.apache.commons.geometry.core.internal.SimpleTupleFormat; import org.apache.commons.geometry.core.util.Vectors; import org.apache.commons.geometry.euclidean.EuclideanPoint; @@ -44,16 +43,6 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D public static final Point3D NEGATIVE_INFINITY = new Point3D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY); - /** Package private factory for delegating instance creation. */ - static final DoubleFunction3N<Point3D> FACTORY = new DoubleFunction3N<Point3D>() { - - /** {@inheritDoc} */ - @Override - public Point3D apply(double n1, double n2, double n3) { - return new Point3D(n1, n2, n3); - } - }; - /** Serializable version identifier. */ private static final long serialVersionUID = 20180710L; @@ -174,20 +163,12 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D return new Point3D(x, y, z); } - /** Returns a point with the given coordinates. - * @param value coordinate values - * @return point instance - */ - public static Point3D of(Cartesian3D value) { - return new Point3D(value.getX(), value.getY(), value.getZ()); - } - /** Creates a point from the coordinates in the given 3-element array. * @param p coordinates array * @return new point * @exception IllegalArgumentException if the array does not have 3 elements */ - public static Point3D of(double[] p) { + public static Point3D ofArray(double[] p) { if (p.length != 3) { throw new IllegalArgumentException("Dimension mismatch: " + p.length + " != 3"); } @@ -202,7 +183,7 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D * @return a point instance with the given set of spherical coordinates */ public static Point3D ofSpherical(double radius, double azimuth, double polar) { - return SphericalCoordinates.toCartesian(radius, azimuth, polar, FACTORY); + return SphericalCoordinates.toCartesian(radius, azimuth, polar, Point3D::new); } /** Parses the given string and returns a new point instance. The expected string @@ -212,7 +193,7 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D * @throws IllegalArgumentException if the given string has an invalid format */ public static Point3D parse(String str) throws IllegalArgumentException { - return SimpleTupleFormat.getDefault().parse(str, FACTORY); + return SimpleTupleFormat.getDefault().parse(str, Point3D::new); } /** Linearly interpolates between the two given points. This methods simply 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 86b664c..9c244d0 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 @@ -70,16 +70,6 @@ public final class SphericalCoordinates implements Spatial, Serializable { /** Serializable version identifier. */ private static final long serialVersionUID = 20180623L; - /** Factory object for delegating instance creation. */ - private static final DoubleFunction3N<SphericalCoordinates> FACTORY = new DoubleFunction3N<SphericalCoordinates>() { - - /** {@inheritDoc} */ - @Override - public SphericalCoordinates apply(double n1, double n2, double n3) { - return new SphericalCoordinates(n1, n2, n3); - } - }; - /** Radius value. */ private final double radius; @@ -153,7 +143,7 @@ public final class SphericalCoordinates implements Spatial, Serializable { * coordinates. */ public Vector3D toVector() { - return toCartesian(radius, azimuth, polar, Vector3D.FACTORY); + return toCartesian(radius, azimuth, polar, Vector3D::of); } /** Convert this set of spherical coordinates to a 3 dimensional point. @@ -161,7 +151,7 @@ public final class SphericalCoordinates implements Spatial, Serializable { * coordinates. */ public Point3D toPoint() { - return toCartesian(radius, azimuth, polar, Point3D.FACTORY); + return toCartesian(radius, azimuth, polar, Point3D::of); } /** Get a hashCode for this set of spherical coordinates. @@ -257,7 +247,7 @@ public final class SphericalCoordinates implements Spatial, Serializable { * @throws IllegalArgumentException if the string format is invalid. */ public static SphericalCoordinates parse(String input) { - return SimpleTupleFormat.getDefault().parse(input, FACTORY); + return SimpleTupleFormat.getDefault().parse(input, SphericalCoordinates::new); } /** Normalize an azimuth value to be within the range {@code [0, 2pi)}. This diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java index 0f28c22..640f232 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java @@ -17,7 +17,6 @@ package org.apache.commons.geometry.euclidean.threed; import org.apache.commons.geometry.core.MultiDimensionalVector; -import org.apache.commons.geometry.core.internal.DoubleFunction3N; import org.apache.commons.geometry.core.internal.SimpleTupleFormat; import org.apache.commons.geometry.core.util.Vectors; import org.apache.commons.geometry.euclidean.EuclideanVector; @@ -62,16 +61,6 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point public static final Vector3D NEGATIVE_INFINITY = new Vector3D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY); - /** Package private factory for delegating instance creation. */ - static final DoubleFunction3N<Vector3D> FACTORY = new DoubleFunction3N<Vector3D>() { - - /** {@inheritDoc} */ - @Override - public Vector3D apply(double n1, double n2, double n3) { - return new Vector3D(n1, n2, n3); - } - }; - /** Serializable UID */ private static final long serialVersionUID = 20180710L; @@ -508,7 +497,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point * @return new vector * @exception IllegalArgumentException if the array does not have 3 elements */ - public static Vector3D of(double[] v) { + public static Vector3D ofArray(double[] v) { if (v.length != 3) { throw new IllegalArgumentException("Dimension mismatch: " + v.length + " != 3"); } @@ -523,7 +512,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point * @return a vector instance with the given set of spherical coordinates */ public static Vector3D ofSpherical(double radius, double azimuth, double polar) { - return SphericalCoordinates.toCartesian(radius, azimuth, polar, FACTORY); + return SphericalCoordinates.toCartesian(radius, azimuth, polar, Vector3D::new); } /** Parses the given string and returns a new vector instance. The expected string @@ -533,7 +522,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point * @throws IllegalArgumentException if the given string has an invalid format */ public static Vector3D parse(String str) throws IllegalArgumentException { - return SimpleTupleFormat.getDefault().parse(str, FACTORY); + return SimpleTupleFormat.getDefault().parse(str, Vector3D::new); } /** Linearly interpolates between the two given vectors. This methods simply diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Point2D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Point2D.java index 5f781d4..f4be64e 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Point2D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Point2D.java @@ -16,7 +16,6 @@ */ package org.apache.commons.geometry.euclidean.twod; -import org.apache.commons.geometry.core.internal.DoubleFunction2N; import org.apache.commons.geometry.core.internal.SimpleTupleFormat; import org.apache.commons.geometry.core.util.Vectors; import org.apache.commons.geometry.euclidean.EuclideanPoint; @@ -43,16 +42,6 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D public static final Point2D NEGATIVE_INFINITY = new Point2D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY); - /** Package private factory for delegating instance creation. */ - static final DoubleFunction2N<Point2D> FACTORY = new DoubleFunction2N<Point2D>() { - - /** {@inheritDoc} */ - @Override - public Point2D apply(double n1, double n2) { - return new Point2D(n1, n2); - } - }; - /** Serializable UID. */ private static final long serialVersionUID = 20180710L; @@ -159,20 +148,12 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D return new Point2D(x, y); } - /** Returns a point with the given coordinates. - * @param value coordinate values - * @return point instance - */ - public static Point2D of(Cartesian2D value) { - return new Point2D(value.getX(), value.getY()); - } - /** Returns a point with the coordinates from the given 2-element array. * @param p coordinates array * @return new point * @exception IllegalArgumentException if the array does not have 2 elements */ - public static Point2D of(double[] p) { + public static Point2D ofArray(double[] p) { if (p.length != 2) { throw new IllegalArgumentException("Dimension mismatch: " + p.length + " != 2"); } @@ -185,7 +166,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D * @return point instance with coordinates equivalent to the given polar coordinates. */ public static Point2D ofPolar(final double radius, final double azimuth) { - return PolarCoordinates.toCartesian(radius, azimuth, FACTORY); + return PolarCoordinates.toCartesian(radius, azimuth, Point2D::new); } /** Parses the given string and returns a new point instance. The expected string @@ -195,7 +176,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D * @throws IllegalArgumentException if the given string has an invalid format */ public static Point2D parse(String str) throws IllegalArgumentException { - return SimpleTupleFormat.getDefault().parse(str, FACTORY); + return SimpleTupleFormat.getDefault().parse(str, Point2D::new); } /** Linearly interpolates between the two given points. This methods simply 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 c910629..cdf5b5b 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 @@ -55,16 +55,6 @@ public final class PolarCoordinates implements Spatial, Serializable { /** Serializable version UID */ private static final long serialVersionUID = 20180630L; - /** Factory object for delegating instance creation. */ - private static final DoubleFunction2N<PolarCoordinates> FACTORY = new DoubleFunction2N<PolarCoordinates>() { - - /** {@inheritDoc} */ - @Override - public PolarCoordinates apply(double n1, double n2) { - return new PolarCoordinates(n1, n2); - } - }; - /** Radius value */ private final double radius; @@ -125,7 +115,7 @@ public final class PolarCoordinates implements Spatial, Serializable { * coordinates. */ public Vector2D toVector() { - return toCartesian(radius, azimuth, Vector2D.FACTORY); + return toCartesian(radius, azimuth, Vector2D::of); } /** Convert this set of polar coordinates to a 2-dimensional @@ -134,7 +124,7 @@ public final class PolarCoordinates implements Spatial, Serializable { * coordinates. */ public Point2D toPoint() { - return toCartesian(radius, azimuth, Point2D.FACTORY); + return toCartesian(radius, azimuth, Point2D::of); } /** Get a hashCode for this set of polar coordinates. @@ -222,7 +212,7 @@ public final class PolarCoordinates implements Spatial, Serializable { * @throws IllegalArgumentException if the string format is invalid. */ public static PolarCoordinates parse(String input) { - return SimpleTupleFormat.getDefault().parse(input, FACTORY); + return SimpleTupleFormat.getDefault().parse(input, PolarCoordinates::new); } /** Normalize an azimuth value to be within the range {@code [0, 2pi)}. diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java index bf2b691..c94b52d 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java @@ -17,7 +17,6 @@ package org.apache.commons.geometry.euclidean.twod; import org.apache.commons.geometry.core.MultiDimensionalVector; -import org.apache.commons.geometry.core.internal.DoubleFunction2N; import org.apache.commons.geometry.core.internal.SimpleTupleFormat; import org.apache.commons.geometry.core.util.Vectors; import org.apache.commons.geometry.euclidean.EuclideanVector; @@ -56,16 +55,6 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point public static final Vector2D NEGATIVE_INFINITY = new Vector2D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY); - /** Package private factory for delegating instance creation. */ - static final DoubleFunction2N<Vector2D> FACTORY = new DoubleFunction2N<Vector2D>() { - - /** {@inheritDoc} */ - @Override - public Vector2D apply(double n1, double n2) { - return new Vector2D(n1, n2); - } - }; - /** Serializable UID */ private static final long serialVersionUID = 20180710L; @@ -441,7 +430,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point * @return new vector * @exception IllegalArgumentException if the array does not have 2 elements */ - public static Vector2D of(double[] v) { + public static Vector2D ofArray(double[] v) { if (v.length != 2) { throw new IllegalArgumentException("Dimension mismatch: " + v.length + " != 2"); } @@ -454,7 +443,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point * @return vector instance with coordinates equivalent to the given polar coordinates. */ public static Vector2D ofPolar(final double radius, final double azimuth) { - return PolarCoordinates.toCartesian(radius, azimuth, Vector2D.FACTORY); + return PolarCoordinates.toCartesian(radius, azimuth, Vector2D::new); } /** Parses the given string and returns a new vector instance. The expected string @@ -464,7 +453,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point * @throws IllegalArgumentException if the given string has an invalid format */ public static Vector2D parse(String str) throws IllegalArgumentException { - return SimpleTupleFormat.getDefault().parse(str, FACTORY); + return SimpleTupleFormat.getDefault().parse(str, Vector2D::new); } /** Linearly interpolates between the two given vectors. This methods simply diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Point1DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Point1DTest.java index 262204f..e9379b1 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Point1DTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Point1DTest.java @@ -269,18 +269,6 @@ public class Point1DTest { } @Test - public void testOf_coordinateArg() { - // act/assert - checkPoint(Point1D.of(Vector1D.of(0)), 0.0); - checkPoint(Point1D.of(Vector1D.of(-1)), -1.0); - checkPoint(Point1D.of(Vector1D.of(1)), 1.0); - checkPoint(Point1D.of(Vector1D.of(Math.PI)), Math.PI); - checkPoint(Point1D.of(Vector1D.of(Double.NaN)), Double.NaN); - checkPoint(Point1D.of(Vector1D.of(Double.NEGATIVE_INFINITY)), Double.NEGATIVE_INFINITY); - checkPoint(Point1D.of(Vector1D.of(Double.POSITIVE_INFINITY)), Double.POSITIVE_INFINITY); - } - - @Test public void testVectorCombination() { // act/assert checkPoint(Point1D.vectorCombination(2, Point1D.of(3)), 6); diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Point3DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Point3DTest.java index 17bfcb5..df54e58 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Point3DTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Point3DTest.java @@ -267,31 +267,20 @@ public class Point3DTest { } @Test - public void testOf_coordinateArg() { - // act/assert - checkPoint(Point3D.of(Vector3D.of(1, 2, 3)), 1, 2, 3); - checkPoint(Point3D.of(Vector3D.of(-1, -2, -3)), -1, -2, -3); - checkPoint(Point3D.of(Vector3D.of(Math.PI, Double.NaN, Double.POSITIVE_INFINITY)), - Math.PI, Double.NaN, Double.POSITIVE_INFINITY); - checkPoint(Point3D.of(Vector3D.of(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E)), - Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E); - } - - @Test public void testOf_arrayArg() { // act/assert - checkPoint(Point3D.of(new double[] { 1, 2, 3 }), 1, 2, 3); - checkPoint(Point3D.of(new double[] { -1, -2, -3 }), -1, -2, -3); - checkPoint(Point3D.of(new double[] { Math.PI, Double.NaN, Double.POSITIVE_INFINITY }), + checkPoint(Point3D.ofArray(new double[] { 1, 2, 3 }), 1, 2, 3); + checkPoint(Point3D.ofArray(new double[] { -1, -2, -3 }), -1, -2, -3); + checkPoint(Point3D.ofArray(new double[] { Math.PI, Double.NaN, Double.POSITIVE_INFINITY }), Math.PI, Double.NaN, Double.POSITIVE_INFINITY); - checkPoint(Point3D.of(new double[] { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E}), + checkPoint(Point3D.ofArray(new double[] { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E}), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E); } @Test(expected = IllegalArgumentException.class) public void testOf_arrayArg_invalidDimensions() { // act/assert - Point3D.of(new double[] { 0.0, 0.0 }); + Point3D.ofArray(new double[] { 0.0, 0.0 }); } @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 ce4f03f..61339dd 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 @@ -180,7 +180,7 @@ public class SphericalCoordinatesTest { public void testToCartesian_static() { // arrange double sqrt3 = Math.sqrt(3); - DoubleFunction3N<Point3D> factory = Point3D.FACTORY; + DoubleFunction3N<Point3D> factory = Point3D::of; // act/assert checkPoint(SphericalCoordinates.toCartesian(0, 0, 0, factory), 0, 0, 0); diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java index 4febb3b..4880438 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java @@ -958,18 +958,18 @@ public class Vector3DTest { @Test public void testOf_arrayArg() { // act/assert - checkVector(Vector3D.of(new double[] { 1, 2, 3 }), 1, 2, 3); - checkVector(Vector3D.of(new double[] { -1, -2, -3 }), -1, -2, -3); - checkVector(Vector3D.of(new double[] { Math.PI, Double.NaN, Double.POSITIVE_INFINITY }), + checkVector(Vector3D.ofArray(new double[] { 1, 2, 3 }), 1, 2, 3); + checkVector(Vector3D.ofArray(new double[] { -1, -2, -3 }), -1, -2, -3); + checkVector(Vector3D.ofArray(new double[] { Math.PI, Double.NaN, Double.POSITIVE_INFINITY }), Math.PI, Double.NaN, Double.POSITIVE_INFINITY); - checkVector(Vector3D.of(new double[] { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E}), + checkVector(Vector3D.ofArray(new double[] { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E}), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E); } @Test(expected = IllegalArgumentException.class) public void testOf_arrayArg_invalidDimensions() { // act/assert - Vector3D.of(new double[] { 0.0, 0.0 }); + Vector3D.ofArray(new double[] { 0.0, 0.0 }); } @Test diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Point2DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Point2DTest.java index b3582ea..199abd2 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Point2DTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Point2DTest.java @@ -248,27 +248,18 @@ public class Point2DTest { } @Test - public void testOf_coordinateArg() { - // act/assert - checkPoint(Point2D.of(Vector2D.of(0, 1)), 0, 1); - checkPoint(Point2D.of(Vector2D.of(-1, -2)), -1, -2); - checkPoint(Point2D.of(Vector2D.of(Math.PI, Double.NaN)), Math.PI, Double.NaN); - checkPoint(Point2D.of(Vector2D.of(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY); - } - - @Test public void testOf_arrayArg() { // act/assert - checkPoint(Point2D.of(new double[] { 0, 1 }), 0, 1); - checkPoint(Point2D.of(new double[] { -1, -2 }), -1, -2); - checkPoint(Point2D.of(new double[] { Math.PI, Double.NaN }), Math.PI, Double.NaN); - checkPoint(Point2D.of(new double[] { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY); + checkPoint(Point2D.ofArray(new double[] { 0, 1 }), 0, 1); + checkPoint(Point2D.ofArray(new double[] { -1, -2 }), -1, -2); + checkPoint(Point2D.ofArray(new double[] { Math.PI, Double.NaN }), Math.PI, Double.NaN); + checkPoint(Point2D.ofArray(new double[] { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY); } @Test(expected = IllegalArgumentException.class) public void testOf_arrayArg_invalidDimensions() { // act/assert - Point2D.of(new double[] {0.0 }); + Point2D.ofArray(new double[] {0.0 }); } @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 524e7e0..7b36c31 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 @@ -257,7 +257,7 @@ public class PolarCoordinatesTest { @Test public void testToCartesian_static() { // arrange - DoubleFunction2N<Point2D> factory = Point2D.FACTORY; + DoubleFunction2N<Point2D> factory = Point2D::of; double sqrt2 = Math.sqrt(2); // act/assert @@ -278,7 +278,7 @@ public class PolarCoordinatesTest { @Test public void testToCartesian_static_NaNAndInfinite() { // arrange - DoubleFunction2N<Point2D> factory = Point2D.FACTORY; + DoubleFunction2N<Point2D> factory = Point2D::of; // act/assert Assert.assertTrue(PolarCoordinates.toCartesian(Double.NaN, 0, factory).isNaN()); diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java index 2af7341..1e3a1ba 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java @@ -730,16 +730,16 @@ public class Vector2DTest { @Test public void testOf_arrayArg() { // act/assert - checkVector(Vector2D.of(new double[] { 0, 1 }), 0, 1); - checkVector(Vector2D.of(new double[] { -1, -2 }), -1, -2); - checkVector(Vector2D.of(new double[] { Math.PI, Double.NaN }), Math.PI, Double.NaN); - checkVector(Vector2D.of(new double[] { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY); + checkVector(Vector2D.ofArray(new double[] { 0, 1 }), 0, 1); + checkVector(Vector2D.ofArray(new double[] { -1, -2 }), -1, -2); + checkVector(Vector2D.ofArray(new double[] { Math.PI, Double.NaN }), Math.PI, Double.NaN); + checkVector(Vector2D.ofArray(new double[] { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY); } @Test(expected = IllegalArgumentException.class) public void testOf_arrayArg_invalidDimensions() { // act/assert - Vector2D.of(new double[] {0.0 }); + Vector2D.ofArray(new double[] {0.0 }); } @Test 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 a9df1aa..1d6615f 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 @@ -19,7 +19,6 @@ package org.apache.commons.geometry.spherical.oned; import java.io.Serializable; import org.apache.commons.geometry.core.Point; -import org.apache.commons.geometry.core.internal.DoubleFunction1N; import org.apache.commons.geometry.core.internal.SimpleTupleFormat; import org.apache.commons.geometry.euclidean.twod.PolarCoordinates; import org.apache.commons.geometry.euclidean.twod.Vector2D; @@ -37,16 +36,6 @@ public final class S1Point implements Point<S1Point>, Serializable { /** Serializable UID. */ private static final long serialVersionUID = 20180710L; - /** Factory for delegating instance creation. */ - private static DoubleFunction1N<S1Point> FACTORY = new DoubleFunction1N<S1Point>() { - - /** {@inheritDoc} */ - @Override - public S1Point apply(double n) { - return new S1Point(n); - } - }; - /** Azimuthal angle in radians. */ private final double azimuth; @@ -183,6 +172,6 @@ public final class S1Point implements Point<S1Point>, Serializable { * @throws IllegalArgumentException if the given string has an invalid format */ public static S1Point parse(String str) throws IllegalArgumentException { - return SimpleTupleFormat.getDefault().parse(str, FACTORY); + return SimpleTupleFormat.getDefault().parse(str, S1Point::new); } } diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Circle.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Circle.java index e0aaba0..357eaba 100644 --- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Circle.java +++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Circle.java @@ -168,7 +168,7 @@ public class Circle implements Hyperplane<S2Point>, Embedding<S2Point, S1Point> */ @Override public S2Point toSpace(final S1Point point) { - return S2Point.of(getPointAt(point.getAzimuth())); + return S2Point.ofVector(getPointAt(point.getAzimuth())); } /** Get a circle point from its phase around the circle. @@ -306,7 +306,7 @@ public class Circle implements Hyperplane<S2Point>, Embedding<S2Point, S1Point> /** {@inheritDoc} */ @Override public S2Point apply(final S2Point point) { - return S2Point.of(rotation.applyTo(point.getVector())); + return S2Point.ofVector(rotation.applyTo(point.getVector())); } /** {@inheritDoc} */ diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Edge.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Edge.java index 609408a..27b0137 100644 --- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Edge.java +++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Edge.java @@ -148,7 +148,7 @@ public class Edge { if (unwrappedEnd >= 0) { // the start of the edge is inside the circle previousVertex = addSubEdge(previousVertex, - new Vertex(S2Point.of(circle.getPointAt(edgeStart + unwrappedEnd))), + new Vertex(S2Point.ofVector(circle.getPointAt(edgeStart + unwrappedEnd))), unwrappedEnd, insideList, splitCircle); alreadyManagedLength = unwrappedEnd; } @@ -166,7 +166,7 @@ public class Edge { } else { // the edge is long enough to enter inside the circle previousVertex = addSubEdge(previousVertex, - new Vertex(S2Point.of(circle.getPointAt(edgeStart + arcRelativeStart))), + new Vertex(S2Point.ofVector(circle.getPointAt(edgeStart + arcRelativeStart))), arcRelativeStart - alreadyManagedLength, outsideList, splitCircle); alreadyManagedLength = arcRelativeStart; @@ -177,7 +177,7 @@ public class Edge { } else { // the edge is long enough to exit outside of the circle previousVertex = addSubEdge(previousVertex, - new Vertex(S2Point.of(circle.getPointAt(edgeStart + arcRelativeStart))), + new Vertex(S2Point.ofVector(circle.getPointAt(edgeStart + arcRelativeStart))), arcRelativeStart - alreadyManagedLength, insideList, splitCircle); alreadyManagedLength = arcRelativeStart; previousVertex = addSubEdge(previousVertex, end, diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/PropertiesComputer.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/PropertiesComputer.java index 258b17e..982c8af 100644 --- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/PropertiesComputer.java +++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/PropertiesComputer.java @@ -160,7 +160,7 @@ class PropertiesComputer implements BSPTreeVisitor<S2Point> { if (summedBarycenter.getNormSq() == 0) { return S2Point.NaN; } else { - return S2Point.of(summedBarycenter); + return S2Point.ofVector(summedBarycenter); } } 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 1031b4b..cd78701 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 @@ -19,7 +19,6 @@ package org.apache.commons.geometry.spherical.twod; import java.io.Serializable; import org.apache.commons.geometry.core.Point; -import org.apache.commons.geometry.core.internal.DoubleFunction2N; import org.apache.commons.geometry.core.internal.SimpleTupleFormat; import org.apache.commons.geometry.euclidean.threed.SphericalCoordinates; import org.apache.commons.geometry.euclidean.threed.Vector3D; @@ -55,16 +54,6 @@ public final class S2Point implements Point<S2Point>, Serializable { /** Serializable UID. */ private static final long serialVersionUID = 20180710L; - /** Factory for delegating instance creation. */ - private static DoubleFunction2N<S2Point> FACTORY = new DoubleFunction2N<S2Point>() { - - /** {@inheritDoc} */ - @Override - public S2Point apply(double n1, double n2) { - return S2Point.of(n1, n2); - } - }; - /** Azimuthal angle in the x-y plane. */ private final double azimuth; @@ -221,7 +210,7 @@ public final class S2Point implements Point<S2Point>, Serializable { * @return point instance with the coordinates determined by the given 3D vector * @exception IllegalStateException if vector norm is zero */ - public static S2Point of(final Vector3D vector) { + public static S2Point ofVector(final Vector3D vector) { SphericalCoordinates coords = vector.toSpherical(); return new S2Point(coords.getAzimuth(), coords.getPolar(), vector.normalize()); @@ -234,6 +223,6 @@ public final class S2Point implements Point<S2Point>, Serializable { * @throws IllegalArgumentException if the given string has an invalid format */ public static S2Point parse(String str) throws IllegalArgumentException { - return SimpleTupleFormat.getDefault().parse(str, FACTORY); + return SimpleTupleFormat.getDefault().parse(str, S2Point::of); } } diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSet.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSet.java index b1b6b50..fafac75 100644 --- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSet.java +++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSet.java @@ -161,11 +161,11 @@ public class SphericalPolygonsSet extends AbstractRegion<S2Point, S1Point> { final S2Point[] array = new S2Point[n]; final Rotation r0 = new Rotation(Vector3D.crossProduct(center, meridian), outsideRadius, RotationConvention.VECTOR_OPERATOR); - array[0] = S2Point.of(r0.applyTo(center)); + array[0] = S2Point.ofVector(r0.applyTo(center)); final Rotation r = new Rotation(center, Geometry.TWO_PI / n, RotationConvention.VECTOR_OPERATOR); for (int i = 1; i < n; ++i) { - array[i] = S2Point.of(r.applyTo(array[i - 1].getVector())); + array[i] = S2Point.ofVector(r.applyTo(array[i - 1].getVector())); } return array; @@ -478,13 +478,13 @@ public class SphericalPolygonsSet extends AbstractRegion<S2Point, S1Point> { if (isEmpty(root.getMinus()) && isFull(root.getPlus())) { // the polygon covers an hemisphere, and its boundary is one 2π long edge final Circle circle = (Circle) root.getCut().getHyperplane(); - return new EnclosingBall<>(S2Point.of(circle.getPole()).negate(), + return new EnclosingBall<>(S2Point.ofVector(circle.getPole()).negate(), 0.5 * Math.PI); } if (isFull(root.getMinus()) && isEmpty(root.getPlus())) { // the polygon covers an hemisphere, and its boundary is one 2π long edge final Circle circle = (Circle) root.getCut().getHyperplane(); - return new EnclosingBall<>(S2Point.of(circle.getPole()), + return new EnclosingBall<>(S2Point.ofVector(circle.getPole()), 0.5 * Math.PI); } @@ -517,7 +517,7 @@ public class SphericalPolygonsSet extends AbstractRegion<S2Point, S1Point> { EnclosingBall<S2Point> enclosingS2 = new EnclosingBall<>(S2Point.PLUS_K, Double.POSITIVE_INFINITY); for (Point3D outsidePoint : getOutsidePoints()) { - final S2Point outsideS2 = S2Point.of(outsidePoint.asVector()); + final S2Point outsideS2 = S2Point.ofVector(outsidePoint.asVector()); final BoundaryProjection<S2Point> projection = projectToBoundary(outsideS2); if (Math.PI - projection.getOffset() < enclosingS2.getRadius()) { enclosingS2 = new EnclosingBall<>(outsideS2.negate(), @@ -529,11 +529,11 @@ public class SphericalPolygonsSet extends AbstractRegion<S2Point, S1Point> { } final S2Point[] support = new S2Point[support3D.length]; for (int i = 0; i < support3D.length; ++i) { - support[i] = S2Point.of(support3D[i].asVector()); + support[i] = S2Point.ofVector(support3D[i].asVector()); } final EnclosingBall<S2Point> enclosingS2 = - new EnclosingBall<>(S2Point.of(enclosing3D.getCenter().asVector()), + new EnclosingBall<>(S2Point.ofVector(enclosing3D.getCenter().asVector()), Math.acos((1 + h * h - r * r) / (2 * h)), support); diff --git a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/CircleTest.java b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/CircleTest.java index 8e96248..f056acb 100644 --- a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/CircleTest.java +++ b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/CircleTest.java @@ -99,10 +99,10 @@ public class CircleTest { @Test public void testSubSpace() { Circle circle = new Circle(S2Point.of(1.2, 2.5), S2Point.of(-4.3, 0), 1.0e-10); - Assert.assertEquals(0.0, circle.toSubSpace(S2Point.of(circle.getXAxis())).getAzimuth(), 1.0e-10); - Assert.assertEquals(0.5 * Math.PI, circle.toSubSpace(S2Point.of(circle.getYAxis())).getAzimuth(), 1.0e-10); + Assert.assertEquals(0.0, circle.toSubSpace(S2Point.ofVector(circle.getXAxis())).getAzimuth(), 1.0e-10); + Assert.assertEquals(0.5 * Math.PI, circle.toSubSpace(S2Point.ofVector(circle.getYAxis())).getAzimuth(), 1.0e-10); Vector3D p = Vector3D.of(1, 2, -4); - Assert.assertEquals(circle.getPhase(p), circle.toSubSpace(S2Point.of(p)).getAzimuth(), 1.0e-10); + Assert.assertEquals(circle.getPhase(p), circle.toSubSpace(S2Point.ofVector(p)).getAzimuth(), 1.0e-10); } @Test @@ -120,12 +120,12 @@ public class CircleTest { @Test public void testOffset() { Circle circle = new Circle(Vector3D.PLUS_Z, 1.0e-10); - Assert.assertEquals(0.0, circle.getOffset(S2Point.of(Vector3D.PLUS_X)), 1.0e-10); - Assert.assertEquals(0.0, circle.getOffset(S2Point.of(Vector3D.MINUS_X)), 1.0e-10); - Assert.assertEquals(0.0, circle.getOffset(S2Point.of(Vector3D.PLUS_Y)), 1.0e-10); - Assert.assertEquals(0.0, circle.getOffset(S2Point.of(Vector3D.MINUS_Y)), 1.0e-10); - Assert.assertEquals(-0.5 * Math.PI, circle.getOffset(S2Point.of(Vector3D.PLUS_Z)), 1.0e-10); - Assert.assertEquals(0.5 * Math.PI, circle.getOffset(S2Point.of(Vector3D.MINUS_Z)), 1.0e-10); + Assert.assertEquals(0.0, circle.getOffset(S2Point.ofVector(Vector3D.PLUS_X)), 1.0e-10); + Assert.assertEquals(0.0, circle.getOffset(S2Point.ofVector(Vector3D.MINUS_X)), 1.0e-10); + Assert.assertEquals(0.0, circle.getOffset(S2Point.ofVector(Vector3D.PLUS_Y)), 1.0e-10); + Assert.assertEquals(0.0, circle.getOffset(S2Point.ofVector(Vector3D.MINUS_Y)), 1.0e-10); + Assert.assertEquals(-0.5 * Math.PI, circle.getOffset(S2Point.ofVector(Vector3D.PLUS_Z)), 1.0e-10); + Assert.assertEquals(0.5 * Math.PI, circle.getOffset(S2Point.ofVector(Vector3D.MINUS_Z)), 1.0e-10); } @@ -134,8 +134,8 @@ public class CircleTest { UnitSphereSampler sphRandom = new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A, 0xbfd34e92231bbcfel)); for (int i = 0; i < 100; ++i) { - Circle c1 = new Circle(Vector3D.of(sphRandom.nextVector()), 1.0e-10); - Circle c2 = new Circle(Vector3D.of(sphRandom.nextVector()), 1.0e-10); + Circle c1 = new Circle(Vector3D.ofArray(sphRandom.nextVector()), 1.0e-10); + Circle c2 = new Circle(Vector3D.ofArray(sphRandom.nextVector()), 1.0e-10); checkArcIsInside(c1, c2); checkArcIsInside(c2, c1); } @@ -159,16 +159,16 @@ public class CircleTest { UnitSphereSampler sphRandom = new UnitSphereSampler(3, random); for (int i = 0; i < 100; ++i) { - Rotation r = new Rotation(Vector3D.of(sphRandom.nextVector()), + Rotation r = new Rotation(Vector3D.ofArray(sphRandom.nextVector()), Math.PI * random.nextDouble(), RotationConvention.VECTOR_OPERATOR); Transform<S2Point, S1Point> t = Circle.getTransform(r); - S2Point p = S2Point.of(Vector3D.of(sphRandom.nextVector())); + S2Point p = S2Point.ofVector(Vector3D.ofArray(sphRandom.nextVector())); S2Point tp = t.apply(p); Assert.assertEquals(0.0, r.applyTo(p.getVector()).distance(tp.getVector()), 1.0e-10); - Circle c = new Circle(Vector3D.of(sphRandom.nextVector()), 1.0e-10); + Circle c = new Circle(Vector3D.ofArray(sphRandom.nextVector()), 1.0e-10); Circle tc = (Circle) t.apply(c); Assert.assertEquals(0.0, r.applyTo(c.getPole()).distance(tc.getPole()), 1.0e-10); Assert.assertEquals(0.0, r.applyTo(c.getXAxis()).distance(tc.getXAxis()), 1.0e-10); diff --git a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSetTest.java b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSetTest.java index ce6b231..1051ea2 100644 --- a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSetTest.java +++ b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSetTest.java @@ -42,8 +42,8 @@ public class SphericalPolygonsSetTest { new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A, 0x852fd2a0ed8d2f6dl)); for (int i = 0; i < 1000; ++i) { - Vector3D v = Vector3D.of(random.nextVector()); - Assert.assertEquals(Location.INSIDE, full.checkPoint(S2Point.of(v))); + Vector3D v = Vector3D.ofArray(random.nextVector()); + Assert.assertEquals(Location.INSIDE, full.checkPoint(S2Point.ofVector(v))); } Assert.assertEquals(4 * Math.PI, new SphericalPolygonsSet(0.01, new S2Point[0]).getSize(), 1.0e-10); Assert.assertEquals(0, new SphericalPolygonsSet(0.01, new S2Point[0]).getBoundarySize(), 1.0e-10); @@ -60,8 +60,8 @@ public class SphericalPolygonsSetTest { new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A, 0x76d9205d6167b6ddl)); for (int i = 0; i < 1000; ++i) { - Vector3D v = Vector3D.of(random.nextVector()); - Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(S2Point.of(v))); + Vector3D v = Vector3D.ofArray(random.nextVector()); + Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(S2Point.ofVector(v))); } Assert.assertEquals(0, empty.getSize(), 1.0e-10); Assert.assertEquals(0, empty.getBoundarySize(), 1.0e-10); @@ -79,13 +79,13 @@ public class SphericalPolygonsSetTest { new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A, 0x6b9d4a6ad90d7b0bl)); for (int i = 0; i < 1000; ++i) { - Vector3D v = Vector3D.of(random.nextVector()); + Vector3D v = Vector3D.ofArray(random.nextVector()); if (v.getZ() < -sinTol) { - Assert.assertEquals(Location.INSIDE, south.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.INSIDE, south.checkPoint(S2Point.ofVector(v))); } else if (v.getZ() > sinTol) { - Assert.assertEquals(Location.OUTSIDE, south.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.OUTSIDE, south.checkPoint(S2Point.ofVector(v))); } else { - Assert.assertEquals(Location.BOUNDARY, south.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.BOUNDARY, south.checkPoint(S2Point.ofVector(v))); } } Assert.assertEquals(1, south.getBoundaryLoops().size()); @@ -115,13 +115,13 @@ public class SphericalPolygonsSetTest { new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A, 0x9c9802fde3cbcf25l)); for (int i = 0; i < 1000; ++i) { - Vector3D v = Vector3D.of(random.nextVector()); + Vector3D v = Vector3D.ofArray(random.nextVector()); if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) { - Assert.assertEquals(Location.INSIDE, octant.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.INSIDE, octant.checkPoint(S2Point.ofVector(v))); } else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) { - Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(S2Point.ofVector(v))); } else { - Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(S2Point.ofVector(v))); } } @@ -156,7 +156,7 @@ public class SphericalPolygonsSetTest { Assert.assertEquals(3, count); Assert.assertEquals(0.0, - octant.getBarycenter().distance(S2Point.of(Vector3D.of(1, 1, 1))), + octant.getBarycenter().distance(S2Point.ofVector(Vector3D.of(1, 1, 1))), 1.0e-10); Assert.assertEquals(0.5 * Math.PI, octant.getSize(), 1.0e-10); @@ -166,7 +166,7 @@ public class SphericalPolygonsSetTest { EnclosingBall<S2Point> reversedCap = ((SphericalPolygonsSet) factory.getComplement(octant)).getEnclosingCap(); - Assert.assertEquals(0, reversedCap.getCenter().distance(S2Point.of(Vector3D.of(-1, -1, -1))), 1.0e-10); + Assert.assertEquals(0, reversedCap.getCenter().distance(S2Point.ofVector(Vector3D.of(-1, -1, -1))), 1.0e-10); Assert.assertEquals(Math.PI - Math.asin(1.0 / Math.sqrt(3)), reversedCap.getRadius(), 1.0e-10); } @@ -180,13 +180,13 @@ public class SphericalPolygonsSetTest { new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A, 0xb8fc5acc91044308l)); for (int i = 0; i < 1000; ++i) { - Vector3D v = Vector3D.of(random.nextVector()); + Vector3D v = Vector3D.ofArray(random.nextVector()); if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) { - Assert.assertEquals(Location.INSIDE, octant.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.INSIDE, octant.checkPoint(S2Point.ofVector(v))); } else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) { - Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(S2Point.ofVector(v))); } else { - Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(S2Point.ofVector(v))); } } } @@ -206,13 +206,13 @@ public class SphericalPolygonsSetTest { new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A, 0x9c9802fde3cbcf25l)); for (int i = 0; i < 1000; ++i) { - Vector3D v = Vector3D.of(random.nextVector()); + Vector3D v = Vector3D.ofArray(random.nextVector()); if (((v.getX() < -sinTol) || (v.getY() < -sinTol)) && (v.getZ() > sinTol)) { - Assert.assertEquals(Location.INSIDE, threeOctants.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.INSIDE, threeOctants.checkPoint(S2Point.ofVector(v))); } else if (((v.getX() > sinTol) && (v.getY() > sinTol)) || (v.getZ() < -sinTol)) { - Assert.assertEquals(Location.OUTSIDE, threeOctants.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.OUTSIDE, threeOctants.checkPoint(S2Point.ofVector(v))); } else { - Assert.assertEquals(Location.BOUNDARY, threeOctants.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.BOUNDARY, threeOctants.checkPoint(S2Point.ofVector(v))); } } @@ -274,14 +274,14 @@ public class SphericalPolygonsSetTest { boundary.add(create(Vector3D.PLUS_Z, Vector3D.MINUS_Y, Vector3D.PLUS_X, tol, 0.0, 0.5 * Math.PI)); SphericalPolygonsSet polygon = new SphericalPolygonsSet(boundary, tol); - Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.of(Vector3D.of( 1, 1, 1).normalize()))); - Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.of(Vector3D.of(-1, 1, 1).normalize()))); - Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.of(Vector3D.of(-1, -1, 1).normalize()))); - Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.of(Vector3D.of( 1, -1, 1).normalize()))); - Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.of(Vector3D.of( 1, 1, -1).normalize()))); - Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.of(Vector3D.of(-1, 1, -1).normalize()))); - Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.of(Vector3D.of(-1, -1, -1).normalize()))); - Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.of(Vector3D.of( 1, -1, -1).normalize()))); + Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.ofVector(Vector3D.of( 1, 1, 1).normalize()))); + Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.ofVector(Vector3D.of(-1, 1, 1).normalize()))); + Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.ofVector(Vector3D.of(-1, -1, 1).normalize()))); + Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.ofVector(Vector3D.of( 1, -1, 1).normalize()))); + Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.ofVector(Vector3D.of( 1, 1, -1).normalize()))); + Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.ofVector(Vector3D.of(-1, 1, -1).normalize()))); + Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.ofVector(Vector3D.of(-1, -1, -1).normalize()))); + Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.ofVector(Vector3D.of( 1, -1, -1).normalize()))); Assert.assertEquals(Geometry.TWO_PI, polygon.getSize(), 1.0e-10); Assert.assertEquals(3 * Math.PI, polygon.getBoundarySize(), 1.0e-10); @@ -340,17 +340,17 @@ public class SphericalPolygonsSetTest { new UnitSphereSampler(3, RandomSource.create(RandomSource.WELL_1024_A, 0xcc5ce49949e0d3ecl)); for (int i = 0; i < 1000; ++i) { - Vector3D v = Vector3D.of(random.nextVector()); + Vector3D v = Vector3D.ofArray(random.nextVector()); if ((v.getX() < -sinTol) && (v.getY() < -sinTol) && (v.getZ() < -sinTol)) { - Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.ofVector(v))); } else if ((v.getX() < sinTol) && (v.getY() < sinTol) && (v.getZ() < sinTol)) { - Assert.assertEquals(Location.BOUNDARY, polygon.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.BOUNDARY, polygon.checkPoint(S2Point.ofVector(v))); } else if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) { - Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.INSIDE, polygon.checkPoint(S2Point.ofVector(v))); } else if ((v.getX() > -sinTol) && (v.getY() > -sinTol) && (v.getZ() > -sinTol)) { - Assert.assertEquals(Location.BOUNDARY, polygon.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.BOUNDARY, polygon.checkPoint(S2Point.ofVector(v))); } else { - Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.of(v))); + Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(S2Point.ofVector(v))); } } @@ -366,7 +366,7 @@ public class SphericalPolygonsSetTest { public void testPartWithHole() { double tol = 0.01; double alpha = 0.7; - S2Point center = S2Point.of(Vector3D.of(1, 1, 1)); + S2Point center = S2Point.ofVector(Vector3D.of(1, 1, 1)); SphericalPolygonsSet hexa = new SphericalPolygonsSet(center.getVector(), Vector3D.PLUS_Z, alpha, 6, tol); SphericalPolygonsSet hole = new SphericalPolygonsSet(tol, S2Point.of(Math.PI / 6, Math.PI / 3), @@ -428,7 +428,7 @@ public class SphericalPolygonsSetTest { concentric.getSize(), 1.0e-10); // we expect lots of sign changes as we traverse all concentric rings - double phi = S2Point.of(center).getPolar(); + double phi = S2Point.ofVector(center).getPolar(); Assert.assertEquals(+0.207, concentric.projectToBoundary(S2Point.of(-0.60, phi)).getOffset(), 0.01); Assert.assertEquals(-0.048, concentric.projectToBoundary(S2Point.of(-0.21, phi)).getOffset(), 0.01); Assert.assertEquals(+0.027, concentric.projectToBoundary(S2Point.of(-0.10, phi)).getOffset(), 0.01);
