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 2018/09/14 00:20:33 UTC

[commons-geometry] branch master updated (d7b4a10 -> adbdc69)

This is an automated email from the ASF dual-hosted git repository.

erans pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-geometry.git.


    from d7b4a10  Merge branch 'GEOMETRY-7__matt'
     new b329f9b  GEOMETRY-9: adding getMagnitude, getMagnitudeSq, and withMagnitude methods to Euclidean vectors; creating Vectors utility class to encapsulate vector norm methods
     new 40a40bc  merging with master
     new 9d09f78  removing unnecessary Vector?D.of(Cartesian?D) methods; conversion between points and vectors can be accomplished with toPoint() and toVector() methods
     new 03e4ff4  GEOMETRY-9: moving magnitude methods to main Vector interface; simplifying 1D magnitude/normalize methods
     new a78ced7  GEOMETRY-9: adding project and reject methods to Vector2D and Vector3D; adding MultiDimensionalVector interface to contain new methods
     new 2f44549  GEOMETRY-9: adding static project and reject methods
     new 43cbc50  GEOMETRY-9: adding lerp method to Euclidean points and vectors
     new 443a0a3  fixing report errors
     new 37b158c  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
     new 204b994  GEOMETRY-9, GEOMETRY-8: removing MultiDimensionalVector class since project, reject, and angle do not require more than one dimension to work mathematically; adding internal ZeroNormException class
     new 5cfca2a  GEOMETRY-9: making Vectors class internal per pull request discussion
     new 45bffa7  GEOMETRY-9: removing Point?D/Vector?D static convenience methods to clean up API, per pull request discussion
     new df6704f  Unchecked exceptions should not appear in the "throws" clause.
     new adbdc69  Merge branch 'GEOMETRY-9__matt'

The 14 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/commons/geometry/core/Vector.java   |  63 ++++-
 .../geometry/core/internal/SimpleTupleFormat.java  |  56 ++---
 .../commons/geometry/core/internal/Vectors.java    | 163 +++++++++++++
 .../geometry/core/internal/VectorsTest.java        | 179 ++++++++++++++
 .../geometry/enclosing/WelzlEncloser3DTest.java    |   6 +-
 .../threed/enclosing/SphereGeneratorTest.java      |   4 +-
 .../twod/enclosing/DiskGeneratorTest.java          |   4 +-
 .../commons/geometry/euclidean/EuclideanPoint.java |  12 +
 .../geometry/euclidean/EuclideanVector.java        |  12 +
 .../euclidean/internal/ZeroNormException.java      |  50 ++++
 .../geometry/euclidean/internal}/package-info.java |   7 +-
 .../commons/geometry/euclidean/oned/Point1D.java   |  34 +--
 .../commons/geometry/euclidean/oned/Vector1D.java  | 128 +++++++---
 .../geometry/euclidean/threed/Cartesian3D.java     |  13 --
 .../commons/geometry/euclidean/threed/Line.java    |   2 +-
 .../commons/geometry/euclidean/threed/Plane.java   |   4 +-
 .../commons/geometry/euclidean/threed/Point3D.java |  39 ++--
 .../geometry/euclidean/threed/Rotation.java        |   6 +-
 .../euclidean/threed/SphericalCoordinates.java     |  16 +-
 .../commons/geometry/euclidean/threed/SubLine.java |   2 +-
 .../geometry/euclidean/threed/Vector3D.java        | 218 +++++++++--------
 .../geometry/euclidean/twod/Cartesian2D.java       |  10 -
 .../geometry/euclidean/twod/NestedLoops.java       |   4 +-
 .../commons/geometry/euclidean/twod/Point2D.java   |  36 +--
 .../geometry/euclidean/twod/PolarCoordinates.java  |  16 +-
 .../commons/geometry/euclidean/twod/Vector2D.java  | 176 ++++++++------
 .../geometry/euclidean/oned/Point1DTest.java       |  39 +++-
 .../geometry/euclidean/oned/Vector1DTest.java      | 170 +++++++++++++-
 .../geometry/euclidean/threed/Point3DTest.java     |  47 ++--
 .../euclidean/threed/SphericalCoordinatesTest.java |   2 +-
 .../geometry/euclidean/threed/Vector3DTest.java    | 259 ++++++++++++++++-----
 .../geometry/euclidean/twod/Point2DTest.java       |  45 ++--
 .../euclidean/twod/PolarCoordinatesTest.java       |   4 +-
 .../geometry/euclidean/twod/Vector2DTest.java      | 232 +++++++++++++-----
 .../geometry/euclidean/twod/hull/ConvexHull2D.java |   2 +-
 .../commons/geometry/spherical/oned/S1Point.java   |  15 +-
 .../commons/geometry/spherical/twod/Circle.java    |   4 +-
 .../commons/geometry/spherical/twod/Edge.java      |   6 +-
 .../geometry/spherical/twod/EdgesBuilder.java      |   6 +-
 .../spherical/twod/PropertiesComputer.java         |   6 +-
 .../commons/geometry/spherical/twod/S2Point.java   |  17 +-
 .../spherical/twod/SphericalPolygonsSet.java       |  22 +-
 .../commons/geometry/spherical/twod/SubCircle.java |   3 +-
 .../geometry/spherical/twod/CircleTest.java        |  60 +++--
 .../spherical/twod/SphericalPolygonsSetTest.java   |  82 +++----
 45 files changed, 1602 insertions(+), 679 deletions(-)
 create mode 100644 commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/Vectors.java
 create mode 100644 commons-geometry-core/src/test/java/org/apache/commons/geometry/core/internal/VectorsTest.java
 create mode 100644 commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/ZeroNormException.java
 copy {commons-geometry-enclosing/src/main/java/org/apache/commons/geometry/euclidean/threed/enclosing => commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal}/package-info.java (78%)


[commons-geometry] 13/14: Unchecked exceptions should not appear in the "throws" clause.

Posted by er...@apache.org.
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 df6704fabf32d0455863df4ed2e41f9fb884ef37
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Fri Sep 14 02:16:24 2018 +0200

    Unchecked exceptions should not appear in the "throws" clause.
---
 .../geometry/core/internal/SimpleTupleFormat.java    | 20 ++++++++++----------
 .../geometry/enclosing/WelzlEncloser3DTest.java      |  2 +-
 .../commons/geometry/euclidean/oned/Point1D.java     |  2 +-
 .../commons/geometry/euclidean/oned/Vector1D.java    | 10 +++++-----
 .../commons/geometry/euclidean/threed/Line.java      |  2 +-
 .../commons/geometry/euclidean/threed/Plane.java     |  4 ++--
 .../commons/geometry/euclidean/threed/Point3D.java   |  2 +-
 .../commons/geometry/euclidean/threed/Rotation.java  |  4 ++--
 .../commons/geometry/euclidean/threed/SubLine.java   |  2 +-
 .../commons/geometry/euclidean/threed/Vector3D.java  | 16 ++++++++--------
 .../commons/geometry/euclidean/twod/NestedLoops.java |  4 ++--
 .../commons/geometry/euclidean/twod/Point2D.java     |  2 +-
 .../commons/geometry/euclidean/twod/Vector2D.java    | 14 +++++++-------
 .../geometry/euclidean/twod/hull/ConvexHull2D.java   |  2 +-
 .../commons/geometry/spherical/oned/S1Point.java     |  2 +-
 .../geometry/spherical/twod/EdgesBuilder.java        |  2 +-
 .../commons/geometry/spherical/twod/S2Point.java     |  2 +-
 .../spherical/twod/SphericalPolygonsSet.java         |  4 ++--
 18 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/SimpleTupleFormat.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/SimpleTupleFormat.java
index 4cca8cc..b2ecfc5 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/SimpleTupleFormat.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/SimpleTupleFormat.java
@@ -168,7 +168,7 @@ public class SimpleTupleFormat {
      * @return object returned by {@code fn}
      * @throws IllegalArgumentException if the input string format is invalid
      */
-    public <T> T parse(String str, DoubleFunction1N<T> fn) throws IllegalArgumentException {
+    public <T> T parse(String str, DoubleFunction1N<T> fn) {
         final ParsePosition pos = new ParsePosition(0);
 
         readPrefix(str, pos);
@@ -187,7 +187,7 @@ public class SimpleTupleFormat {
      * @return object returned by {@code fn}
      * @throws IllegalArgumentException if the input string format is invalid
      */
-    public <T> T parse(String str, DoubleFunction2N<T> fn) throws IllegalArgumentException {
+    public <T> T parse(String str, DoubleFunction2N<T> fn) {
         final ParsePosition pos = new ParsePosition(0);
 
         readPrefix(str, pos);
@@ -207,7 +207,7 @@ public class SimpleTupleFormat {
      * @return object returned by {@code fn}
      * @throws IllegalArgumentException if the input string format is invalid
      */
-    public <T> T parse(String str, DoubleFunction3N<T> fn) throws IllegalArgumentException {
+    public <T> T parse(String str, DoubleFunction3N<T> fn) {
         final ParsePosition pos = new ParsePosition(0);
 
         readPrefix(str, pos);
@@ -228,7 +228,7 @@ public class SimpleTupleFormat {
      * @throws IllegalArgumentException if the configured prefix is not null and is not found at the current
      *      parsing position, ignoring preceding whitespace
      */
-    private void readPrefix(String str, ParsePosition pos) throws IllegalArgumentException {
+    private void readPrefix(String str, ParsePosition pos) {
         if (prefix != null) {
             consumeWhitespace(str, pos);
             readSequence(str, prefix, pos);
@@ -243,7 +243,7 @@ public class SimpleTupleFormat {
      * @throws IllegalArgumentException if the configured prefix is not null and is not found at the current
      *      parsing position, ignoring preceding whitespace
      */
-    private double readTupleValue(String str, ParsePosition pos) throws IllegalArgumentException {
+    private double readTupleValue(String str, ParsePosition pos) {
         final int startIdx = pos.getIndex();
 
         int endIdx = str.indexOf(separator, startIdx);
@@ -281,7 +281,7 @@ public class SimpleTupleFormat {
      * @throws IllegalArgumentException if the configured suffix is not null and is not found at the current
      *      parsing position, ignoring preceding whitespace
      */
-    private void readSuffix(String str, ParsePosition pos) throws IllegalArgumentException {
+    private void readSuffix(String str, ParsePosition pos) {
         if (suffix != null) {
             consumeWhitespace(str, pos);
             readSequence(str, suffix, pos);
@@ -294,7 +294,7 @@ public class SimpleTupleFormat {
      * @param pos the current parsing position
      * @throws IllegalArgumentException if extra non-whitespace content is found past the current parsing position
      */
-    private void endParse(String str, ParsePosition pos) throws IllegalArgumentException {
+    private void endParse(String str, ParsePosition pos) {
         consumeWhitespace(str, pos);
         if (pos.getIndex() != str.length()) {
             fail("unexpected content", str, pos);
@@ -359,7 +359,7 @@ public class SimpleTupleFormat {
      * @throws IllegalArgumentException if {@code str} does not contain the characters from
      *      {@code seq} at position {@code pos}
      */
-    private void readSequence(String str, String seq, ParsePosition pos) throws IllegalArgumentException {
+    private void readSequence(String str, String seq, ParsePosition pos) {
         if (!matchSequence(str, seq, pos)) {
             final int idx = pos.getIndex();
             final String actualSeq = str.substring(idx, Math.min(str.length(), idx + seq.length()));
@@ -375,7 +375,7 @@ public class SimpleTupleFormat {
      * @param pos the current parse position
      * @throws IllegalArgumentException the exception signaling a parse failure
      */
-    private void fail(String msg, String str, ParsePosition pos) throws IllegalArgumentException {
+    private void fail(String msg, String str, ParsePosition pos) {
         fail(msg, str, pos, null);
     }
 
@@ -387,7 +387,7 @@ public class SimpleTupleFormat {
      * @param cause the original cause of the error
      * @throws IllegalArgumentException the exception signaling a parse failure
      */
-    private void fail(String msg, String str, ParsePosition pos, Throwable cause) throws IllegalArgumentException {
+    private void fail(String msg, String str, ParsePosition pos, Throwable cause) {
         final String fullMsg = String.format("Failed to parse string \"%s\" at index %d: %s", str, pos.getIndex(), msg);
 
         throw new TupleParseException(fullMsg, cause);
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 8d5e3d2..a9b1dc1 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
@@ -100,7 +100,7 @@ public class WelzlEncloser3DTest {
     }
 
     @Test
-    public void testLargeSamples() throws IOException {
+    public void testLargeSamples() {
         final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
                                                                  0x35ddecfc78131e1dl);
         final UnitSphereSampler sr = new UnitSphereSampler(3, random);
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 eec4b79..4f0fec1 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
@@ -157,7 +157,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D
      * @return point instance represented by the string
      * @throws IllegalArgumentException if the given string has an invalid format
      */
-    public static Point1D parse(String str) throws IllegalArgumentException {
+    public static Point1D parse(String str) {
         return SimpleTupleFormat.getDefault().parse(str, Point1D::new);
     }
 
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 df40670..10fabed 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
@@ -159,7 +159,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
 
     /** {@inheritDoc} */
     @Override
-    public Vector1D normalize() throws IllegalStateException {
+    public Vector1D normalize() {
         final double x = getX();
         if (x > 0.0) {
             return ONE;
@@ -210,7 +210,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
      * <p>For the one-dimensional case, this method simply returns the current instance.</p>
      */
     @Override
-    public Vector1D project(final Vector1D base) throws IllegalStateException {
+    public Vector1D project(final Vector1D base) {
         if (base.getX() == 0) {
             throw new ZeroNormException(ZeroNormException.INVALID_BASE);
         }
@@ -221,7 +221,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
      * <p>For the one-dimensional case, this method simply returns the zero vector.</p>
      */
     @Override
-    public Vector1D reject(final Vector1D base) throws IllegalStateException {
+    public Vector1D reject(final Vector1D base) {
         if (base.getX() == 0) {
             throw new ZeroNormException(ZeroNormException.INVALID_BASE);
         }
@@ -233,7 +233,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
      * the same sign and {@code pi} if they are opposite.</p>
      */
     @Override
-    public double angle(final Vector1D v) throws IllegalStateException {
+    public double angle(final Vector1D v) {
         final double sig1 = Math.signum(getX());
         final double sig2 = Math.signum(v.getX());
 
@@ -309,7 +309,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
      * @return vector instance represented by the string
      * @throws IllegalArgumentException if the given string has an invalid format
      */
-    public static Vector1D parse(String str) throws IllegalArgumentException {
+    public static Vector1D parse(String str) {
         return SimpleTupleFormat.getDefault().parse(str, Vector1D::new);
     }
 
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
index e7b4f38..5df7374 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java
@@ -69,7 +69,7 @@ public class Line implements Embedding<Point3D, Point1D> {
      * @param p2 second point belonging to the line (this can be any point, different from p1)
      * @exception IllegalArgumentException if the points are equal
      */
-    public void reset(final Point3D p1, final Point3D p2) throws IllegalArgumentException {
+    public void reset(final Point3D p1, final Point3D p2) {
         final Vector3D delta = p2.subtract(p1);
         final double norm2 = delta.getNormSq();
         if (norm2 == 0.0) {
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java
index 639b4ae..bc3c040 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java
@@ -116,7 +116,7 @@ public class Plane implements Hyperplane<Point3D>, Embedding<Point3D, Point2D> {
      * @param normal normal direction to the plane
      * @exception IllegalArgumentException if the normal norm is too small
      */
-    public void reset(final Point3D p, final Vector3D normal) throws IllegalArgumentException {
+    public void reset(final Point3D p, final Vector3D normal) {
         setNormal(normal);
         originOffset = -p.asVector().dotProduct(w);
         setFrame();
@@ -140,7 +140,7 @@ public class Plane implements Hyperplane<Point3D>, Embedding<Point3D, Point2D> {
      * @param normal normal direction to the plane (will be copied)
      * @exception IllegalArgumentException if the normal norm is too close to zero
      */
-    private void setNormal(final Vector3D normal) throws IllegalArgumentException {
+    private void setNormal(final Vector3D normal) {
         final double norm = normal.getNorm();
         if (norm < 1.0e-10) {
             throw new IllegalArgumentException("Norm is zero");
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 8e15230..3958326 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
@@ -192,7 +192,7 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D
      * @return point instance represented by the string
      * @throws IllegalArgumentException if the given string has an invalid format
      */
-    public static Point3D parse(String str) throws IllegalArgumentException {
+    public static Point3D parse(String str) {
         return SimpleTupleFormat.getDefault().parse(str, Point3D::new);
     }
 
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Rotation.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Rotation.java
index 272d5c0..f696f37 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Rotation.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Rotation.java
@@ -163,7 +163,7 @@ public class Rotation implements Serializable {
    * @deprecated as of 3.6, replaced with {@link #Rotation(Vector3D, double, RotationConvention)}
    */
   @Deprecated
-  public Rotation(Vector3D axis, double angle) throws IllegalArgumentException {
+  public Rotation(Vector3D axis, double angle) {
       this(axis, angle, RotationConvention.VECTOR_OPERATOR);
   }
 
@@ -327,7 +327,7 @@ public class Rotation implements Serializable {
    * @param v desired image of u by the rotation
    * @exception IllegalArgumentException if the norm of one of the vectors is zero
    */
-  public Rotation(Vector3D u, Vector3D v) throws IllegalArgumentException {
+  public Rotation(Vector3D u, Vector3D v) {
 
     double normProduct = u.getNorm() * v.getNorm();
     if (normProduct == 0) {
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SubLine.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SubLine.java
index d390536..b1721ab 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SubLine.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SubLine.java
@@ -58,7 +58,7 @@ public class SubLine {
      * @param segment single segment forming the sub-line
      * @exception IllegalArgumentException if the segment endpoints are equal
      */
-    public SubLine(final Segment segment) throws IllegalArgumentException {
+    public SubLine(final Segment segment) {
         this(segment.getLine(),
              buildIntervalSet(segment.getStart(), segment.getEnd(), segment.getLine().getTolerance()));
     }
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 fd52558..75b797a 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
@@ -188,7 +188,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
 
     /** {@inheritDoc} */
     @Override
-    public Vector3D normalize() throws IllegalStateException {
+    public Vector3D normalize() {
         return scalarMultiply(1.0 / getNonZeroNorm());
     }
 
@@ -207,7 +207,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      * @return a new normalized vector orthogonal to the instance
      * @exception IllegalStateException if the norm of the instance is zero
      */
-    public Vector3D orthogonal() throws IllegalStateException {
+    public Vector3D orthogonal() {
         double threshold = 0.6 * getNonZeroNorm();
 
         final double x = getX();
@@ -233,7 +233,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      * other.</p>
      */
     @Override
-    public double angle(Vector3D v) throws IllegalStateException {
+    public double angle(Vector3D v) {
         double normProduct = getNonZeroNorm() * v.getNonZeroNorm();
 
         double dot = dotProduct(v);
@@ -322,13 +322,13 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
 
     /** {@inheritDoc} */
     @Override
-    public Vector3D project(Vector3D base) throws IllegalStateException {
+    public Vector3D project(Vector3D base) {
         return getComponent(base, false);
     }
 
     /** {@inheritDoc} */
     @Override
-    public Vector3D reject(Vector3D base) throws IllegalStateException {
+    public Vector3D reject(Vector3D base) {
         return getComponent(base, true);
     }
 
@@ -386,7 +386,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      * @return the non-zero norm value
      * @throws IllegalStateException if the norm is zero
      */
-    private double getNonZeroNorm() throws IllegalStateException {
+    private double getNonZeroNorm() {
         final double n = getNorm();
         if (n == 0) {
             throw new ZeroNormException();
@@ -406,7 +406,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      *      depending on the value of {@code reject}.
      * @throws IllegalStateException if {@code base} has a zero norm
      */
-    private Vector3D getComponent(Vector3D base, boolean reject) throws IllegalStateException {
+    private Vector3D getComponent(Vector3D base, boolean reject) {
         final double aDotB = dotProduct(base);
 
         final double baseMagSq = base.getNormSq();
@@ -466,7 +466,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      * @return vector instance represented by the string
      * @throws IllegalArgumentException if the given string has an invalid format
      */
-    public static Vector3D parse(String str) throws IllegalArgumentException {
+    public static Vector3D parse(String str) {
         return SimpleTupleFormat.getDefault().parse(str, Vector3D::new);
     }
 
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/NestedLoops.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/NestedLoops.java
index a8ec823..4ee2a7c 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/NestedLoops.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/NestedLoops.java
@@ -116,7 +116,7 @@ class NestedLoops {
      * @exception IllegalArgumentException if an outline has crossing
      * boundary loops or open boundary loops
      */
-    public void add(final Point2D[] bLoop) throws IllegalArgumentException {
+    public void add(final Point2D[] bLoop) {
         add(new NestedLoops(bLoop, tolerance));
     }
 
@@ -125,7 +125,7 @@ class NestedLoops {
      * @exception IllegalArgumentException if an outline has boundary
      * loops that cross each other
      */
-    private void add(final NestedLoops node) throws IllegalArgumentException {
+    private void add(final NestedLoops node) {
 
         // check if we can go deeper in the tree
         for (final NestedLoops child : surrounded) {
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 e7a89cb..fb6e23d 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
@@ -175,7 +175,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D
      * @return point instance represented by the string
      * @throws IllegalArgumentException if the given string has an invalid format
      */
-    public static Point2D parse(String str) throws IllegalArgumentException {
+    public static Point2D parse(String str) {
         return SimpleTupleFormat.getDefault().parse(str, Point2D::new);
     }
 
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 fec9764..95313ae 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
@@ -171,7 +171,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
 
     /** {@inheritDoc} */
     @Override
-    public Vector2D normalize() throws IllegalStateException {
+    public Vector2D normalize() {
         return scalarMultiply(1.0 / getNonZeroNorm());
     }
 
@@ -213,13 +213,13 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
 
     /** {@inheritDoc} */
     @Override
-    public Vector2D project(Vector2D base) throws IllegalStateException {
+    public Vector2D project(Vector2D base) {
         return getComponent(base, false);
     }
 
     /** {@inheritDoc} */
     @Override
-    public Vector2D reject(Vector2D base) throws IllegalStateException {
+    public Vector2D reject(Vector2D base) {
         return getComponent(base, true);
     }
 
@@ -231,7 +231,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
      * other.</p>
      */
     @Override
-    public double angle(Vector2D v) throws IllegalStateException {
+    public double angle(Vector2D v) {
         double normProduct = getNonZeroNorm() * v.getNonZeroNorm();
 
         double dot = dotProduct(v);
@@ -332,7 +332,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
      * @return the non-zero norm value
      * @throws IllegalStateException if the norm is zero
      */
-    private double getNonZeroNorm() throws IllegalStateException {
+    private double getNonZeroNorm() {
         final double n = getNorm();
         if (n == 0) {
             throw new ZeroNormException();
@@ -352,7 +352,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
      *      depending on the value of {@code reject}.
      * @throws IllegalStateException if {@code base} has a zero norm
      */
-    private Vector2D getComponent(Vector2D base, boolean reject) throws IllegalStateException {
+    private Vector2D getComponent(Vector2D base, boolean reject) {
         final double aDotB = dotProduct(base);
 
         final double baseMagSq = base.getNormSq();
@@ -408,7 +408,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
      * @return vector instance represented by the string
      * @throws IllegalArgumentException if the given string has an invalid format
      */
-    public static Vector2D parse(String str) throws IllegalArgumentException {
+    public static Vector2D parse(String str) {
         return SimpleTupleFormat.getDefault().parse(str, Vector2D::new);
     }
 
diff --git a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/ConvexHull2D.java b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/ConvexHull2D.java
index 242de67..9f594fc 100644
--- a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/ConvexHull2D.java
+++ b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/ConvexHull2D.java
@@ -154,7 +154,7 @@ public class ConvexHull2D implements ConvexHull<Point2D>, Serializable {
 
     /** {@inheritDoc} */
     @Override
-    public Region<Point2D> createRegion() throws IllegalStateException {
+    public Region<Point2D> createRegion() {
         if (vertices.length < 3) {
             throw new IllegalStateException("Region generation requires at least 3 vertices but found only " + vertices.length);
         }
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 1d6615f..d12dc9b 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
@@ -171,7 +171,7 @@ public final class S1Point implements Point<S1Point>, Serializable {
      * @return point instance represented by the string
      * @throws IllegalArgumentException if the given string has an invalid format
      */
-    public static S1Point parse(String str) throws IllegalArgumentException {
+    public static S1Point parse(String str) {
         return SimpleTupleFormat.getDefault().parse(str, S1Point::new);
     }
 }
diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/EdgesBuilder.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/EdgesBuilder.java
index b44ee95..08b2df6 100644
--- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/EdgesBuilder.java
+++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/EdgesBuilder.java
@@ -155,7 +155,7 @@ class EdgesBuilder implements BSPTreeVisitor<S2Point> {
      * @return boundary edges
      * @exception IllegalStateException if there is not a single other edge
      */
-    public List<Edge> getEdges() throws IllegalStateException {
+    public List<Edge> getEdges() {
 
         // connect the edges
         for (final Edge previous : edgeToNode.keySet()) {
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 cd78701..ddac14d 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
@@ -222,7 +222,7 @@ public final class S2Point implements Point<S2Point>, Serializable {
      * @return point instance represented by the string
      * @throws IllegalArgumentException if the given string has an invalid format
      */
-    public static S2Point parse(String str) throws IllegalArgumentException {
+    public static S2Point parse(String str) {
         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 d16ef8b..2f45169 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
@@ -314,7 +314,7 @@ public class SphericalPolygonsSet extends AbstractRegion<S2Point, S1Point> {
      * a clean non-ambiguous boundary
      */
     @Override
-    protected void computeGeometricalProperties() throws IllegalStateException {
+    protected void computeGeometricalProperties() {
 
         final BSPTree<S2Point> tree = getTree(true);
 
@@ -366,7 +366,7 @@ public class SphericalPolygonsSet extends AbstractRegion<S2Point, S1Point> {
      * @see Vertex
      * @see Edge
      */
-    public List<Vertex> getBoundaryLoops() throws IllegalStateException {
+    public List<Vertex> getBoundaryLoops() {
 
         if (loops == null) {
             if (getTree(false).getCut() == null) {


[commons-geometry] 12/14: GEOMETRY-9: removing Point?D/Vector?D static convenience methods to clean up API, per pull request discussion

Posted by er...@apache.org.
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 45bffa7314331f787865dd3ef126424e156d8148
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Sun Sep 9 15:00:56 2018 -0400

    GEOMETRY-9: removing Point?D/Vector?D static convenience methods to clean up API, per pull request discussion
---
 .../commons/geometry/euclidean/oned/Point1D.java   |  12 --
 .../commons/geometry/euclidean/oned/Vector1D.java  |  12 --
 .../commons/geometry/euclidean/threed/Point3D.java |  12 --
 .../geometry/euclidean/threed/Vector3D.java        |  67 ---------
 .../commons/geometry/euclidean/twod/Point2D.java   |  12 --
 .../commons/geometry/euclidean/twod/Vector2D.java  |  56 --------
 .../geometry/euclidean/oned/Point1DTest.java       |  26 ----
 .../geometry/euclidean/oned/Vector1DTest.java      |  26 ----
 .../geometry/euclidean/threed/Point3DTest.java     |  26 ----
 .../geometry/euclidean/threed/Vector3DTest.java    | 152 ---------------------
 .../geometry/euclidean/twod/Point2DTest.java       |  26 ----
 .../geometry/euclidean/twod/Vector2DTest.java      | 119 ----------------
 .../geometry/spherical/twod/EdgesBuilder.java      |   4 +-
 .../spherical/twod/PropertiesComputer.java         |   4 +-
 .../spherical/twod/SphericalPolygonsSet.java       |   4 +-
 .../commons/geometry/spherical/twod/SubCircle.java |   3 +-
 .../geometry/spherical/twod/CircleTest.java        |  32 ++---
 .../spherical/twod/SphericalPolygonsSetTest.java   |   6 +-
 18 files changed, 25 insertions(+), 574 deletions(-)

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 800f157..eec4b79 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
@@ -161,18 +161,6 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D
         return SimpleTupleFormat.getDefault().parse(str, Point1D::new);
     }
 
-    /** Linearly interpolates between the two given points. This methods simply
-     * calls {@code a.lerp(b, t)}.
-     * @param a first point
-     * @param b second point
-     * @param t interpolation parameter
-     * @return the interpolated point
-     * @see #lerp(Point1D, double)
-     */
-    public static Point1D lerp(Point1D a, Point1D b, double t) {
-        return a.lerp(b, t);
-    }
-
     /** Returns a point with coordinates calculated by multiplying each input coordinate
      * with its corresponding factor and adding the results.
      *
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 57f85b5..df40670 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
@@ -313,18 +313,6 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
         return SimpleTupleFormat.getDefault().parse(str, Vector1D::new);
     }
 
-    /** Linearly interpolates between the two given vectors. This methods simply
-     * calls {@code a.lerp(b, t)}.
-     * @param a first vector
-     * @param b second vector
-     * @param t interpolation parameter
-     * @return the interpolated vector
-     * @see #lerp(Vector1D, double)
-     */
-    public static Vector1D lerp(Vector1D a, Vector1D b, double t) {
-        return a.lerp(b, t);
-    }
-
     /** Returns a vector consisting of the linear combination of the inputs.
      * <p>
      * A linear combination is the sum of all of the inputs multiplied by their
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 a930ba0..8e15230 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
@@ -196,18 +196,6 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D
         return SimpleTupleFormat.getDefault().parse(str, Point3D::new);
     }
 
-    /** Linearly interpolates between the two given points. This methods simply
-     * calls {@code a.lerp(b, t)}.
-     * @param a first point
-     * @param b second point
-     * @param t interpolation parameter
-     * @return the interpolated point
-     * @see #lerp(Point3D, double)
-     */
-    public static Point3D lerp(Point3D a, Point3D b, double t) {
-        return a.lerp(b, t);
-    }
-
     /** Returns a point with coordinates calculated by multiplying each input coordinate
      * with its corresponding factor and adding the results.
      *
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 61644ef..fd52558 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
@@ -427,61 +427,6 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return new Vector3D(projX, projY, projZ);
     }
 
-    /** Computes the dot product between to vectors. This method simply
-     * calls {@code v1.dotProduct(v2)}.
-     * @param v1 first vector
-     * @param v2 second vector
-     * @return the dot product
-     * @see #dotProduct(Vector3D)
-     */
-    public static double dotProduct(Vector3D v1, Vector3D v2) {
-        return v1.dotProduct(v2);
-    }
-
-    /** Computes the angle in radians between two vectors. This method
-     * simply calls {@code v1.angle(v2)}.
-     * @param v1 first vector
-     * @param v2 second vector
-     * @return the angle between the vectors in radians
-     * @see #angle(Vector3D)
-     */
-    public static double angle(Vector3D v1, Vector3D v2) {
-        return v1.angle(v2);
-    }
-
-    /** Projects the given vector onto {@code base}. This method simply
-     * calls {@code v.project(base)}.
-     * @param v vector to project
-     * @param base the base vector to project onto
-     * @return the projected vector
-     * @see #project(Vector3D)
-     */
-    public static Vector3D project(Vector3D v, Vector3D base) {
-        return v.project(base);
-    }
-
-    /** Returns the vector rejection of {@code v} from {@code base}. This
-     * method simply calls {@code v.reject(base)}.
-     * @param v vector to reject
-     * @param base the base vector to reject from
-     * @return the vector rejection
-     * @see #reject(Vector3D)
-     */
-    public static Vector3D reject(Vector3D v, Vector3D base) {
-        return v.reject(base);
-    }
-
-    /** Computes the cross product between two vectors. This method simply
-     * calls {@code v1.crossProduct(v2)}.
-     * @param v1 first vector
-     * @param v2 second vector
-     * @return the computed cross product vector
-     * @see #crossProduct(Vector3D)
-     */
-    public static Vector3D crossProduct(Vector3D v1, Vector3D v2) {
-        return v1.crossProduct(v2);
-    }
-
     /** Returns a vector with the given coordinate values.
      * @param x abscissa (first coordinate value)
      * @param y abscissa (second coordinate value)
@@ -525,18 +470,6 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return SimpleTupleFormat.getDefault().parse(str, Vector3D::new);
     }
 
-    /** Linearly interpolates between the two given vectors. This methods simply
-     * calls {@code a.lerp(b, t)}.
-     * @param a first vector
-     * @param b second vector
-     * @param t interpolation parameter
-     * @return the interpolated vector
-     * @see #lerp(Vector3D, double)
-     */
-    public static Vector3D lerp(Vector3D a, Vector3D b, double t) {
-        return a.lerp(b, t);
-    }
-
     /** Returns a vector consisting of the linear combination of the inputs.
      * <p>
      * A linear combination is the sum of all of the inputs multiplied by their
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 3600689..e7a89cb 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
@@ -179,18 +179,6 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D
         return SimpleTupleFormat.getDefault().parse(str, Point2D::new);
     }
 
-    /** Linearly interpolates between the two given points. This methods simply
-     * calls {@code a.lerp(b, t)}.
-     * @param a first point
-     * @param b second point
-     * @param t interpolation parameter
-     * @return the interpolated point
-     * @see #lerp(Point2D, double)
-     */
-    public static Point2D lerp(Point2D a, Point2D b, double t) {
-        return a.lerp(b, t);
-    }
-
     /** Returns a point with coordinates calculated by multiplying each input coordinate
      * with its corresponding factor and adding the results.
      *
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 946d01b..fec9764 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
@@ -372,50 +372,6 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
         return new Vector2D(projX, projY);
     }
 
-    /** Computes the dot product between to vectors. This method simply
-     * calls {@code v1.dotProduct(v2)}.
-     * @param v1 first vector
-     * @param v2 second vector
-     * @return the dot product
-     * @see #dotProduct(Vector2D)
-     */
-    public static double dotProduct(Vector2D v1, Vector2D v2) {
-        return v1.dotProduct(v2);
-    }
-
-    /** Projects the given vector onto {@code base}. This method simply
-     * calls {@code v.project(base)}.
-     * @param v vector to project
-     * @param base the base vector to project onto
-     * @return the projected vector
-     * @see #project(Vector2D)
-     */
-    public static Vector2D project(Vector2D v, Vector2D base) {
-        return v.project(base);
-    }
-
-    /** Returns the vector rejection of {@code v} from {@code base}. This
-     * method simply calls {@code v.reject(base)}.
-     * @param v vector to reject
-     * @param base the base vector to reject from
-     * @return the vector rejection
-     * @see #reject(Vector2D)
-     */
-    public static Vector2D reject(Vector2D v, Vector2D base) {
-        return v.reject(base);
-    }
-
-    /** Computes the angle in radians between two vectors. This method
-     * simply calls {@code v1.angle(v2)}.
-     * @param v1 first vector
-     * @param v2 second vector
-     * @return the angle between the vectors in radians
-     * @see #angle(Vector2D)
-     */
-    public static double angle(Vector2D v1, Vector2D v2) {
-        return v1.angle(v2);
-    }
-
     /** Returns a vector with the given coordinate values.
      * @param x abscissa (first coordinate value)
      * @param y abscissa (second coordinate value)
@@ -456,18 +412,6 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
         return SimpleTupleFormat.getDefault().parse(str, Vector2D::new);
     }
 
-    /** Linearly interpolates between the two given vectors. This methods simply
-     * calls {@code a.lerp(b, t)}.
-     * @param a first vector
-     * @param b second vector
-     * @param t interpolation parameter
-     * @return the interpolated vector
-     * @see #lerp(Vector2D, double)
-     */
-    public static Vector2D lerp(Vector2D a, Vector2D b, double t) {
-        return a.lerp(b, t);
-    }
-
     /** Returns a vector consisting of the linear combination of the inputs.
      * <p>
      * A linear combination is the sum of all of the inputs multiplied by their
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 e9379b1..25b2fe6 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
@@ -144,32 +144,6 @@ public class Point1DTest {
     }
 
     @Test
-    public void testLerp_static() {
-        // arrange
-        Point1D p1 = Point1D.of(1);
-        Point1D p2 = Point1D.of(-4);
-        Point1D p3 = Point1D.of(10);
-
-        // act/assert
-        checkPoint(Point1D.lerp(p1, p1, 0), 1);
-        checkPoint(Point1D.lerp(p1, p1, 1), 1);
-
-        checkPoint(Point1D.lerp(p1, p2, -0.25), 2.25);
-        checkPoint(Point1D.lerp(p1, p2, 0), 1);
-        checkPoint(Point1D.lerp(p1, p2, 0.25), -0.25);
-        checkPoint(Point1D.lerp(p1, p2, 0.5), -1.5);
-        checkPoint(Point1D.lerp(p1, p2, 0.75), -2.75);
-        checkPoint(Point1D.lerp(p1, p2, 1), -4);
-        checkPoint(Point1D.lerp(p1, p2, 1.25), -5.25);
-
-        checkPoint(Point1D.lerp(p1, p3, 0), 1);
-        checkPoint(Point1D.lerp(p1, p3, 0.25), 3.25);
-        checkPoint(Point1D.lerp(p1, p3, 0.5), 5.5);
-        checkPoint(Point1D.lerp(p1, p3, 0.75), 7.75);
-        checkPoint(Point1D.lerp(p1, p3, 1), 10);
-    }
-
-    @Test
     public void testAdd() {
         // arrange
         Point1D p1 = Point1D.of(2.0);
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
index 20396fe..e5b580a 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
@@ -415,32 +415,6 @@ public class Vector1DTest {
     }
 
     @Test
-    public void testLerp_static() {
-        // arrange
-        Vector1D v1 = Vector1D.of(1);
-        Vector1D v2 = Vector1D.of(-4);
-        Vector1D v3 = Vector1D.of(10);
-
-        // act/assert
-        checkVector(Vector1D.lerp(v1, v1, 0), 1);
-        checkVector(Vector1D.lerp(v1, v1, 1), 1);
-
-        checkVector(Vector1D.lerp(v1, v2, -0.25), 2.25);
-        checkVector(Vector1D.lerp(v1, v2, 0), 1);
-        checkVector(Vector1D.lerp(v1, v2, 0.25), -0.25);
-        checkVector(Vector1D.lerp(v1, v2, 0.5), -1.5);
-        checkVector(Vector1D.lerp(v1, v2, 0.75), -2.75);
-        checkVector(Vector1D.lerp(v1, v2, 1), -4);
-        checkVector(Vector1D.lerp(v1, v2, 1.25), -5.25);
-
-        checkVector(Vector1D.lerp(v1, v3, 0), 1);
-        checkVector(Vector1D.lerp(v1, v3, 0.25), 3.25);
-        checkVector(Vector1D.lerp(v1, v3, 0.5), 5.5);
-        checkVector(Vector1D.lerp(v1, v3, 0.75), 7.75);
-        checkVector(Vector1D.lerp(v1, v3, 1), 10);
-    }
-
-    @Test
     public void testHashCode() {
         // arrange
         Vector1D u = Vector1D.of(1);
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 df54e58..3e312dd 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
@@ -129,32 +129,6 @@ public class Point3DTest {
     }
 
     @Test
-    public void testLerp_static() {
-        // arrange
-        Point3D p1 = Point3D.of(1, -5, 2);
-        Point3D p2 = Point3D.of(-4, 0, 2);
-        Point3D p3 = Point3D.of(10, -4, 0);
-
-        // act/assert
-        checkPoint(Point3D.lerp(p1, p1, 0), 1, -5, 2);
-        checkPoint(Point3D.lerp(p1, p1, 1), 1, -5, 2);
-
-        checkPoint(Point3D.lerp(p1, p2, -0.25), 2.25, -6.25, 2);
-        checkPoint(Point3D.lerp(p1, p2, 0), 1, -5, 2);
-        checkPoint(Point3D.lerp(p1, p2, 0.25), -0.25, -3.75, 2);
-        checkPoint(Point3D.lerp(p1, p2, 0.5), -1.5, -2.5, 2);
-        checkPoint(Point3D.lerp(p1, p2, 0.75), -2.75, -1.25, 2);
-        checkPoint(Point3D.lerp(p1, p2, 1), -4, 0, 2);
-        checkPoint(Point3D.lerp(p1, p2, 1.25), -5.25, 1.25, 2);
-
-        checkPoint(Point3D.lerp(p1, p3, 0), 1, -5, 2);
-        checkPoint(Point3D.lerp(p1, p3, 0.25), 3.25, -4.75, 1.5);
-        checkPoint(Point3D.lerp(p1, p3, 0.5), 5.5, -4.5, 1);
-        checkPoint(Point3D.lerp(p1, p3, 0.75), 7.75, -4.25, 0.5);
-        checkPoint(Point3D.lerp(p1, p3, 1), 10, -4, 0);
-    }
-
-    @Test
     public void testAdd() {
         // act/assert
         Point3D p1 = Point3D.of(1, 2, 3);
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 4880438..3aa2dd7 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
@@ -316,28 +316,6 @@ public class Vector3DTest {
 
         // act/assert
         Assert.assertTrue(Math.abs(v1.angle(v2) - 1.2) < 1.0e-12);
-  }
-
-    @Test
-    public void testAngle_static() {
-        // arrange
-        double tolerance = 1e-10;
-
-        Vector3D v1 = Vector3D.of(1, 2, 3);
-        Vector3D v2 = Vector3D.of(4, 5, 6);
-
-        // act/assert
-        Assert.assertEquals(0.22572612855273393616, Vector3D.angle(v1, v2), tolerance);
-        Assert.assertEquals(7.98595620686106654517199e-8, Vector3D.angle(v1, Vector3D.of(2, 4, 6.000001)), tolerance);
-        Assert.assertEquals(3.14159257373023116985197793156, Vector3D.angle(v1, Vector3D.of(-2, -4, -6.000001)), tolerance);
-
-        Assert.assertEquals(0.0, Vector3D.angle(Vector3D.PLUS_X, Vector3D.PLUS_X), tolerance);
-        Assert.assertEquals(Geometry.PI, Vector3D.angle(Vector3D.PLUS_X, Vector3D.MINUS_X), tolerance);
-
-        Assert.assertEquals(Geometry.HALF_PI, Vector3D.angle(Vector3D.PLUS_X, Vector3D.PLUS_Y), tolerance);
-        Assert.assertEquals(Geometry.HALF_PI, Vector3D.angle(Vector3D.PLUS_X, Vector3D.MINUS_Y), tolerance);
-        Assert.assertEquals(Geometry.HALF_PI, Vector3D.angle(Vector3D.PLUS_X, Vector3D.PLUS_Z), tolerance);
-        Assert.assertEquals(Geometry.HALF_PI, Vector3D.angle(Vector3D.PLUS_X, Vector3D.MINUS_Z), tolerance);
     }
 
     @Test
@@ -422,21 +400,6 @@ public class Vector3DTest {
     }
 
     @Test
-    public void testCrossProduct_static() {
-        // act/assert
-        checkVector(Vector3D.crossProduct(Vector3D.PLUS_X, Vector3D.PLUS_Y), 0, 0, 1);
-        checkVector(Vector3D.crossProduct(Vector3D.PLUS_X, Vector3D.MINUS_Y), 0, 0, -1);
-
-        checkVector(Vector3D.crossProduct(Vector3D.MINUS_X, Vector3D.MINUS_Y), 0, 0, 1);
-        checkVector(Vector3D.crossProduct(Vector3D.MINUS_X, Vector3D.PLUS_Y), 0, 0, -1);
-
-        checkVector(Vector3D.crossProduct(Vector3D.of(2, 1, -4), Vector3D.of(3, 1, -1)), 3, -10, -1);
-
-        double invSqrt6 = 1 / Math.sqrt(6);
-        checkVector(Vector3D.crossProduct(Vector3D.of(1, 1, 1), Vector3D.of(-1, 0, 1)).normalize(), invSqrt6, - 2 * invSqrt6, invSqrt6);
-    }
-
-    @Test
     public void testScalarMultiply() {
         // arrange
         Vector3D v1 = Vector3D.of(2, 3, 4);
@@ -600,23 +563,6 @@ public class Vector3DTest {
     }
 
     @Test
-    public void testDotProduct_static() {
-        // arrange
-        Vector3D v1 = Vector3D.of(1, -2, 3);
-        Vector3D v2 = Vector3D.of(-4, 5, -6);
-        Vector3D v3 = Vector3D.of(7, 8, 9);
-
-        // act/assert
-        Assert.assertEquals(14, Vector3D.dotProduct(v1, v1), EPS);
-
-        Assert.assertEquals(-32, Vector3D.dotProduct(v1, v2), EPS);
-        Assert.assertEquals(-32, Vector3D.dotProduct(v2, v1), EPS);
-
-        Assert.assertEquals(18, Vector3D.dotProduct(v1, v3), EPS);
-        Assert.assertEquals(18, Vector3D.dotProduct(v3, v1), EPS);
-    }
-
-    @Test
     public void testProject() {
         // arrange
         Vector3D v1 = Vector3D.of(2.0, 3.0, 4.0);
@@ -653,42 +599,6 @@ public class Vector3DTest {
     }
 
     @Test
-    public void testProject_static() {
-        // arrange
-        Vector3D v1 = Vector3D.of(2.0, 3.0, 4.0);
-        Vector3D v2 = Vector3D.of(-5.0, -6.0, -7.0);
-
-        // act/assert
-        checkVector(Vector3D.project(Vector3D.ZERO, Vector3D.PLUS_X), 0.0, 0.0, 0.0);
-
-        checkVector(Vector3D.project(v1, Vector3D.PLUS_X), 2.0, 0.0, 0.0);
-        checkVector(Vector3D.project(v1, Vector3D.MINUS_X), 2.0, 0.0, 0.0);
-        checkVector(Vector3D.project(v1, Vector3D.PLUS_Y), 0.0, 3.0, 0.0);
-        checkVector(Vector3D.project(v1, Vector3D.MINUS_Y), 0.0, 3.0, 0.0);
-        checkVector(Vector3D.project(v1, Vector3D.PLUS_Z), 0.0, 0.0, 4.0);
-        checkVector(Vector3D.project(v1, Vector3D.MINUS_Z), 0.0, 0.0, 4.0);
-
-        checkVector(Vector3D.project(v2, Vector3D.PLUS_X), -5.0, 0.0, 0.0);
-        checkVector(Vector3D.project(v2, Vector3D.MINUS_X), -5.0, 0.0, 0.0);
-        checkVector(Vector3D.project(v2, Vector3D.PLUS_Y), 0.0, -6.0, 0.0);
-        checkVector(Vector3D.project(v2, Vector3D.MINUS_Y), 0.0, -6.0, 0.0);
-        checkVector(Vector3D.project(v2, Vector3D.PLUS_Z), 0.0, 0.0, -7.0);
-        checkVector(Vector3D.project(v2, Vector3D.MINUS_Z), 0.0, 0.0, -7.0);
-
-        checkVector(Vector3D.project(v1, Vector3D.of(1.0, 1.0, 1.0)), 3.0, 3.0, 3.0);
-        checkVector(Vector3D.project(v1, Vector3D.of(-1.0, -1.0, -1.0)), 3.0, 3.0, 3.0);
-
-        checkVector(Vector3D.project(v2, Vector3D.of(1.0, 1.0, 1.0)), -6.0, -6.0, -6.0);
-        checkVector(Vector3D.project(v2, Vector3D.of(-1.0, -1.0, -1.0)), -6.0, -6.0, -6.0);
-    }
-
-    @Test(expected = IllegalStateException.class)
-    public void testProject_baseHasZeroNorm_static() {
-        // act/assert
-        Vector3D.project(Vector3D.of(1.0, 1.0, 1.0), Vector3D.ZERO);
-    }
-
-    @Test
     public void testReject() {
         // arrange
         Vector3D v1 = Vector3D.of(2.0, 3.0, 4.0);
@@ -725,42 +635,6 @@ public class Vector3DTest {
     }
 
     @Test
-    public void testReject_static() {
-        // arrange
-        Vector3D v1 = Vector3D.of(2.0, 3.0, 4.0);
-        Vector3D v2 = Vector3D.of(-5.0, -6.0, -7.0);
-
-        // act/assert
-        checkVector(Vector3D.reject(Vector3D.ZERO, Vector3D.PLUS_X), 0.0, 0.0, 0.0);
-
-        checkVector(Vector3D.reject(v1, Vector3D.PLUS_X), 0.0, 3.0, 4.0);
-        checkVector(Vector3D.reject(v1, Vector3D.MINUS_X), 0.0, 3.0, 4.0);
-        checkVector(Vector3D.reject(v1, Vector3D.PLUS_Y), 2.0, 0.0, 4.0);
-        checkVector(Vector3D.reject(v1, Vector3D.MINUS_Y), 2.0, 0.0, 4.0);
-        checkVector(Vector3D.reject(v1, Vector3D.PLUS_Z), 2.0, 3.0, 0.0);
-        checkVector(Vector3D.reject(v1, Vector3D.MINUS_Z), 2.0, 3.0, 0.0);
-
-        checkVector(Vector3D.reject(v2, Vector3D.PLUS_X), 0.0, -6.0, -7.0);
-        checkVector(Vector3D.reject(v2, Vector3D.MINUS_X), 0.0, -6.0, -7.0);
-        checkVector(Vector3D.reject(v2, Vector3D.PLUS_Y), -5.0, 0.0, -7.0);
-        checkVector(Vector3D.reject(v2, Vector3D.MINUS_Y), -5.0, 0.0, -7.0);
-        checkVector(Vector3D.reject(v2, Vector3D.PLUS_Z), -5.0, -6.0, 0.0);
-        checkVector(Vector3D.reject(v2, Vector3D.MINUS_Z), -5.0, -6.0, 0.0);
-
-        checkVector(Vector3D.reject(v1, Vector3D.of(1.0, 1.0, 1.0)), -1.0, 0.0, 1.0);
-        checkVector(Vector3D.reject(v1, Vector3D.of(-1.0, -1.0, -1.0)), -1.0, 0.0, 1.0);
-
-        checkVector(Vector3D.reject(v2, Vector3D.of(1.0, 1.0, 1.0)), 1.0, 0.0, -1.0);
-        checkVector(Vector3D.reject(v2, Vector3D.of(-1.0, -1.0, -1.0)), 1.0, 0.0, -1.0);
-    }
-
-    @Test(expected = IllegalStateException.class)
-    public void testReject_baseHasZeroNorm_static() {
-        // act/assert
-        Vector3D.reject(Vector3D.of(1.0, 1.0, 1.0), Vector3D.ZERO);
-    }
-
-    @Test
     public void testProjectAndReject_areComplementary() {
         // arrange
         double eps = 1e-12;
@@ -837,32 +711,6 @@ public class Vector3DTest {
     }
 
     @Test
-    public void testLerp_static() {
-        // arrange
-        Vector3D v1 = Vector3D.of(1, -5, 2);
-        Vector3D v2 = Vector3D.of(-4, 0, 2);
-        Vector3D v3 = Vector3D.of(10, -4, 0);
-
-        // act/assert
-        checkVector(Vector3D.lerp(v1, v1, 0), 1, -5, 2);
-        checkVector(Vector3D.lerp(v1, v1, 1), 1, -5, 2);
-
-        checkVector(Vector3D.lerp(v1, v2, -0.25), 2.25, -6.25, 2);
-        checkVector(Vector3D.lerp(v1, v2, 0), 1, -5, 2);
-        checkVector(Vector3D.lerp(v1, v2, 0.25), -0.25, -3.75, 2);
-        checkVector(Vector3D.lerp(v1, v2, 0.5), -1.5, -2.5, 2);
-        checkVector(Vector3D.lerp(v1, v2, 0.75), -2.75, -1.25, 2);
-        checkVector(Vector3D.lerp(v1, v2, 1), -4, 0, 2);
-        checkVector(Vector3D.lerp(v1, v2, 1.25), -5.25, 1.25, 2);
-
-        checkVector(Vector3D.lerp(v1, v3, 0), 1, -5, 2);
-        checkVector(Vector3D.lerp(v1, v3, 0.25), 3.25, -4.75, 1.5);
-        checkVector(Vector3D.lerp(v1, v3, 0.5), 5.5, -4.5, 1);
-        checkVector(Vector3D.lerp(v1, v3, 0.75), 7.75, -4.25, 0.5);
-        checkVector(Vector3D.lerp(v1, v3, 1), 10, -4, 0);
-    }
-
-    @Test
     public void testHashCode() {
         // arrange
         double delta = 10 * Precision.EPSILON;
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 199abd2..d5903de 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
@@ -120,32 +120,6 @@ public class Point2DTest {
     }
 
     @Test
-    public void testLerp_static() {
-        // arrange
-        Point2D p1 = Point2D.of(1, -5);
-        Point2D p2 = Point2D.of(-4, 0);
-        Point2D p3 = Point2D.of(10, -4);
-
-        // act/assert
-        checkPoint(Point2D.lerp(p1, p1, 0), 1, -5);
-        checkPoint(Point2D.lerp(p1, p1, 1), 1, -5);
-
-        checkPoint(Point2D.lerp(p1, p2, -0.25), 2.25, -6.25);
-        checkPoint(Point2D.lerp(p1, p2, 0), 1, -5);
-        checkPoint(Point2D.lerp(p1, p2, 0.25), -0.25, -3.75);
-        checkPoint(Point2D.lerp(p1, p2, 0.5), -1.5, -2.5);
-        checkPoint(Point2D.lerp(p1, p2, 0.75), -2.75, -1.25);
-        checkPoint(Point2D.lerp(p1, p2, 1), -4, 0);
-        checkPoint(Point2D.lerp(p1, p2, 1.25), -5.25, 1.25);
-
-        checkPoint(Point2D.lerp(p1, p3, 0), 1, -5);
-        checkPoint(Point2D.lerp(p1, p3, 0.25), 3.25, -4.75);
-        checkPoint(Point2D.lerp(p1, p3, 0.5), 5.5, -4.5);
-        checkPoint(Point2D.lerp(p1, p3, 0.75), 7.75, -4.25);
-        checkPoint(Point2D.lerp(p1, p3, 1), 10, -4);
-    }
-
-    @Test
     public void testAdd() {
         // arrange
         Point2D p1 = Point2D.of(1, 1);
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 1e3a1ba..62e0c8e 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
@@ -361,30 +361,6 @@ public class Vector2DTest {
     }
 
     @Test
-    public void testDotProduct_static() {
-        // arrange
-        Vector2D v1 = Vector2D.of(1, 1);
-        Vector2D v2 = Vector2D.of(4, 5);
-        Vector2D v3 = Vector2D.of(-1, 0);
-
-        // act/assert
-        Assert.assertEquals(2, Vector2D.dotProduct(v1, v1), EPS);
-        Assert.assertEquals(41, Vector2D.dotProduct(v2, v2), EPS);
-        Assert.assertEquals(1, Vector2D.dotProduct(v3, v3), EPS);
-
-        Assert.assertEquals(9, Vector2D.dotProduct(v1, v2), EPS);
-        Assert.assertEquals(9, Vector2D.dotProduct(v2, v1), EPS);
-
-        Assert.assertEquals(-1, Vector2D.dotProduct(v1, v3), EPS);
-        Assert.assertEquals(-1, Vector2D.dotProduct(v3, v1), EPS);
-
-        Assert.assertEquals(1, Vector2D.dotProduct(Vector2D.PLUS_X, Vector2D.PLUS_X), EPS);
-        Assert.assertEquals(0, Vector2D.dotProduct(Vector2D.PLUS_X, Vector2D.PLUS_Y), EPS);
-        Assert.assertEquals(-1, Vector2D.dotProduct(Vector2D.PLUS_X, Vector2D.MINUS_X), EPS);
-        Assert.assertEquals(0, Vector2D.dotProduct(Vector2D.PLUS_X, Vector2D.MINUS_Y), EPS);
-    }
-
-    @Test
     public void testAngle() {
         // act/assert
         Assert.assertEquals(0, Vector2D.PLUS_X.angle(Vector2D.PLUS_X), EPS);
@@ -399,21 +375,6 @@ public class Vector2DTest {
         Assert.assertEquals(0.004999958333958323, Vector2D.of(20.0, 0.0).angle(Vector2D.of(20.0, 0.1)), EPS);
     }
 
-    @Test
-    public void testAngle_static() {
-        // act/assert
-        Assert.assertEquals(0, Vector2D.angle(Vector2D.PLUS_X, Vector2D.PLUS_X), EPS);
-
-        Assert.assertEquals(Geometry.PI, Vector2D.angle(Vector2D.PLUS_X, Vector2D.MINUS_X), EPS);
-        Assert.assertEquals(Geometry.HALF_PI, Vector2D.angle(Vector2D.PLUS_X, Vector2D.PLUS_Y), EPS);
-        Assert.assertEquals(Geometry.HALF_PI, Vector2D.angle(Vector2D.PLUS_X, Vector2D.MINUS_Y), EPS);
-
-        Assert.assertEquals(Geometry.PI / 4, Vector2D.angle(Vector2D.of(1, 1), Vector2D.of(1, 0)), EPS);
-        Assert.assertEquals(Geometry.PI / 4, Vector2D.angle(Vector2D.of(1, 0), Vector2D.of(1, 1)), EPS);
-
-        Assert.assertEquals(0.004999958333958323, Vector2D.angle(Vector2D.of(20.0, 0.0), Vector2D.of(20.0, 0.1)), EPS);
-    }
-
 
     @Test(expected = IllegalStateException.class)
     public void testAngle_zeroNorm() {
@@ -464,33 +425,6 @@ public class Vector2DTest {
     }
 
     @Test
-    public void testProject_static() {
-     // arrange
-        Vector2D v1 = Vector2D.of(3.0, 4.0);
-        Vector2D v2 = Vector2D.of(1.0, 4.0);
-
-        // act/assert
-        checkVector(Vector2D.project(Vector2D.ZERO, v1), 0.0, 0.0);
-
-        checkVector(Vector2D.project(v1, v1), 3.0, 4.0);
-        checkVector(Vector2D.project(v1, v1.negate()), 3.0, 4.0);
-
-        checkVector(Vector2D.project(v1, Vector2D.PLUS_X), 3.0, 0.0);
-        checkVector(Vector2D.project(v1, Vector2D.MINUS_X), 3.0, 0.0);
-
-        checkVector(Vector2D.project(v1, Vector2D.PLUS_Y), 0.0, 4.0);
-        checkVector(Vector2D.project(v1, Vector2D.MINUS_Y), 0.0, 4.0);
-
-        checkVector(Vector2D.project(v2, v1), (19.0 / 25.0) * 3.0, (19.0 / 25.0) * 4.0);
-    }
-
-    @Test(expected = IllegalStateException.class)
-    public void testProject_baseHasZeroNorm_static() {
-        // act/assert
-        Vector2D.project(Vector2D.of(1.0, 1.0), Vector2D.ZERO);
-    }
-
-    @Test
     public void testReject() {
         // arrange
         Vector2D v1 = Vector2D.of(3.0, 4.0);
@@ -518,33 +452,6 @@ public class Vector2DTest {
     }
 
     @Test
-    public void testReject_static() {
-        // arrange
-        Vector2D v1 = Vector2D.of(3.0, 4.0);
-        Vector2D v2 = Vector2D.of(1.0, 4.0);
-
-        // act/assert
-        checkVector(Vector2D.ZERO.reject(v1), 0.0, 0.0);
-
-        checkVector(Vector2D.reject(v1, v1), 0.0, 0.0);
-        checkVector(Vector2D.reject(v1, v1.negate()), 0.0, 0.0);
-
-        checkVector(Vector2D.reject(v1, Vector2D.PLUS_X), 0.0, 4.0);
-        checkVector(Vector2D.reject(v1, Vector2D.MINUS_X), 0.0, 4.0);
-
-        checkVector(Vector2D.reject(v1, Vector2D.PLUS_Y), 3.0, 0.0);
-        checkVector(Vector2D.reject(v1, Vector2D.MINUS_Y), 3.0, 0.0);
-
-        checkVector(Vector2D.reject(v2, v1), (-32.0 / 25.0), (6.0 / 25.0) * 4.0);
-    }
-
-    @Test(expected = IllegalStateException.class)
-    public void testReject_baseHasZeroNorm_static() {
-        // act/assert
-        Vector2D.reject(Vector2D.of(1.0, 1.0), Vector2D.ZERO);
-    }
-
-    @Test
     public void testProjectAndReject_areComplementary() {
         // arrange
         double eps = 1e-12;
@@ -617,32 +524,6 @@ public class Vector2DTest {
     }
 
     @Test
-    public void testLerp_static() {
-        // arrange
-        Vector2D v1 = Vector2D.of(1, -5);
-        Vector2D v2 = Vector2D.of(-4, 0);
-        Vector2D v3 = Vector2D.of(10, -4);
-
-        // act/assert
-        checkVector(Vector2D.lerp(v1, v1, 0), 1, -5);
-        checkVector(Vector2D.lerp(v1, v1, 1), 1, -5);
-
-        checkVector(Vector2D.lerp(v1, v2, -0.25), 2.25, -6.25);
-        checkVector(Vector2D.lerp(v1, v2, 0), 1, -5);
-        checkVector(Vector2D.lerp(v1, v2, 0.25), -0.25, -3.75);
-        checkVector(Vector2D.lerp(v1, v2, 0.5), -1.5, -2.5);
-        checkVector(Vector2D.lerp(v1, v2, 0.75), -2.75, -1.25);
-        checkVector(Vector2D.lerp(v1, v2, 1), -4, 0);
-        checkVector(Vector2D.lerp(v1, v2, 1.25), -5.25, 1.25);
-
-        checkVector(Vector2D.lerp(v1, v3, 0), 1, -5);
-        checkVector(Vector2D.lerp(v1, v3, 0.25), 3.25, -4.75);
-        checkVector(Vector2D.lerp(v1, v3, 0.5), 5.5, -4.5);
-        checkVector(Vector2D.lerp(v1, v3, 0.75), 7.75, -4.25);
-        checkVector(Vector2D.lerp(v1, v3, 1), 10, -4);
-    }
-
-    @Test
     public void testHashCode() {
         // arrange
         Vector2D u = Vector2D.of(1, 1);
diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/EdgesBuilder.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/EdgesBuilder.java
index 085f9c5..b44ee95 100644
--- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/EdgesBuilder.java
+++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/EdgesBuilder.java
@@ -126,7 +126,7 @@ class EdgesBuilder implements BSPTreeVisitor<S2Point> {
             for (final Edge edge : nodeToEdgesList.get(node)) {
                 if (edge != previous && edge.getStart().getIncoming() == null) {
                     final Vector3D edgeStart = edge.getStart().getLocation().getVector();
-                    final double gap         = Vector3D.angle(point.getVector(), edgeStart);
+                    final double gap         = point.getVector().angle(edgeStart);
                     if (gap <= closest) {
                         closest   = gap;
                         following = edge;
@@ -137,7 +137,7 @@ class EdgesBuilder implements BSPTreeVisitor<S2Point> {
 
         if (following == null) {
             final Vector3D previousStart = previous.getStart().getLocation().getVector();
-            if (Vector3D.angle(point.getVector(), previousStart) <= tolerance) {
+            if (point.getVector().angle(previousStart) <= tolerance) {
                 // the edge connects back to itself
                 return previous;
             }
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 982c8af..3f6da88 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
@@ -110,8 +110,8 @@ class PropertiesComputer implements BSPTreeVisitor<S2Point> {
             final Vector3D previousPole = e.getCircle().getPole();
             final Vector3D nextPole     = e.getEnd().getOutgoing().getCircle().getPole();
             final Vector3D point        = e.getEnd().getLocation().getVector();
-            double alpha = Math.atan2(Vector3D.dotProduct(nextPole, Vector3D.crossProduct(point, previousPole)),
-                                          -Vector3D.dotProduct(nextPole, previousPole));
+            double alpha = Math.atan2(nextPole.dotProduct(point.crossProduct(previousPole)),
+                                          - nextPole.dotProduct(previousPole));
             if (alpha < 0) {
                 alpha += Geometry.TWO_PI;
             }
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 fafac75..d16ef8b 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
@@ -159,7 +159,7 @@ public class SphericalPolygonsSet extends AbstractRegion<S2Point, S1Point> {
     private static S2Point[] createRegularPolygonVertices(final Vector3D center, final Vector3D meridian,
                                                           final double outsideRadius, final int n) {
         final S2Point[] array = new S2Point[n];
-        final Rotation r0 = new Rotation(Vector3D.crossProduct(center, meridian),
+        final Rotation r0 = new Rotation(center.crossProduct(meridian),
                                          outsideRadius, RotationConvention.VECTOR_OPERATOR);
         array[0] = S2Point.ofVector(r0.applyTo(center));
 
@@ -223,7 +223,7 @@ public class SphericalPolygonsSet extends AbstractRegion<S2Point, S1Point> {
 
             // create the edge and store it
             edges.add(new Edge(start, end,
-                               Vector3D.angle(start.getLocation().getVector(),
+                               start.getLocation().getVector().angle(
                                               end.getLocation().getVector()),
                                circle));
 
diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SubCircle.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SubCircle.java
index 2205060..30349ca 100644
--- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SubCircle.java
+++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SubCircle.java
@@ -19,7 +19,6 @@ package org.apache.commons.geometry.spherical.twod;
 import org.apache.commons.geometry.core.partitioning.AbstractSubHyperplane;
 import org.apache.commons.geometry.core.partitioning.Hyperplane;
 import org.apache.commons.geometry.core.partitioning.Region;
-import org.apache.commons.geometry.euclidean.threed.Vector3D;
 import org.apache.commons.geometry.spherical.oned.Arc;
 import org.apache.commons.geometry.spherical.oned.ArcsSet;
 import org.apache.commons.geometry.spherical.oned.S1Point;
@@ -50,7 +49,7 @@ public class SubCircle extends AbstractSubHyperplane<S2Point, S1Point> {
 
         final Circle thisCircle   = (Circle) getHyperplane();
         final Circle otherCircle  = (Circle) hyperplane;
-        final double angle = Vector3D.angle(thisCircle.getPole(), otherCircle.getPole());
+        final double angle = thisCircle.getPole().angle(otherCircle.getPole());
 
         if (angle < thisCircle.getTolerance() || angle > Math.PI - thisCircle.getTolerance()) {
             // the two circles are aligned or opposite
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 f056acb..f281988 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
@@ -50,11 +50,11 @@ public class CircleTest {
         Circle circle = new Circle(S2Point.of(1.2, 2.5), S2Point.of(-4.3, 0), 1.0e-10);
         Assert.assertEquals(0.0, circle.getPointAt(0).distance(circle.getXAxis()), 1.0e-10);
         Assert.assertEquals(0.0, circle.getPointAt(0.5 * Math.PI).distance(circle.getYAxis()), 1.0e-10);
-        Assert.assertEquals(0.5 * Math.PI, Vector3D.angle(circle.getXAxis(), circle.getYAxis()), 1.0e-10);
-        Assert.assertEquals(0.5 * Math.PI, Vector3D.angle(circle.getXAxis(), circle.getPole()), 1.0e-10);
-        Assert.assertEquals(0.5 * Math.PI, Vector3D.angle(circle.getPole(), circle.getYAxis()), 1.0e-10);
+        Assert.assertEquals(0.5 * Math.PI, circle.getXAxis().angle(circle.getYAxis()), 1.0e-10);
+        Assert.assertEquals(0.5 * Math.PI, circle.getXAxis().angle(circle.getPole()), 1.0e-10);
+        Assert.assertEquals(0.5 * Math.PI, circle.getPole().angle(circle.getYAxis()), 1.0e-10);
         Assert.assertEquals(0.0,
-                            circle.getPole().distance(Vector3D.crossProduct(circle.getXAxis(), circle.getYAxis())),
+                            circle.getPole().distance(circle.getXAxis().crossProduct(circle.getYAxis())),
                             1.0e-10);
     }
 
@@ -64,20 +64,19 @@ public class CircleTest {
         Circle reversed = circle.getReverse();
         Assert.assertEquals(0.0, reversed.getPointAt(0).distance(reversed.getXAxis()), 1.0e-10);
         Assert.assertEquals(0.0, reversed.getPointAt(0.5 * Math.PI).distance(reversed.getYAxis()), 1.0e-10);
-        Assert.assertEquals(0.5 * Math.PI, Vector3D.angle(reversed.getXAxis(), reversed.getYAxis()), 1.0e-10);
-        Assert.assertEquals(0.5 * Math.PI, Vector3D.angle(reversed.getXAxis(), reversed.getPole()), 1.0e-10);
-        Assert.assertEquals(0.5 * Math.PI, Vector3D.angle(reversed.getPole(), reversed.getYAxis()), 1.0e-10);
+        Assert.assertEquals(0.5 * Math.PI, reversed.getXAxis().angle(reversed.getYAxis()), 1.0e-10);
+        Assert.assertEquals(0.5 * Math.PI, reversed.getXAxis().angle(reversed.getPole()), 1.0e-10);
+        Assert.assertEquals(0.5 * Math.PI, reversed.getPole().angle(reversed.getYAxis()), 1.0e-10);
         Assert.assertEquals(0.0,
-                            reversed.getPole().distance(Vector3D.crossProduct(reversed.getXAxis(), reversed.getYAxis())),
+                            reversed.getPole().distance(reversed.getXAxis().crossProduct(reversed.getYAxis())),
                             1.0e-10);
 
-        Assert.assertEquals(0, Vector3D.angle(circle.getXAxis(), reversed.getXAxis()), 1.0e-10);
-        Assert.assertEquals(Math.PI, Vector3D.angle(circle.getYAxis(), reversed.getYAxis()), 1.0e-10);
-        Assert.assertEquals(Math.PI, Vector3D.angle(circle.getPole(), reversed.getPole()), 1.0e-10);
+        Assert.assertEquals(0, circle.getXAxis().angle(reversed.getXAxis()), 1.0e-10);
+        Assert.assertEquals(Math.PI, circle.getYAxis().angle(reversed.getYAxis()), 1.0e-10);
+        Assert.assertEquals(Math.PI, circle.getPole().angle(reversed.getPole()), 1.0e-10);
 
         Assert.assertTrue(circle.sameOrientationAs(circle));
         Assert.assertFalse(circle.sameOrientationAs(reversed));
-
     }
 
     @Test
@@ -86,14 +85,13 @@ public class CircleTest {
         Vector3D p = Vector3D.of(1, 2, -4);
         Vector3D samePhase = circle.getPointAt(circle.getPhase(p));
         Assert.assertEquals(0.0,
-                            Vector3D.angle(Vector3D.crossProduct(circle.getPole(), p),
-                                           Vector3D.crossProduct(circle.getPole(), samePhase)),
+                            circle.getPole().crossProduct(p).angle(
+                                           circle.getPole().crossProduct(samePhase)),
                             1.0e-10);
-        Assert.assertEquals(0.5 * Math.PI, Vector3D.angle(circle.getPole(), samePhase), 1.0e-10);
+        Assert.assertEquals(0.5 * Math.PI, circle.getPole().angle(samePhase), 1.0e-10);
         Assert.assertEquals(circle.getPhase(p), circle.getPhase(samePhase), 1.0e-10);
         Assert.assertEquals(0.0, circle.getPhase(circle.getXAxis()), 1.0e-10);
         Assert.assertEquals(0.5 * Math.PI, circle.getPhase(circle.getYAxis()), 1.0e-10);
-
     }
 
     @Test
@@ -113,7 +111,7 @@ public class CircleTest {
                                       Math.sin(alpha), circle.getYAxis());
             Vector3D q = circle.toSpace(S1Point.of(alpha)).getVector();
             Assert.assertEquals(0.0, p.distance(q), 1.0e-10);
-            Assert.assertEquals(0.5 * Math.PI, Vector3D.angle(circle.getPole(), q), 1.0e-10);
+            Assert.assertEquals(0.5 * Math.PI, circle.getPole().angle(q), 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 1051ea2..9c9f891 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
@@ -478,7 +478,7 @@ public class SphericalPolygonsSetTest {
                 ++count;
                 for (int i = 0; i < Math.ceil(v.getOutgoing().getLength() / step); ++i) {
                     Vector3D p = v.getOutgoing().getPointAt(i * step);
-                    Assert.assertTrue(Vector3D.angle(p, enclosingCenter) <= enclosing.getRadius());
+                    Assert.assertTrue(p.angle(enclosingCenter) <= enclosing.getRadius());
                 }
             }
         }
@@ -500,7 +500,7 @@ public class SphericalPolygonsSetTest {
                 ++count;
                 for (int i = 0; i < Math.ceil(v.getOutgoing().getLength() / step); ++i) {
                     Vector3D p = v.getOutgoing().getPointAt(i * step);
-                    Assert.assertTrue(Vector3D.angle(p, continentalCenter) <= continentalInscribed.getRadius());
+                    Assert.assertTrue(p.angle(continentalCenter) <= continentalInscribed.getRadius());
                 }
             }
         }
@@ -515,7 +515,7 @@ public class SphericalPolygonsSetTest {
                 ++count;
                 for (int i = 0; i < Math.ceil(v.getOutgoing().getLength() / step); ++i) {
                     Vector3D p = v.getOutgoing().getPointAt(i * step);
-                    Assert.assertTrue(Vector3D.angle(p, corsicaCenter) <= corsicaInscribed.getRadius());
+                    Assert.assertTrue(p.angle(corsicaCenter) <= corsicaInscribed.getRadius());
                 }
             }
         }


[commons-geometry] 07/14: GEOMETRY-9: adding lerp method to Euclidean points and vectors

Posted by er...@apache.org.
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 43cbc50bae35be37f19f9c955a90803e08af7fa2
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Sun Sep 2 23:27:19 2018 -0400

    GEOMETRY-9: adding lerp method to Euclidean points and vectors
---
 .../commons/geometry/euclidean/EuclideanPoint.java | 10 +++++
 .../geometry/euclidean/EuclideanVector.java        | 10 +++++
 .../commons/geometry/euclidean/oned/Point1D.java   | 18 ++++++++
 .../commons/geometry/euclidean/oned/Vector1D.java  | 18 ++++++++
 .../commons/geometry/euclidean/threed/Point3D.java | 18 ++++++++
 .../geometry/euclidean/threed/Vector3D.java        | 18 ++++++++
 .../commons/geometry/euclidean/twod/Point2D.java   | 18 ++++++++
 .../commons/geometry/euclidean/twod/Vector2D.java  | 18 ++++++++
 .../geometry/euclidean/oned/Point1DTest.java       | 52 ++++++++++++++++++++++
 .../geometry/euclidean/oned/Vector1DTest.java      | 52 ++++++++++++++++++++++
 .../geometry/euclidean/threed/Point3DTest.java     | 52 ++++++++++++++++++++++
 .../geometry/euclidean/threed/Vector3DTest.java    | 52 ++++++++++++++++++++++
 .../geometry/euclidean/twod/Point2DTest.java       | 52 ++++++++++++++++++++++
 .../geometry/euclidean/twod/Vector2DTest.java      | 52 ++++++++++++++++++++++
 14 files changed, 440 insertions(+)

diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanPoint.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanPoint.java
index 033b6bd..4941306 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanPoint.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanPoint.java
@@ -40,4 +40,14 @@ public interface EuclideanPoint<P extends EuclideanPoint<P, V>, V extends Euclid
      * @return vector representing the displacement <em>from</em> this point <em>to</em> the given point
      */
     V vectorTo(P p);
+
+    /** Linearly interpolates between this point and the given point using the equation
+     * {@code P = (1 - t)*A + t*B}, where {@code A} is the current point and {@code B}
+     * is the given point. This means that if {@code t = 0}, a point equal to the current
+     * point will be returned. If {@code t = 1}, a point equal to the argument will be returned.
+     * @param p other point
+     * @param t interpolation parameter
+     * @return interpolated point
+     */
+    P lerp(P p, double t);
 }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
index 0622c89..923df74 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
@@ -32,4 +32,14 @@ public interface EuclideanVector<P extends EuclideanPoint<P, V>, V extends Eucli
      * @return point with the same coordinates as this vector
      */
     P asPoint();
+
+    /** Linearly interpolates between this vector and the given vector using the equation
+     * {@code V = (1 - t)*A + t*B}, where {@code A} is the current vector and {@code B}
+     * is the given vector. This means that if {@code t = 0}, a vector equal to the current
+     * vector will be returned. If {@code t = 1}, a vector equal to the argument will be returned.
+     * @param v other vector
+     * @param t interpolation parameter
+     * @return interpolated vector
+     */
+    V lerp(V p, double t);
 }
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 af324c1..b304014 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
@@ -94,6 +94,12 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D
 
     /** {@inheritDoc} */
     @Override
+    public Point1D lerp(Point1D p, double t) {
+        return vectorCombination(1.0 - t, this, t, p);
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public Point1D add(Vector1D v) {
         return new Point1D(getX() + v.getX());
     }
@@ -174,6 +180,18 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D
         return SimpleTupleFormat.getDefault().parse(str, FACTORY);
     }
 
+    /** Linearly interpolates between the two given points. This methods simply
+     * calls {@code a.lerp(b, t)}.
+     * @param a first point
+     * @param b second point
+     * @param t interpolation parameter
+     * @return the interpolated point
+     * @see #lerp(Point1D, double)
+     */
+    public static Point1D lerp(Point1D a, Point1D b, double t) {
+        return a.lerp(b, t);
+    }
+
     /** Returns a point with coordinates calculated by multiplying each input coordinate
      * with its corresponding factor and adding the results.
      *
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 207f949..dea8636 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
@@ -80,6 +80,12 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
 
     /** {@inheritDoc} */
     @Override
+    public Vector1D lerp(Vector1D p, double t) {
+        return linearCombination(1.0 - t, this, t, p);
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public Vector1D getZero() {
         return ZERO;
     }
@@ -281,6 +287,18 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
         return SimpleTupleFormat.getDefault().parse(str, FACTORY);
     }
 
+    /** Linearly interpolates between the two given vectors. This methods simply
+     * calls {@code a.lerp(b, t)}.
+     * @param a first vector
+     * @param b second vector
+     * @param t interpolation parameter
+     * @return the interpolated vector
+     * @see #lerp(Vector1D, double)
+     */
+    public static Vector1D lerp(Vector1D a, Vector1D b, double t) {
+        return a.lerp(b, t);
+    }
+
     /** Returns a vector consisting of the linear combination of the inputs.
      * <p>
      * A linear combination is the sum of all of the inputs multiplied by their
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 92d861a..f8146a5 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
@@ -100,6 +100,12 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D
 
     /** {@inheritDoc} */
     @Override
+    public Point3D lerp(Point3D p, double t) {
+        return vectorCombination(1.0 - t, this, t, p);
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public Point3D add(Vector3D v) {
         return new Point3D(
                     getX() + v.getX(),
@@ -209,6 +215,18 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D
         return SimpleTupleFormat.getDefault().parse(str, FACTORY);
     }
 
+    /** Linearly interpolates between the two given points. This methods simply
+     * calls {@code a.lerp(b, t)}.
+     * @param a first point
+     * @param b second point
+     * @param t interpolation parameter
+     * @return the interpolated point
+     * @see #lerp(Point3D, double)
+     */
+    public static Point3D lerp(Point3D a, Point3D b, double t) {
+        return a.lerp(b, t);
+    }
+
     /** Returns a point with coordinates calculated by multiplying each input coordinate
      * with its corresponding factor and adding the results.
      *
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 a84f3d7..0f28c22 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
@@ -99,6 +99,12 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
 
     /** {@inheritDoc} */
     @Override
+    public Vector3D lerp(Vector3D p, double t) {
+        return linearCombination(1.0 - t, this, t, p);
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public double getNorm1() {
         return Vectors.norm1(getX(), getY(), getZ());
     }
@@ -530,6 +536,18 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return SimpleTupleFormat.getDefault().parse(str, FACTORY);
     }
 
+    /** Linearly interpolates between the two given vectors. This methods simply
+     * calls {@code a.lerp(b, t)}.
+     * @param a first vector
+     * @param b second vector
+     * @param t interpolation parameter
+     * @return the interpolated vector
+     * @see #lerp(Vector3D, double)
+     */
+    public static Vector3D lerp(Vector3D a, Vector3D b, double t) {
+        return a.lerp(b, t);
+    }
+
     /** Returns a vector consisting of the linear combination of the inputs.
      * <p>
      * A linear combination is the sum of all of the inputs multiplied by their
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 a994c45..5f781d4 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
@@ -91,6 +91,12 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D
 
     /** {@inheritDoc} */
     @Override
+    public Point2D lerp(Point2D p, double t) {
+        return vectorCombination(1.0 - t, this, t, p);
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public Point2D add(Vector2D v) {
         return new Point2D(getX() + v.getX(), getY() + v.getY());
     }
@@ -192,6 +198,18 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D
         return SimpleTupleFormat.getDefault().parse(str, FACTORY);
     }
 
+    /** Linearly interpolates between the two given points. This methods simply
+     * calls {@code a.lerp(b, t)}.
+     * @param a first point
+     * @param b second point
+     * @param t interpolation parameter
+     * @return the interpolated point
+     * @see #lerp(Point2D, double)
+     */
+    public static Point2D lerp(Point2D a, Point2D b, double t) {
+        return a.lerp(b, t);
+    }
+
     /** Returns a point with coordinates calculated by multiplying each input coordinate
      * with its corresponding factor and adding the results.
      *
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 2f39b06..bf2b691 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
@@ -93,6 +93,12 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
 
     /** {@inheritDoc} */
     @Override
+    public Vector2D lerp(Vector2D p, double t) {
+        return linearCombination(1.0 - t, this, t, p);
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public Vector2D getZero() {
         return ZERO;
     }
@@ -461,6 +467,18 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
         return SimpleTupleFormat.getDefault().parse(str, FACTORY);
     }
 
+    /** Linearly interpolates between the two given vectors. This methods simply
+     * calls {@code a.lerp(b, t)}.
+     * @param a first vector
+     * @param b second vector
+     * @param t interpolation parameter
+     * @return the interpolated vector
+     * @see #lerp(Vector2D, double)
+     */
+    public static Vector2D lerp(Vector2D a, Vector2D b, double t) {
+        return a.lerp(b, t);
+    }
+
     /** Returns a vector consisting of the linear combination of the inputs.
      * <p>
      * A linear combination is the sum of all of the inputs multiplied by their
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 8233d1c..262204f 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
@@ -118,6 +118,58 @@ public class Point1DTest {
     }
 
     @Test
+    public void testLerp() {
+        // arrange
+        Point1D p1 = Point1D.of(1);
+        Point1D p2 = Point1D.of(-4);
+        Point1D p3 = Point1D.of(10);
+
+        // act/assert
+        checkPoint(p1.lerp(p1, 0), 1);
+        checkPoint(p1.lerp(p1, 1), 1);
+
+        checkPoint(p1.lerp(p2, -0.25), 2.25);
+        checkPoint(p1.lerp(p2, 0), 1);
+        checkPoint(p1.lerp(p2, 0.25), -0.25);
+        checkPoint(p1.lerp(p2, 0.5), -1.5);
+        checkPoint(p1.lerp(p2, 0.75), -2.75);
+        checkPoint(p1.lerp(p2, 1), -4);
+        checkPoint(p1.lerp(p2, 1.25), -5.25);
+
+        checkPoint(p1.lerp(p3, 0), 1);
+        checkPoint(p1.lerp(p3, 0.25), 3.25);
+        checkPoint(p1.lerp(p3, 0.5), 5.5);
+        checkPoint(p1.lerp(p3, 0.75), 7.75);
+        checkPoint(p1.lerp(p3, 1), 10);
+    }
+
+    @Test
+    public void testLerp_static() {
+        // arrange
+        Point1D p1 = Point1D.of(1);
+        Point1D p2 = Point1D.of(-4);
+        Point1D p3 = Point1D.of(10);
+
+        // act/assert
+        checkPoint(Point1D.lerp(p1, p1, 0), 1);
+        checkPoint(Point1D.lerp(p1, p1, 1), 1);
+
+        checkPoint(Point1D.lerp(p1, p2, -0.25), 2.25);
+        checkPoint(Point1D.lerp(p1, p2, 0), 1);
+        checkPoint(Point1D.lerp(p1, p2, 0.25), -0.25);
+        checkPoint(Point1D.lerp(p1, p2, 0.5), -1.5);
+        checkPoint(Point1D.lerp(p1, p2, 0.75), -2.75);
+        checkPoint(Point1D.lerp(p1, p2, 1), -4);
+        checkPoint(Point1D.lerp(p1, p2, 1.25), -5.25);
+
+        checkPoint(Point1D.lerp(p1, p3, 0), 1);
+        checkPoint(Point1D.lerp(p1, p3, 0.25), 3.25);
+        checkPoint(Point1D.lerp(p1, p3, 0.5), 5.5);
+        checkPoint(Point1D.lerp(p1, p3, 0.75), 7.75);
+        checkPoint(Point1D.lerp(p1, p3, 1), 10);
+    }
+
+    @Test
     public void testAdd() {
         // arrange
         Point1D p1 = Point1D.of(2.0);
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
index 2ac2cc7..14b40b7 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
@@ -292,6 +292,58 @@ public class Vector1DTest {
     }
 
     @Test
+    public void testLerp() {
+        // arrange
+        Vector1D v1 = Vector1D.of(1);
+        Vector1D v2 = Vector1D.of(-4);
+        Vector1D v3 = Vector1D.of(10);
+
+        // act/assert
+        checkVector(v1.lerp(v1, 0), 1);
+        checkVector(v1.lerp(v1, 1), 1);
+
+        checkVector(v1.lerp(v2, -0.25), 2.25);
+        checkVector(v1.lerp(v2, 0), 1);
+        checkVector(v1.lerp(v2, 0.25), -0.25);
+        checkVector(v1.lerp(v2, 0.5), -1.5);
+        checkVector(v1.lerp(v2, 0.75), -2.75);
+        checkVector(v1.lerp(v2, 1), -4);
+        checkVector(v1.lerp(v2, 1.25), -5.25);
+
+        checkVector(v1.lerp(v3, 0), 1);
+        checkVector(v1.lerp(v3, 0.25), 3.25);
+        checkVector(v1.lerp(v3, 0.5), 5.5);
+        checkVector(v1.lerp(v3, 0.75), 7.75);
+        checkVector(v1.lerp(v3, 1), 10);
+    }
+
+    @Test
+    public void testLerp_static() {
+        // arrange
+        Vector1D v1 = Vector1D.of(1);
+        Vector1D v2 = Vector1D.of(-4);
+        Vector1D v3 = Vector1D.of(10);
+
+        // act/assert
+        checkVector(Vector1D.lerp(v1, v1, 0), 1);
+        checkVector(Vector1D.lerp(v1, v1, 1), 1);
+
+        checkVector(Vector1D.lerp(v1, v2, -0.25), 2.25);
+        checkVector(Vector1D.lerp(v1, v2, 0), 1);
+        checkVector(Vector1D.lerp(v1, v2, 0.25), -0.25);
+        checkVector(Vector1D.lerp(v1, v2, 0.5), -1.5);
+        checkVector(Vector1D.lerp(v1, v2, 0.75), -2.75);
+        checkVector(Vector1D.lerp(v1, v2, 1), -4);
+        checkVector(Vector1D.lerp(v1, v2, 1.25), -5.25);
+
+        checkVector(Vector1D.lerp(v1, v3, 0), 1);
+        checkVector(Vector1D.lerp(v1, v3, 0.25), 3.25);
+        checkVector(Vector1D.lerp(v1, v3, 0.5), 5.5);
+        checkVector(Vector1D.lerp(v1, v3, 0.75), 7.75);
+        checkVector(Vector1D.lerp(v1, v3, 1), 10);
+    }
+
+    @Test
     public void testHashCode() {
         // arrange
         Vector1D u = Vector1D.of(1);
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 b76cbda..17bfcb5 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
@@ -103,6 +103,58 @@ public class Point3DTest {
     }
 
     @Test
+    public void testLerp() {
+        // arrange
+        Point3D p1 = Point3D.of(1, -5, 2);
+        Point3D p2 = Point3D.of(-4, 0, 2);
+        Point3D p3 = Point3D.of(10, -4, 0);
+
+        // act/assert
+        checkPoint(p1.lerp(p1, 0), 1, -5, 2);
+        checkPoint(p1.lerp(p1, 1), 1, -5, 2);
+
+        checkPoint(p1.lerp(p2, -0.25), 2.25, -6.25, 2);
+        checkPoint(p1.lerp(p2, 0), 1, -5, 2);
+        checkPoint(p1.lerp(p2, 0.25), -0.25, -3.75, 2);
+        checkPoint(p1.lerp(p2, 0.5), -1.5, -2.5, 2);
+        checkPoint(p1.lerp(p2, 0.75), -2.75, -1.25, 2);
+        checkPoint(p1.lerp(p2, 1), -4, 0, 2);
+        checkPoint(p1.lerp(p2, 1.25), -5.25, 1.25, 2);
+
+        checkPoint(p1.lerp(p3, 0), 1, -5, 2);
+        checkPoint(p1.lerp(p3, 0.25), 3.25, -4.75, 1.5);
+        checkPoint(p1.lerp(p3, 0.5), 5.5, -4.5, 1);
+        checkPoint(p1.lerp(p3, 0.75), 7.75, -4.25, 0.5);
+        checkPoint(p1.lerp(p3, 1), 10, -4, 0);
+    }
+
+    @Test
+    public void testLerp_static() {
+        // arrange
+        Point3D p1 = Point3D.of(1, -5, 2);
+        Point3D p2 = Point3D.of(-4, 0, 2);
+        Point3D p3 = Point3D.of(10, -4, 0);
+
+        // act/assert
+        checkPoint(Point3D.lerp(p1, p1, 0), 1, -5, 2);
+        checkPoint(Point3D.lerp(p1, p1, 1), 1, -5, 2);
+
+        checkPoint(Point3D.lerp(p1, p2, -0.25), 2.25, -6.25, 2);
+        checkPoint(Point3D.lerp(p1, p2, 0), 1, -5, 2);
+        checkPoint(Point3D.lerp(p1, p2, 0.25), -0.25, -3.75, 2);
+        checkPoint(Point3D.lerp(p1, p2, 0.5), -1.5, -2.5, 2);
+        checkPoint(Point3D.lerp(p1, p2, 0.75), -2.75, -1.25, 2);
+        checkPoint(Point3D.lerp(p1, p2, 1), -4, 0, 2);
+        checkPoint(Point3D.lerp(p1, p2, 1.25), -5.25, 1.25, 2);
+
+        checkPoint(Point3D.lerp(p1, p3, 0), 1, -5, 2);
+        checkPoint(Point3D.lerp(p1, p3, 0.25), 3.25, -4.75, 1.5);
+        checkPoint(Point3D.lerp(p1, p3, 0.5), 5.5, -4.5, 1);
+        checkPoint(Point3D.lerp(p1, p3, 0.75), 7.75, -4.25, 0.5);
+        checkPoint(Point3D.lerp(p1, p3, 1), 10, -4, 0);
+    }
+
+    @Test
     public void testAdd() {
         // act/assert
         Point3D p1 = Point3D.of(1, 2, 3);
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 2abc8f5..4febb3b 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
@@ -811,6 +811,58 @@ public class Vector3DTest {
     }
 
     @Test
+    public void testLerp() {
+        // arrange
+        Vector3D v1 = Vector3D.of(1, -5, 2);
+        Vector3D v2 = Vector3D.of(-4, 0, 2);
+        Vector3D v3 = Vector3D.of(10, -4, 0);
+
+        // act/assert
+        checkVector(v1.lerp(v1, 0), 1, -5, 2);
+        checkVector(v1.lerp(v1, 1), 1, -5, 2);
+
+        checkVector(v1.lerp(v2, -0.25), 2.25, -6.25, 2);
+        checkVector(v1.lerp(v2, 0), 1, -5, 2);
+        checkVector(v1.lerp(v2, 0.25), -0.25, -3.75, 2);
+        checkVector(v1.lerp(v2, 0.5), -1.5, -2.5, 2);
+        checkVector(v1.lerp(v2, 0.75), -2.75, -1.25, 2);
+        checkVector(v1.lerp(v2, 1), -4, 0, 2);
+        checkVector(v1.lerp(v2, 1.25), -5.25, 1.25, 2);
+
+        checkVector(v1.lerp(v3, 0), 1, -5, 2);
+        checkVector(v1.lerp(v3, 0.25), 3.25, -4.75, 1.5);
+        checkVector(v1.lerp(v3, 0.5), 5.5, -4.5, 1);
+        checkVector(v1.lerp(v3, 0.75), 7.75, -4.25, 0.5);
+        checkVector(v1.lerp(v3, 1), 10, -4, 0);
+    }
+
+    @Test
+    public void testLerp_static() {
+        // arrange
+        Vector3D v1 = Vector3D.of(1, -5, 2);
+        Vector3D v2 = Vector3D.of(-4, 0, 2);
+        Vector3D v3 = Vector3D.of(10, -4, 0);
+
+        // act/assert
+        checkVector(Vector3D.lerp(v1, v1, 0), 1, -5, 2);
+        checkVector(Vector3D.lerp(v1, v1, 1), 1, -5, 2);
+
+        checkVector(Vector3D.lerp(v1, v2, -0.25), 2.25, -6.25, 2);
+        checkVector(Vector3D.lerp(v1, v2, 0), 1, -5, 2);
+        checkVector(Vector3D.lerp(v1, v2, 0.25), -0.25, -3.75, 2);
+        checkVector(Vector3D.lerp(v1, v2, 0.5), -1.5, -2.5, 2);
+        checkVector(Vector3D.lerp(v1, v2, 0.75), -2.75, -1.25, 2);
+        checkVector(Vector3D.lerp(v1, v2, 1), -4, 0, 2);
+        checkVector(Vector3D.lerp(v1, v2, 1.25), -5.25, 1.25, 2);
+
+        checkVector(Vector3D.lerp(v1, v3, 0), 1, -5, 2);
+        checkVector(Vector3D.lerp(v1, v3, 0.25), 3.25, -4.75, 1.5);
+        checkVector(Vector3D.lerp(v1, v3, 0.5), 5.5, -4.5, 1);
+        checkVector(Vector3D.lerp(v1, v3, 0.75), 7.75, -4.25, 0.5);
+        checkVector(Vector3D.lerp(v1, v3, 1), 10, -4, 0);
+    }
+
+    @Test
     public void testHashCode() {
         // arrange
         double delta = 10 * Precision.EPSILON;
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 69c3aa3..b3582ea 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
@@ -94,6 +94,58 @@ public class Point2DTest {
     }
 
     @Test
+    public void testLerp() {
+        // arrange
+        Point2D p1 = Point2D.of(1, -5);
+        Point2D p2 = Point2D.of(-4, 0);
+        Point2D p3 = Point2D.of(10, -4);
+
+        // act/assert
+        checkPoint(p1.lerp(p1, 0), 1, -5);
+        checkPoint(p1.lerp(p1, 1), 1, -5);
+
+        checkPoint(p1.lerp(p2, -0.25), 2.25, -6.25);
+        checkPoint(p1.lerp(p2, 0), 1, -5);
+        checkPoint(p1.lerp(p2, 0.25), -0.25, -3.75);
+        checkPoint(p1.lerp(p2, 0.5), -1.5, -2.5);
+        checkPoint(p1.lerp(p2, 0.75), -2.75, -1.25);
+        checkPoint(p1.lerp(p2, 1), -4, 0);
+        checkPoint(p1.lerp(p2, 1.25), -5.25, 1.25);
+
+        checkPoint(p1.lerp(p3, 0), 1, -5);
+        checkPoint(p1.lerp(p3, 0.25), 3.25, -4.75);
+        checkPoint(p1.lerp(p3, 0.5), 5.5, -4.5);
+        checkPoint(p1.lerp(p3, 0.75), 7.75, -4.25);
+        checkPoint(p1.lerp(p3, 1), 10, -4);
+    }
+
+    @Test
+    public void testLerp_static() {
+        // arrange
+        Point2D p1 = Point2D.of(1, -5);
+        Point2D p2 = Point2D.of(-4, 0);
+        Point2D p3 = Point2D.of(10, -4);
+
+        // act/assert
+        checkPoint(Point2D.lerp(p1, p1, 0), 1, -5);
+        checkPoint(Point2D.lerp(p1, p1, 1), 1, -5);
+
+        checkPoint(Point2D.lerp(p1, p2, -0.25), 2.25, -6.25);
+        checkPoint(Point2D.lerp(p1, p2, 0), 1, -5);
+        checkPoint(Point2D.lerp(p1, p2, 0.25), -0.25, -3.75);
+        checkPoint(Point2D.lerp(p1, p2, 0.5), -1.5, -2.5);
+        checkPoint(Point2D.lerp(p1, p2, 0.75), -2.75, -1.25);
+        checkPoint(Point2D.lerp(p1, p2, 1), -4, 0);
+        checkPoint(Point2D.lerp(p1, p2, 1.25), -5.25, 1.25);
+
+        checkPoint(Point2D.lerp(p1, p3, 0), 1, -5);
+        checkPoint(Point2D.lerp(p1, p3, 0.25), 3.25, -4.75);
+        checkPoint(Point2D.lerp(p1, p3, 0.5), 5.5, -4.5);
+        checkPoint(Point2D.lerp(p1, p3, 0.75), 7.75, -4.25);
+        checkPoint(Point2D.lerp(p1, p3, 1), 10, -4);
+    }
+
+    @Test
     public void testAdd() {
         // arrange
         Point2D p1 = Point2D.of(1, 1);
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 3da0318..2af7341 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
@@ -591,6 +591,58 @@ public class Vector2DTest {
     }
 
     @Test
+    public void testLerp() {
+        // arrange
+        Vector2D v1 = Vector2D.of(1, -5);
+        Vector2D v2 = Vector2D.of(-4, 0);
+        Vector2D v3 = Vector2D.of(10, -4);
+
+        // act/assert
+        checkVector(v1.lerp(v1, 0), 1, -5);
+        checkVector(v1.lerp(v1, 1), 1, -5);
+
+        checkVector(v1.lerp(v2, -0.25), 2.25, -6.25);
+        checkVector(v1.lerp(v2, 0), 1, -5);
+        checkVector(v1.lerp(v2, 0.25), -0.25, -3.75);
+        checkVector(v1.lerp(v2, 0.5), -1.5, -2.5);
+        checkVector(v1.lerp(v2, 0.75), -2.75, -1.25);
+        checkVector(v1.lerp(v2, 1), -4, 0);
+        checkVector(v1.lerp(v2, 1.25), -5.25, 1.25);
+
+        checkVector(v1.lerp(v3, 0), 1, -5);
+        checkVector(v1.lerp(v3, 0.25), 3.25, -4.75);
+        checkVector(v1.lerp(v3, 0.5), 5.5, -4.5);
+        checkVector(v1.lerp(v3, 0.75), 7.75, -4.25);
+        checkVector(v1.lerp(v3, 1), 10, -4);
+    }
+
+    @Test
+    public void testLerp_static() {
+        // arrange
+        Vector2D v1 = Vector2D.of(1, -5);
+        Vector2D v2 = Vector2D.of(-4, 0);
+        Vector2D v3 = Vector2D.of(10, -4);
+
+        // act/assert
+        checkVector(Vector2D.lerp(v1, v1, 0), 1, -5);
+        checkVector(Vector2D.lerp(v1, v1, 1), 1, -5);
+
+        checkVector(Vector2D.lerp(v1, v2, -0.25), 2.25, -6.25);
+        checkVector(Vector2D.lerp(v1, v2, 0), 1, -5);
+        checkVector(Vector2D.lerp(v1, v2, 0.25), -0.25, -3.75);
+        checkVector(Vector2D.lerp(v1, v2, 0.5), -1.5, -2.5);
+        checkVector(Vector2D.lerp(v1, v2, 0.75), -2.75, -1.25);
+        checkVector(Vector2D.lerp(v1, v2, 1), -4, 0);
+        checkVector(Vector2D.lerp(v1, v2, 1.25), -5.25, 1.25);
+
+        checkVector(Vector2D.lerp(v1, v3, 0), 1, -5);
+        checkVector(Vector2D.lerp(v1, v3, 0.25), 3.25, -4.75);
+        checkVector(Vector2D.lerp(v1, v3, 0.5), 5.5, -4.5);
+        checkVector(Vector2D.lerp(v1, v3, 0.75), 7.75, -4.25);
+        checkVector(Vector2D.lerp(v1, v3, 1), 10, -4);
+    }
+
+    @Test
     public void testHashCode() {
         // arrange
         Vector2D u = Vector2D.of(1, 1);


[commons-geometry] 14/14: Merge branch 'GEOMETRY-9__matt'

Posted by er...@apache.org.
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 adbdc69eba4112590003a2869392d3cbac14b963
Merge: d7b4a10 df6704f
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Fri Sep 14 02:17:51 2018 +0200

    Merge branch 'GEOMETRY-9__matt'
    
    Closes #8

 .../org/apache/commons/geometry/core/Vector.java   |  63 ++++-
 .../geometry/core/internal/SimpleTupleFormat.java  |  56 ++---
 .../commons/geometry/core/internal/Vectors.java    | 163 +++++++++++++
 .../geometry/core/internal/VectorsTest.java        | 179 ++++++++++++++
 .../geometry/enclosing/WelzlEncloser3DTest.java    |   6 +-
 .../threed/enclosing/SphereGeneratorTest.java      |   4 +-
 .../twod/enclosing/DiskGeneratorTest.java          |   4 +-
 .../commons/geometry/euclidean/EuclideanPoint.java |  12 +
 .../geometry/euclidean/EuclideanVector.java        |  12 +
 .../euclidean/internal/ZeroNormException.java      |  50 ++++
 .../package-info.java}                             |  24 +-
 .../commons/geometry/euclidean/oned/Point1D.java   |  34 +--
 .../commons/geometry/euclidean/oned/Vector1D.java  | 128 +++++++---
 .../geometry/euclidean/threed/Cartesian3D.java     |  13 --
 .../commons/geometry/euclidean/threed/Line.java    |   2 +-
 .../commons/geometry/euclidean/threed/Plane.java   |   4 +-
 .../commons/geometry/euclidean/threed/Point3D.java |  39 ++--
 .../geometry/euclidean/threed/Rotation.java        |   6 +-
 .../euclidean/threed/SphericalCoordinates.java     |  16 +-
 .../commons/geometry/euclidean/threed/SubLine.java |   2 +-
 .../geometry/euclidean/threed/Vector3D.java        | 218 +++++++++--------
 .../geometry/euclidean/twod/Cartesian2D.java       |  10 -
 .../geometry/euclidean/twod/NestedLoops.java       |   4 +-
 .../commons/geometry/euclidean/twod/Point2D.java   |  36 +--
 .../geometry/euclidean/twod/PolarCoordinates.java  |  16 +-
 .../commons/geometry/euclidean/twod/Vector2D.java  | 176 ++++++++------
 .../geometry/euclidean/oned/Point1DTest.java       |  39 +++-
 .../geometry/euclidean/oned/Vector1DTest.java      | 170 +++++++++++++-
 .../geometry/euclidean/threed/Point3DTest.java     |  47 ++--
 .../euclidean/threed/SphericalCoordinatesTest.java |   2 +-
 .../geometry/euclidean/threed/Vector3DTest.java    | 259 ++++++++++++++++-----
 .../geometry/euclidean/twod/Point2DTest.java       |  45 ++--
 .../euclidean/twod/PolarCoordinatesTest.java       |   4 +-
 .../geometry/euclidean/twod/Vector2DTest.java      | 232 +++++++++++++-----
 .../geometry/euclidean/twod/hull/ConvexHull2D.java |   2 +-
 .../commons/geometry/spherical/oned/S1Point.java   |  15 +-
 .../commons/geometry/spherical/twod/Circle.java    |   4 +-
 .../commons/geometry/spherical/twod/Edge.java      |   6 +-
 .../geometry/spherical/twod/EdgesBuilder.java      |   6 +-
 .../spherical/twod/PropertiesComputer.java         |   6 +-
 .../commons/geometry/spherical/twod/S2Point.java   |  17 +-
 .../spherical/twod/SphericalPolygonsSet.java       |  22 +-
 .../commons/geometry/spherical/twod/SubCircle.java |   3 +-
 .../geometry/spherical/twod/CircleTest.java        |  60 +++--
 .../spherical/twod/SphericalPolygonsSetTest.java   |  82 +++----
 45 files changed, 1605 insertions(+), 693 deletions(-)


[commons-geometry] 05/14: GEOMETRY-9: adding project and reject methods to Vector2D and Vector3D; adding MultiDimensionalVector interface to contain new methods

Posted by er...@apache.org.
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 a78ced7f202486d2bf57eeb070e9529c2e77269d
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Sun Sep 2 22:05:35 2018 -0400

    GEOMETRY-9: adding project and reject methods to Vector2D and Vector3D; adding MultiDimensionalVector interface to contain new methods
---
 .../geometry/core/MultiDimensionalVector.java      |  60 ++++++++++++
 .../geometry/euclidean/threed/Vector3D.java        |  53 +++++++++-
 .../commons/geometry/euclidean/twod/Vector2D.java  |  56 +++++++++--
 .../geometry/euclidean/threed/Vector3DTest.java    | 107 +++++++++++++++++++++
 .../geometry/euclidean/twod/Vector2DTest.java      | 101 +++++++++++++++++++
 5 files changed, 364 insertions(+), 13 deletions(-)

diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java
new file mode 100644
index 0000000..a8eb74e
--- /dev/null
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.geometry.core;
+
+/** Interface representing a vector in a vector space with two or more
+ * dimensions.
+ *
+ * @param <V> Vector implementation type
+ */
+public interface MultiDimensionalVector<V extends MultiDimensionalVector<V>> extends Vector<V> {
+
+    /** Get the projection of the instance onto the given base vector. The returned
+     * vector is parallel to {@code base}. Vector projection and rejection onto
+     * a given base are related by the equation
+     * <code>
+     *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
+     * </code>
+     * @param base
+     * @return the vector projection of the instance onto {@code base}
+     * @exception IllegalStateException if the norm of the base vector is zero
+     * @see #reject(MultiDimensionalVector)
+     */
+    V project(V base) throws IllegalStateException;
+
+    /** Get the rejection of the instance from the given base vector. The returned
+     * vector is orthogonal to {@code base}. This operation can be interpreted as
+     * returning the orthogonal projection of the instance onto the hyperplane
+     * orthogonal to {@code base}. Vector projection and rejection onto
+     * a given base are related by the equation
+     * <code>
+     *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
+     * </code>
+     * @param base
+     * @return the vector rejection of the instance from {@code base}
+     * @exception IllegalStateException if the norm of the base vector is zero
+     * @see #project(MultiDimensionalVector)
+     */
+    V reject(V base) throws IllegalStateException;
+
+    /** Compute the angular separation in radians between two vectors.
+     * @param v other vector
+     * @return angular separation between this instance and v in radians
+     * @exception IllegalStateException if either vector has a zero norm
+     */
+    double angle(V v) throws IllegalStateException;
+}
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 cac3b23..62856a3 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
@@ -16,6 +16,7 @@
  */
 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;
@@ -25,7 +26,7 @@ import org.apache.commons.numbers.arrays.LinearCombination;
 /** This class represents a vector in three-dimensional Euclidean space.
  * Instances of this class are guaranteed to be immutable.
  */
-public final class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Vector3D> {
+public final class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Vector3D>, MultiDimensionalVector<Vector3D> {
 
     /** Zero (null) vector (coordinates: 0, 0, 0). */
     public static final Vector3D ZERO   = new Vector3D(0, 0, 0);
@@ -229,16 +230,14 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return new Vector3D(inverse * y, -inverse * x, 0);
     }
 
-    /** Compute the angular separation between two vectors.
+    /** {@inheritDoc}
      * <p>This method computes the angular separation between two
      * vectors using the dot product for well separated vectors and the
      * cross product for almost aligned vectors. This allows to have a
      * good accuracy in all cases, even for vectors very close to each
      * other.</p>
-     * @param v other vector
-     * @return angular separation between this instance and v
-     * @exception IllegalStateException if either vector has a zero norm
      */
+    @Override
     public double angle(Vector3D v) throws IllegalStateException {
         double normProduct = getNonZeroNorm() * v.getNonZeroNorm();
 
@@ -326,6 +325,50 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return LinearCombination.value(getX(), v.getX(), getY(), v.getY(), getZ(), v.getZ());
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public Vector3D project(Vector3D base) throws IllegalStateException {
+        return getComponent(base, false);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Vector3D reject(Vector3D base) throws IllegalStateException {
+        return getComponent(base, true);
+    }
+
+    /** Returns a component of the current instance relative to the given base
+     * vector. If {@code reject} is true, the vector rejection is returned; otherwise,
+     * the projection is returned.
+     * @param base The base vector
+     * @param reject If true, the rejection of this instance from {@code base} is
+     *      returned. If false, the projection of this instance onto {@code base}
+     *      is returned.
+     * @return The projection or rejection of this instance relative to {@code base},
+     *      depending on the value of {@code reject}.
+     * @throws IllegalStateException if {@code base} has a zero norm
+     */
+    private Vector3D getComponent(Vector3D base, boolean reject) throws IllegalStateException {
+        final double aDotB = dotProduct(base);
+
+        final double baseMagSq = base.getNormSq();
+        if (baseMagSq == 0.0) {
+            throw new IllegalStateException("Invalid base vector: norm is zero");
+        }
+
+        final double scale = aDotB / baseMagSq;
+
+        final double projX = scale * base.getX();
+        final double projY = scale * base.getY();
+        final double projZ = scale * base.getZ();
+
+        if (reject) {
+            return new Vector3D(getX() - projX, getY() - projY, getZ() - projZ);
+        }
+
+        return new Vector3D(projX, projY, projZ);
+    }
+
     /**
      * Get a hashCode for the vector.
      * <p>All NaN values have the same hash code.</p>
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 52a16f3..004b6c3 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
@@ -16,6 +16,7 @@
  */
 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;
@@ -25,7 +26,7 @@ import org.apache.commons.numbers.arrays.LinearCombination;
 /** This class represents a vector in two-dimensional Euclidean space.
  * Instances of this class are guaranteed to be immutable.
  */
-public final class Vector2D extends Cartesian2D implements EuclideanVector<Point2D, Vector2D> {
+public final class Vector2D extends Cartesian2D implements EuclideanVector<Point2D, Vector2D>, MultiDimensionalVector<Vector2D> {
 
     /** Zero vector (coordinates: 0, 0). */
     public static final Vector2D ZERO   = new Vector2D(0, 0);
@@ -215,19 +216,58 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
         return LinearCombination.value(getX(), v.getX(), getY(), v.getY());
     }
 
-    /** Compute the angular separation in radians between this vector
-     * and the given vector.
+    /** {@inheritDoc} */
+    @Override
+    public Vector2D project(Vector2D base) throws IllegalStateException {
+        return getComponent(base, false);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Vector2D reject(Vector2D base) throws IllegalStateException {
+        return getComponent(base, true);
+    }
+
+    /** Returns a component of the current instance relative to the given base
+     * vector. If {@code reject} is true, the vector rejection is returned; otherwise,
+     * the projection is returned.
+     * @param base The base vector
+     * @param reject If true, the rejection of this instance from {@code base} is
+     *      returned. If false, the projection of this instance onto {@code base}
+     *      is returned.
+     * @return The projection or rejection of this instance relative to {@code base},
+     *      depending on the value of {@code reject}.
+     * @throws IllegalStateException if {@code base} has a zero norm
+     */
+    private Vector2D getComponent(Vector2D base, boolean reject) throws IllegalStateException {
+        final double aDotB = dotProduct(base);
+
+        final double baseMagSq = base.getNormSq();
+        if (baseMagSq == 0.0) {
+            throw new IllegalStateException("Invalid base vector: norm is zero");
+        }
+
+        final double scale = aDotB / baseMagSq;
+
+        final double projX = scale * base.getX();
+        final double projY = scale * base.getY();
+
+        if (reject) {
+            return new Vector2D(getX() - projX, getY() - projY);
+        }
+
+        return new Vector2D(projX, projY);
+    }
+
+    /** {@inheritDoc}
      * <p>This method computes the angular separation between the two
      * vectors using the dot product for well separated vectors and the
      * cross product for almost aligned vectors. This allows to have a
      * good accuracy in all cases, even for vectors very close to each
      * other.</p>
-     *
-     * @param v vector to compute the angle with
-     * @return angular separation between this vector and v in radians
-     * @exception IllegalStateException if either vector has a zero norm
      */
-    public double angle(Vector2D v) throws IllegalArgumentException {
+    @Override
+    public double angle(Vector2D v) throws IllegalStateException {
         double normProduct = getNonZeroNorm() * v.getNonZeroNorm();
 
         double dot = dotProduct(v);
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 a0dfd4b..834b472 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
@@ -20,6 +20,7 @@ package org.apache.commons.geometry.euclidean.threed;
 import java.util.regex.Pattern;
 
 import org.apache.commons.geometry.core.Geometry;
+import org.apache.commons.geometry.euclidean.EuclideanTestUtils;
 import org.apache.commons.numbers.core.Precision;
 import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.rng.simple.RandomSource;
@@ -616,6 +617,112 @@ public class Vector3DTest {
     }
 
     @Test
+    public void testProject() {
+        // arrange
+        Vector3D v1 = Vector3D.of(2.0, 3.0, 4.0);
+        Vector3D v2 = Vector3D.of(-5.0, -6.0, -7.0);
+
+        // act/assert
+        checkVector(v1.project(Vector3D.PLUS_X), 2.0, 0.0, 0.0);
+        checkVector(v1.project(Vector3D.MINUS_X), 2.0, 0.0, 0.0);
+        checkVector(v1.project(Vector3D.PLUS_Y), 0.0, 3.0, 0.0);
+        checkVector(v1.project(Vector3D.MINUS_Y), 0.0, 3.0, 0.0);
+        checkVector(v1.project(Vector3D.PLUS_Z), 0.0, 0.0, 4.0);
+        checkVector(v1.project(Vector3D.MINUS_Z), 0.0, 0.0, 4.0);
+
+        checkVector(v2.project(Vector3D.PLUS_X), -5.0, 0.0, 0.0);
+        checkVector(v2.project(Vector3D.MINUS_X), -5.0, 0.0, 0.0);
+        checkVector(v2.project(Vector3D.PLUS_Y), 0.0, -6.0, 0.0);
+        checkVector(v2.project(Vector3D.MINUS_Y), 0.0, -6.0, 0.0);
+        checkVector(v2.project(Vector3D.PLUS_Z), 0.0, 0.0, -7.0);
+        checkVector(v2.project(Vector3D.MINUS_Z), 0.0, 0.0, -7.0);
+
+        checkVector(v1.project(Vector3D.of(1.0, 1.0, 1.0)), 3.0, 3.0, 3.0);
+        checkVector(v1.project(Vector3D.of(-1.0, -1.0, -1.0)), 3.0, 3.0, 3.0);
+
+        checkVector(v2.project(Vector3D.of(1.0, 1.0, 1.0)), -6.0, -6.0, -6.0);
+        checkVector(v2.project(Vector3D.of(-1.0, -1.0, -1.0)), -6.0, -6.0, -6.0);
+    }
+
+    @Test
+    public void testReject() {
+        // arrange
+        Vector3D v1 = Vector3D.of(2.0, 3.0, 4.0);
+        Vector3D v2 = Vector3D.of(-5.0, -6.0, -7.0);
+
+        // act/assert
+        checkVector(v1.reject(Vector3D.PLUS_X), 0.0, 3.0, 4.0);
+        checkVector(v1.reject(Vector3D.MINUS_X), 0.0, 3.0, 4.0);
+        checkVector(v1.reject(Vector3D.PLUS_Y), 2.0, 0.0, 4.0);
+        checkVector(v1.reject(Vector3D.MINUS_Y), 2.0, 0.0, 4.0);
+        checkVector(v1.reject(Vector3D.PLUS_Z), 2.0, 3.0, 0.0);
+        checkVector(v1.reject(Vector3D.MINUS_Z), 2.0, 3.0, 0.0);
+
+        checkVector(v2.reject(Vector3D.PLUS_X), 0.0, -6.0, -7.0);
+        checkVector(v2.reject(Vector3D.MINUS_X), 0.0, -6.0, -7.0);
+        checkVector(v2.reject(Vector3D.PLUS_Y), -5.0, 0.0, -7.0);
+        checkVector(v2.reject(Vector3D.MINUS_Y), -5.0, 0.0, -7.0);
+        checkVector(v2.reject(Vector3D.PLUS_Z), -5.0, -6.0, 0.0);
+        checkVector(v2.reject(Vector3D.MINUS_Z), -5.0, -6.0, 0.0);
+
+        checkVector(v1.reject(Vector3D.of(1.0, 1.0, 1.0)), -1.0, 0.0, 1.0);
+        checkVector(v1.reject(Vector3D.of(-1.0, -1.0, -1.0)), -1.0, 0.0, 1.0);
+
+        checkVector(v2.reject(Vector3D.of(1.0, 1.0, 1.0)), 1.0, 0.0, -1.0);
+        checkVector(v2.reject(Vector3D.of(-1.0, -1.0, -1.0)), 1.0, 0.0, -1.0);
+    }
+
+    @Test
+    public void testProjectAndReject_areComplementary() {
+        // arrange
+        double eps = 1e-12;
+
+        // act/assert
+        checkProjectAndRejectFullSphere(Vector3D.of(1.0, 0.0, 0.0), 1.0, eps);
+        checkProjectAndRejectFullSphere(Vector3D.of(0.0, 1.0, 0.0), 2.0, eps);
+        checkProjectAndRejectFullSphere(Vector3D.of(0.0, 0.0, 1.0), 2.0, eps);
+        checkProjectAndRejectFullSphere(Vector3D.of(1.0, 1.0, 1.0), 3.0, eps);
+
+        checkProjectAndRejectFullSphere(Vector3D.of(-2.0, 0.0, 0.0), 1.0, eps);
+        checkProjectAndRejectFullSphere(Vector3D.of(0.0, -2.0, 0.0), 2.0, eps);
+        checkProjectAndRejectFullSphere(Vector3D.of(0.0, 0.0, -2.0), 2.0, eps);
+        checkProjectAndRejectFullSphere(Vector3D.of(-2.0, -2.0, -2.0), 3.0, eps);
+    }
+
+    private void checkProjectAndRejectFullSphere(Vector3D vec, double baseMag, double eps) {
+        for (double polar = 0.0; polar <= Geometry.PI; polar += 0.5) {
+            for (double azimuth = 0.0; azimuth <= Geometry.TWO_PI; azimuth += 0.5) {
+                Vector3D base = Vector3D.ofSpherical(baseMag, azimuth, polar);
+
+                Vector3D proj = vec.project(base);
+                Vector3D rej = vec.reject(base);
+
+                // ensure that the projection and rejection sum to the original vector
+                EuclideanTestUtils.assertCoordinatesEqual(vec, proj.add(rej), eps);
+
+                double angle = base.angle(vec);
+
+                // check the angle between the projection and the base; this will
+                // be undefined when the angle between the original vector and the
+                // base is pi/2 (which means that the projection is the zero vector)
+                if (angle < Geometry.HALF_PI) {
+                    Assert.assertEquals(0.0, proj.angle(base), eps);
+                }
+                else if (angle > Geometry.HALF_PI) {
+                    Assert.assertEquals(Geometry.PI, proj.angle(base), eps);
+                }
+
+                // check the angle between the rejection and the base; this should
+                // always be pi/2 except for when the angle between the original vector
+                // and the base is 0 or pi, in which case the rejection is the zero vector.
+                if (angle > 0.0 && angle < Geometry.PI) {
+                    Assert.assertEquals(Geometry.HALF_PI, rej.angle(base), eps);
+                }
+            }
+        }
+    }
+
+    @Test
     public void testHashCode() {
         // arrange
         double delta = 10 * Precision.EPSILON;
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 3bf0687..7c31092 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
@@ -19,6 +19,7 @@ package org.apache.commons.geometry.euclidean.twod;
 import java.util.regex.Pattern;
 
 import org.apache.commons.geometry.core.Geometry;
+import org.apache.commons.geometry.euclidean.EuclideanTestUtils;
 import org.apache.commons.numbers.core.Precision;
 import org.junit.Assert;
 import org.junit.Test;
@@ -436,6 +437,106 @@ public class Vector2DTest {
     }
 
     @Test
+    public void testProject() {
+        // arrange
+        Vector2D v1 = Vector2D.of(3.0, 4.0);
+        Vector2D v2 = Vector2D.of(1.0, 4.0);
+
+        // act/assert
+        checkVector(Vector2D.ZERO.project(v1), 0.0, 0.0);
+
+        checkVector(v1.project(v1), 3.0, 4.0);
+        checkVector(v1.project(v1.negate()), 3.0, 4.0);
+
+        checkVector(v1.project(Vector2D.PLUS_X), 3.0, 0.0);
+        checkVector(v1.project(Vector2D.MINUS_X), 3.0, 0.0);
+
+        checkVector(v1.project(Vector2D.PLUS_Y), 0.0, 4.0);
+        checkVector(v1.project(Vector2D.MINUS_Y), 0.0, 4.0);
+
+        checkVector(v2.project(v1), (19.0 / 25.0) * 3.0, (19.0 / 25.0) * 4.0);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testProject_baseHasZeroNorm() {
+        // act/assert
+        Vector2D.of(1.0, 1.0).project(Vector2D.ZERO);
+    }
+
+    @Test
+    public void testReject() {
+        // arrange
+        Vector2D v1 = Vector2D.of(3.0, 4.0);
+        Vector2D v2 = Vector2D.of(1.0, 4.0);
+
+        // act/assert
+        checkVector(Vector2D.ZERO.reject(v1), 0.0, 0.0);
+
+        checkVector(v1.reject(v1), 0.0, 0.0);
+        checkVector(v1.reject(v1.negate()), 0.0, 0.0);
+
+        checkVector(v1.reject(Vector2D.PLUS_X), 0.0, 4.0);
+        checkVector(v1.reject(Vector2D.MINUS_X), 0.0, 4.0);
+
+        checkVector(v1.reject(Vector2D.PLUS_Y), 3.0, 0.0);
+        checkVector(v1.reject(Vector2D.MINUS_Y), 3.0, 0.0);
+
+        checkVector(v2.reject(v1), (-32.0 / 25.0), (6.0 / 25.0) * 4.0);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testReject_baseHasZeroNorm() {
+        // act/assert
+        Vector2D.of(1.0, 1.0).reject(Vector2D.ZERO);
+    }
+
+    @Test
+    public void testProjectAndReject_areComplementary() {
+        // arrange
+        double eps = 1e-12;
+
+        // act/assert
+        checkProjectAndRejectFullCircle(Vector2D.of(1.0, 0.0), 1.0, eps);
+        checkProjectAndRejectFullCircle(Vector2D.of(0.0, 1.0), 2.0, eps);
+        checkProjectAndRejectFullCircle(Vector2D.of(1.0, 1.0), 3.0, eps);
+
+        checkProjectAndRejectFullCircle(Vector2D.of(-2.0, 0.0), 4.0, eps);
+        checkProjectAndRejectFullCircle(Vector2D.of(0.0, -2.0), 5.0, eps);
+        checkProjectAndRejectFullCircle(Vector2D.of(-2.0, -2.0), 6.0, eps);
+    }
+
+    private void checkProjectAndRejectFullCircle(Vector2D vec, double baseMag, double eps) {
+        for (double theta = 0.0; theta <= Geometry.TWO_PI; theta += 0.5) {
+            Vector2D base = Vector2D.ofPolar(baseMag, theta);
+
+            Vector2D proj = vec.project(base);
+            Vector2D rej = vec.reject(base);
+
+            // ensure that the projection and rejection sum to the original vector
+            EuclideanTestUtils.assertCoordinatesEqual(vec, proj.add(rej), eps);
+
+            double angle = base.angle(vec);
+
+            // check the angle between the projection and the base; this will
+            // be undefined when the angle between the original vector and the
+            // base is pi/2 (which means that the projection is the zero vector)
+            if (angle < Geometry.HALF_PI) {
+                Assert.assertEquals(0.0, proj.angle(base), eps);
+            }
+            else if (angle > Geometry.HALF_PI) {
+                Assert.assertEquals(Geometry.PI, proj.angle(base), eps);
+            }
+
+            // check the angle between the rejection and the base; this should
+            // always be pi/2 except for when the angle between the original vector
+            // and the base is 0 or pi, in which case the rejection is the zero vector.
+            if (angle > 0.0 && angle < Geometry.PI) {
+                Assert.assertEquals(Geometry.HALF_PI, rej.angle(base), eps);
+            }
+        }
+    }
+
+    @Test
     public void testHashCode() {
         // arrange
         Vector2D u = Vector2D.of(1, 1);


[commons-geometry] 08/14: fixing report errors

Posted by er...@apache.org.
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 443a0a3a67fce2255223952ddc5a55d54096b0f8
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Sun Sep 2 23:44:36 2018 -0400

    fixing report errors
---
 .../geometry/core/MultiDimensionalVector.java      |  4 +--
 .../geometry/core/internal/SimpleTupleFormat.java  | 36 +++++++++++-----------
 .../apache/commons/geometry/core/util/Vectors.java | 12 ++++----
 .../geometry/euclidean/EuclideanVector.java        |  2 +-
 4 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java
index a8eb74e..cf21b56 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java
@@ -29,7 +29,7 @@ public interface MultiDimensionalVector<V extends MultiDimensionalVector<V>> ext
      * <code>
      *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
      * </code>
-     * @param base
+     * @param base base vector
      * @return the vector projection of the instance onto {@code base}
      * @exception IllegalStateException if the norm of the base vector is zero
      * @see #reject(MultiDimensionalVector)
@@ -44,7 +44,7 @@ public interface MultiDimensionalVector<V extends MultiDimensionalVector<V>> ext
      * <code>
      *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
      * </code>
-     * @param base
+     * @param base base vector
      * @return the vector rejection of the instance from {@code base}
      * @exception IllegalStateException if the norm of the base vector is zero
      * @see #project(MultiDimensionalVector)
diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/SimpleTupleFormat.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/SimpleTupleFormat.java
index 041380f..4cca8cc 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/SimpleTupleFormat.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/SimpleTupleFormat.java
@@ -93,7 +93,7 @@ public class SimpleTupleFormat {
      * @return 1-tuple string
      */
     public String format(double a) {
-        StringBuilder sb = new StringBuilder();
+        final StringBuilder sb = new StringBuilder();
 
         if (prefix != null) {
             sb.append(prefix);
@@ -114,16 +114,16 @@ public class SimpleTupleFormat {
      * @return 2-tuple string
      */
     public String format(double a1, double a2) {
-        StringBuilder sb = new StringBuilder();
+        final StringBuilder sb = new StringBuilder();
 
         if (prefix != null) {
             sb.append(prefix);
         }
 
-        sb.append(a1);
-        sb.append(separator);
-        sb.append(SPACE);
-        sb.append(a2);
+        sb.append(a1)
+            .append(separator)
+            .append(SPACE)
+            .append(a2);
 
         if (suffix != null) {
             sb.append(suffix);
@@ -139,19 +139,19 @@ public class SimpleTupleFormat {
      * @return 3-tuple string
      */
     public String format(double a1, double a2, double a3) {
-        StringBuilder sb = new StringBuilder();
+        final StringBuilder sb = new StringBuilder();
 
         if (prefix != null) {
             sb.append(prefix);
         }
 
-        sb.append(a1);
-        sb.append(separator);
-        sb.append(SPACE);
-        sb.append(a2);
-        sb.append(separator);
-        sb.append(SPACE);
-        sb.append(a3);
+        sb.append(a1)
+            .append(separator)
+            .append(SPACE)
+            .append(a2)
+            .append(separator)
+            .append(SPACE)
+            .append(a3);
 
         if (suffix != null) {
             sb.append(suffix);
@@ -208,7 +208,7 @@ public class SimpleTupleFormat {
      * @throws IllegalArgumentException if the input string format is invalid
      */
     public <T> T parse(String str, DoubleFunction3N<T> fn) throws IllegalArgumentException {
-        ParsePosition pos = new ParsePosition(0);
+        final ParsePosition pos = new ParsePosition(0);
 
         readPrefix(str, pos);
         final double v1 = readTupleValue(str, pos);
@@ -257,9 +257,9 @@ public class SimpleTupleFormat {
             }
         }
 
-        String substr = str.substring(startIdx, endIdx);
+        final String substr = str.substring(startIdx, endIdx);
         try {
-            double value = Double.parseDouble(substr);
+            final double value = Double.parseDouble(substr);
 
             // advance the position and move past any terminating separator
             pos.setIndex(endIdx);
@@ -388,7 +388,7 @@ public class SimpleTupleFormat {
      * @throws IllegalArgumentException the exception signaling a parse failure
      */
     private void fail(String msg, String str, ParsePosition pos, Throwable cause) throws IllegalArgumentException {
-        String fullMsg = String.format("Failed to parse string \"%s\" at index %d: %s", str, pos.getIndex(), msg);
+        final String fullMsg = String.format("Failed to parse string \"%s\" at index %d: %s", str, pos.getIndex(), msg);
 
         throw new TupleParseException(fullMsg, cause);
     }
diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java
index f066364..4cd24b2 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java
@@ -20,6 +20,9 @@ package org.apache.commons.geometry.core.util;
  */
 public final class Vectors {
 
+    /** Private constructor. */
+    private Vectors() {}
+
     /** Get the L<sub>1</sub> norm for the vector with the given components.
      * This is defined as the sum of the absolute values of all vector components.
      * @param x vector component
@@ -33,7 +36,7 @@ public final class Vectors {
     /** Get the L<sub>1</sub> norm for the vector with the given components.
      * This is defined as the sum of the absolute values of all vector components.
      * @param x1 first vector component
-     * @param x2 second vector compoent
+     * @param x2 second vector component
      * @return L<sub>1</sub> norm for the vector with the given components
      * @see <a href="http://mathworld.wolfram.com/L1-Norm.html">L1 Norm</a>
      */
@@ -44,8 +47,8 @@ public final class Vectors {
     /** Get the L<sub>1</sub> norm for the vector with the given components.
      * This is defined as the sum of the absolute values of all vector components.
      * @param x1 first vector component
-     * @param x2 second vector compoent
-     * @param x2 third vector component
+     * @param x2 second vector component
+     * @param x3 third vector component
      * @return L<sub>1</sub> norm for the vector with the given components
      * @see <a href="http://mathworld.wolfram.com/L1-Norm.html">L1 Norm</a>
      */
@@ -157,7 +160,4 @@ public final class Vectors {
     public static double normInf(final double x1, final double x2, final double x3) {
         return Math.max(Math.max(Math.abs(x1), Math.abs(x2)), Math.abs(x3));
     }
-
-    /** Private constructor. */
-    private Vectors() {}
 }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
index 923df74..8df3a91 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
@@ -41,5 +41,5 @@ public interface EuclideanVector<P extends EuclideanPoint<P, V>, V extends Eucli
      * @param t interpolation parameter
      * @return interpolated vector
      */
-    V lerp(V p, double t);
+    V lerp(V v, double t);
 }


[commons-geometry] 11/14: GEOMETRY-9: making Vectors class internal per pull request discussion

Posted by er...@apache.org.
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 5cfca2a16fde9918f647836c3c8c98d01f756d7a
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Sun Sep 9 14:32:32 2018 -0400

    GEOMETRY-9: making Vectors class internal per pull request discussion
---
 .../geometry/core/{util => internal}/Vectors.java  |  2 +-
 .../commons/geometry/core/util/package-info.java   | 23 ----------------------
 .../core/{util => internal}/VectorsTest.java       |  3 ++-
 .../commons/geometry/euclidean/oned/Vector1D.java  |  2 +-
 .../commons/geometry/euclidean/threed/Point3D.java |  2 +-
 .../geometry/euclidean/threed/Vector3D.java        |  2 +-
 .../commons/geometry/euclidean/twod/Point2D.java   |  2 +-
 .../commons/geometry/euclidean/twod/Vector2D.java  |  2 +-
 8 files changed, 8 insertions(+), 30 deletions(-)

diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/Vectors.java
similarity index 99%
rename from commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java
rename to commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/Vectors.java
index 4cd24b2..673d53b 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/internal/Vectors.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.geometry.core.util;
+package org.apache.commons.geometry.core.internal;
 
 /** This class consists exclusively of static vector utility methods.
  */
diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/package-info.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/package-info.java
deleted file mode 100644
index fd6dea3..0000000
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- *
- * <p>
- * This package contains geometry utility classes.
- * </p>
- */
-package org.apache.commons.geometry.core.util;
diff --git a/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/util/VectorsTest.java b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/internal/VectorsTest.java
similarity index 98%
rename from commons-geometry-core/src/test/java/org/apache/commons/geometry/core/util/VectorsTest.java
rename to commons-geometry-core/src/test/java/org/apache/commons/geometry/core/internal/VectorsTest.java
index 253192a..9817b28 100644
--- a/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/util/VectorsTest.java
+++ b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/internal/VectorsTest.java
@@ -14,8 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.geometry.core.util;
+package org.apache.commons.geometry.core.internal;
 
+import org.apache.commons.geometry.core.internal.Vectors;
 import org.junit.Assert;
 import org.junit.Test;
 
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 68fec66..57f85b5 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
@@ -18,7 +18,7 @@ package org.apache.commons.geometry.euclidean.oned;
 
 import org.apache.commons.geometry.core.Geometry;
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
-import org.apache.commons.geometry.core.util.Vectors;
+import org.apache.commons.geometry.core.internal.Vectors;
 import org.apache.commons.geometry.euclidean.EuclideanVector;
 import org.apache.commons.geometry.euclidean.internal.ZeroNormException;
 import org.apache.commons.numbers.arrays.LinearCombination;
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 52c574b..a930ba0 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
@@ -18,7 +18,7 @@
 package org.apache.commons.geometry.euclidean.threed;
 
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
-import org.apache.commons.geometry.core.util.Vectors;
+import org.apache.commons.geometry.core.internal.Vectors;
 import org.apache.commons.geometry.euclidean.EuclideanPoint;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
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 2a1a5f7..61644ef 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,7 @@
 package org.apache.commons.geometry.euclidean.threed;
 
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
-import org.apache.commons.geometry.core.util.Vectors;
+import org.apache.commons.geometry.core.internal.Vectors;
 import org.apache.commons.geometry.euclidean.EuclideanVector;
 import org.apache.commons.geometry.euclidean.internal.ZeroNormException;
 import org.apache.commons.numbers.arrays.LinearCombination;
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 f4be64e..3600689 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
@@ -17,7 +17,7 @@
 package org.apache.commons.geometry.euclidean.twod;
 
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
-import org.apache.commons.geometry.core.util.Vectors;
+import org.apache.commons.geometry.core.internal.Vectors;
 import org.apache.commons.geometry.euclidean.EuclideanPoint;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
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 60877cb..946d01b 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,7 @@
 package org.apache.commons.geometry.euclidean.twod;
 
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
-import org.apache.commons.geometry.core.util.Vectors;
+import org.apache.commons.geometry.core.internal.Vectors;
 import org.apache.commons.geometry.euclidean.EuclideanVector;
 import org.apache.commons.geometry.euclidean.internal.ZeroNormException;
 import org.apache.commons.numbers.arrays.LinearCombination;


[commons-geometry] 01/14: GEOMETRY-9: adding getMagnitude, getMagnitudeSq, and withMagnitude methods to Euclidean vectors; creating Vectors utility class to encapsulate vector norm methods

Posted by er...@apache.org.
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 b329f9b0952c9c3537b6bcd0803a482a1001af17
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Fri Jul 20 00:43:59 2018 -0400

    GEOMETRY-9: adding getMagnitude, getMagnitudeSq, and withMagnitude methods to Euclidean vectors; creating Vectors utility class to encapsulate vector norm methods
---
 .../org/apache/commons/geometry/core/Geometry.java |   2 +-
 .../org/apache/commons/geometry/core/Vector.java   |   5 +-
 .../apache/commons/geometry/core/util/Vectors.java | 163 +++++++++++++++++++
 .../core/{Geometry.java => util/package-info.java} |  29 +---
 .../commons/geometry/core/util/VectorsTest.java    | 178 +++++++++++++++++++++
 .../geometry/euclidean/EuclideanVector.java        |  23 +++
 .../commons/geometry/euclidean/oned/Vector1D.java  |  46 +++++-
 .../geometry/euclidean/threed/Cartesian3D.java     |  13 --
 .../commons/geometry/euclidean/threed/Point3D.java |   6 +-
 .../geometry/euclidean/threed/Vector3D.java        | 111 +++++++------
 .../geometry/euclidean/twod/Cartesian2D.java       |  10 --
 .../commons/geometry/euclidean/twod/Point2D.java   |   3 +-
 .../commons/geometry/euclidean/twod/Vector2D.java  |  79 +++++----
 .../geometry/euclidean/oned/Vector1DTest.java      |  34 ++++
 .../geometry/euclidean/threed/Vector3DTest.java    |  51 +++++-
 .../geometry/euclidean/twod/Vector2DTest.java      |  47 +++++-
 16 files changed, 662 insertions(+), 138 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 d74d312..6eb700b 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
@@ -18,7 +18,7 @@ package org.apache.commons.geometry.core;
 
 /** Class containing geometric constants.
  */
-public class Geometry {
+public final class Geometry {
 
     /** Alias for {@link Math#PI}, placed here for completeness. */
     public static final double PI = Math.PI;
diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java
index 1d0269d..03bda8f 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java
@@ -36,7 +36,6 @@ public interface Vector<V extends Vector<V>> extends Spatial {
 
     /** Get the L<sub>1</sub> norm for the vector. This is defined as the
      * sum of the absolute values of all vector components.
-     *
      * @see <a href="http://mathworld.wolfram.com/L1-Norm.html">L1 Norm</a>
      * @return L<sub>1</sub> norm for the vector
      */
@@ -46,14 +45,14 @@ public interface Vector<V extends Vector<V>> extends Spatial {
      * This corresponds to the common notion of vector magnitude or length.
      * This is defined as the square root of the sum of the squares of all vector components.
      * @see <a href="http://mathworld.wolfram.com/L2-Norm.html">L2 Norm</a>
-     * @return Euclidean norm for the vector
+     * @return L<sub>2</sub> norm for the vector
      */
     double getNorm();
 
     /** Get the square of the L<sub>2</sub> norm (also known as the Euclidean norm)
      * for the vector. This is equal to the sum of the squares of all vector components.
      * @see #getNorm()
-     * @return square of the Euclidean norm for the vector
+     * @return square of the L<sub>2</sub> norm for the vector
      */
     double getNormSq();
 
diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java
new file mode 100644
index 0000000..f066364
--- /dev/null
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/Vectors.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.geometry.core.util;
+
+/** This class consists exclusively of static vector utility methods.
+ */
+public final class Vectors {
+
+    /** Get the L<sub>1</sub> norm for the vector with the given components.
+     * This is defined as the sum of the absolute values of all vector components.
+     * @param x vector component
+     * @return L<sub>1</sub> norm for the vector with the given components
+     * @see <a href="http://mathworld.wolfram.com/L1-Norm.html">L1 Norm</a>
+     */
+    public static double norm1(final double x) {
+        return Math.abs(x);
+    }
+
+    /** Get the L<sub>1</sub> norm for the vector with the given components.
+     * This is defined as the sum of the absolute values of all vector components.
+     * @param x1 first vector component
+     * @param x2 second vector compoent
+     * @return L<sub>1</sub> norm for the vector with the given components
+     * @see <a href="http://mathworld.wolfram.com/L1-Norm.html">L1 Norm</a>
+     */
+    public static double norm1(final double x1, final double x2) {
+        return Math.abs(x1) + Math.abs(x2);
+    }
+
+    /** Get the L<sub>1</sub> norm for the vector with the given components.
+     * This is defined as the sum of the absolute values of all vector components.
+     * @param x1 first vector component
+     * @param x2 second vector compoent
+     * @param x2 third vector component
+     * @return L<sub>1</sub> norm for the vector with the given components
+     * @see <a href="http://mathworld.wolfram.com/L1-Norm.html">L1 Norm</a>
+     */
+    public static double norm1(final double x1, final double x2, final double x3) {
+        return Math.abs(x1) + Math.abs(x2) + Math.abs(x3);
+    }
+
+    /** Get the L<sub>2</sub> norm (commonly known as the Euclidean norm) for the vector
+     * with the given components. This corresponds to the common notion of vector magnitude
+     * or length and is defined as the square root of the sum of the squares of all vector components.
+     * @param x vector component
+     * @return L<sub>2</sub> norm for the vector with the given components
+     * @see <a href="http://mathworld.wolfram.com/L2-Norm.html">L2 Norm</a>
+     */
+    public static double norm(final double x) {
+        return Math.abs(x);
+    }
+
+    /** Get the L<sub>2</sub> norm (commonly known as the Euclidean norm) for the vector
+     * with the given components. This corresponds to the common notion of vector magnitude
+     * or length and is defined as the square root of the sum of the squares of all vector components.
+     * @param x1 first vector component
+     * @param x2 second vector component
+     * @return L<sub>2</sub> norm for the vector with the given components
+     * @see <a href="http://mathworld.wolfram.com/L2-Norm.html">L2 Norm</a>
+     */
+    public static double norm(final double x1, final double x2) {
+        return Math.hypot(x1, x2);
+    }
+
+    /** Get the L<sub>2</sub> norm (commonly known as the Euclidean norm) for the vector
+     * with the given components. This corresponds to the common notion of vector magnitude
+     * or length and is defined as the square root of the sum of the squares of all vector components.
+     * @param x1 first vector component
+     * @param x2 second vector component
+     * @param x3 third vector component
+     * @return L<sub>2</sub> norm for the vector with the given components
+     * @see <a href="http://mathworld.wolfram.com/L2-Norm.html">L2 Norm</a>
+     */
+    public static double norm(final double x1, final double x2, final double x3) {
+        return Math.sqrt(normSq(x1, x2, x3));
+    }
+
+    /** Get the square of the L<sub>2</sub> norm (also known as the Euclidean norm)
+     * for the vector with the given components. This is equal to the sum of the squares of
+     * all vector components.
+     * @param x vector component
+     * @return square of the L<sub>2</sub> norm for the vector with the given components
+     * @see #norm(double)
+     */
+    public static double normSq(final double x) {
+        return x * x;
+    }
+
+    /** Get the square of the L<sub>2</sub> norm (also known as the Euclidean norm)
+     * for the vector with the given components. This is equal to the sum of the squares of
+     * all vector components.
+     * @param x1 first vector component
+     * @param x2 second vector component
+     * @return square of the L<sub>2</sub> norm for the vector with the given components
+     * @see #norm(double, double)
+     */
+    public static double normSq(final double x1, final double x2) {
+        return (x1 * x1) + (x2 * x2);
+    }
+
+    /** Get the square of the L<sub>2</sub> norm (also known as the Euclidean norm)
+     * for the vector with the given components. This is equal to the sum of the squares of
+     * all vector components.
+     * @param x1 first vector component
+     * @param x2 second vector component
+     * @param x3 third vector component
+     * @return square of the L<sub>2</sub> norm for the vector with the given components
+     * @see #norm(double, double, double)
+     */
+    public static double normSq(final double x1, final double x2, final double x3) {
+        return (x1 * x1) + (x2 * x2) + (x3 * x3);
+    }
+
+    /** Get the L<sub>&infin;</sub> norm for the vector with the given components. This is defined
+     * as the maximum of the absolute values of all vector components.
+     * @param x vector component
+     * @return L<sub>&infin;</sub> norm for the vector with the given components
+     * @see <a href="http://mathworld.wolfram.com/L-Infinity-Norm.html">L<sub>&infin;</sub> Norm</a>
+     */
+    public static double normInf(final double x) {
+        return Math.abs(x);
+    }
+
+    /** Get the L<sub>&infin;</sub> norm for the vector with the given components. This is defined
+     * as the maximum of the absolute values of all vector components.
+     * @param x1 first vector component
+     * @param x2 second vector component
+     * @return L<sub>&infin;</sub> norm for the vector with the given components
+     * @see <a href="http://mathworld.wolfram.com/L-Infinity-Norm.html">L<sub>&infin;</sub> Norm</a>
+     */
+    public static double normInf(final double x1, final double x2) {
+        return Math.max(Math.abs(x1), Math.abs(x2));
+    }
+
+    /** Get the L<sub>&infin;</sub> norm for the vector with the given components. This is defined
+     * as the maximum of the absolute values of all vector components.
+     * @param x1 first vector component
+     * @param x2 second vector component
+     * @param x3 third vector component
+     * @return L<sub>&infin;</sub> norm for the vector with the given components
+     * @see <a href="http://mathworld.wolfram.com/L-Infinity-Norm.html">L<sub>&infin;</sub> Norm</a>
+     */
+    public static double normInf(final double x1, final double x2, final double x3) {
+        return Math.max(Math.max(Math.abs(x1), Math.abs(x2)), Math.abs(x3));
+    }
+
+    /** Private constructor. */
+    private Vectors() {}
+}
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/util/package-info.java
similarity index 56%
copy from commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Geometry.java
copy to commons-geometry-core/src/main/java/org/apache/commons/geometry/core/util/package-info.java
index d74d312..fd6dea3 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/util/package-info.java
@@ -14,27 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.geometry.core;
-
-/** Class containing geometric constants.
+/**
+ *
+ * <p>
+ * This package contains geometry utility classes.
+ * </p>
  */
-public class Geometry {
-
-    /** Alias for {@link Math#PI}, placed here for completeness. */
-    public static final double PI = Math.PI;
-
-    /** Constant value for {@code 2*pi}.
-     */
-    public static final double TWO_PI = 2.0 * Math.PI;
-
-    /** Constant value for {@code pi / 2}.
-     */
-    public static final double HALF_PI = 0.5 * Math.PI;
-
-    /** Constant value for {@code - pi / 2}.
-     */
-    public static final double MINUS_HALF_PI = - 0.5 * Math.PI;
-
-    /** Private constructor */
-    private Geometry() {}
-}
+package org.apache.commons.geometry.core.util;
diff --git a/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/util/VectorsTest.java b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/util/VectorsTest.java
new file mode 100644
index 0000000..253192a
--- /dev/null
+++ b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/util/VectorsTest.java
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.geometry.core.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class VectorsTest {
+
+    private static final double EPS = Math.ulp(1d);
+
+    @Test
+    public void testNorm1_oneD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.norm1(0.0), EPS);
+
+        Assert.assertEquals(2.0, Vectors.norm1(-2.0), EPS);
+        Assert.assertEquals(1.0, Vectors.norm1(-1.0), EPS);
+
+        Assert.assertEquals(1.0, Vectors.norm1(1.0), EPS);
+        Assert.assertEquals(2.0, Vectors.norm1(2.0), EPS);
+    }
+
+    @Test
+    public void testNorm1_twoD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.norm1(0.0, 0.0), EPS);
+
+        Assert.assertEquals(3.0, Vectors.norm1(1.0, 2.0), EPS);
+        Assert.assertEquals(7.0, Vectors.norm1(3.0, -4.0), EPS);
+        Assert.assertEquals(11.0, Vectors.norm1(-5.0, 6.0), EPS);
+        Assert.assertEquals(16.0, Vectors.norm1(-7.0, -9.0), EPS);
+    }
+
+    @Test
+    public void testNorm1_threeD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.norm1(0.0, 0.0, 0.0), EPS);
+
+        Assert.assertEquals(6.0, Vectors.norm1(1.0, 2.0, 3.0), EPS);
+        Assert.assertEquals(15.0, Vectors.norm1(4.0, 5.0, -6.0), EPS);
+        Assert.assertEquals(24.0, Vectors.norm1(7.0, -8.0, 9.0), EPS);
+        Assert.assertEquals(33.0, Vectors.norm1(10.0, -11.0, -12.0), EPS);
+        Assert.assertEquals(42.0, Vectors.norm1(-13.0, 14.0, 15.0), EPS);
+        Assert.assertEquals(51.0, Vectors.norm1(-16.0, 17.0, -18.0), EPS);
+        Assert.assertEquals(60.0, Vectors.norm1(-19.0, -20.0, 21.0), EPS);
+        Assert.assertEquals(69.0, Vectors.norm1(-22.0, -23.0, -24.0), EPS);
+    }
+
+    @Test
+    public void testNorm_oneD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.norm(0.0), EPS);
+
+        Assert.assertEquals(2.0, Vectors.norm(-2.0), EPS);
+        Assert.assertEquals(1.0, Vectors.norm(-1.0), EPS);
+
+        Assert.assertEquals(1.0, Vectors.norm(1.0), EPS);
+        Assert.assertEquals(2.0, Vectors.norm(2.0), EPS);
+    }
+
+    @Test
+    public void testNorm_twoD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.norm(0.0, 0.0), EPS);
+
+        Assert.assertEquals(Math.sqrt(5.0), Vectors.norm(1.0, 2.0), EPS);
+        Assert.assertEquals(5.0, Vectors.norm(3.0, -4.0), EPS);
+        Assert.assertEquals(Math.sqrt(61.0), Vectors.norm(-5.0, 6.0), EPS);
+        Assert.assertEquals(Math.sqrt(130.0), Vectors.norm(-7.0, -9.0), EPS);
+    }
+
+    @Test
+    public void testNorm_threeD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.norm(0.0, 0.0, 0.0), EPS);
+
+        Assert.assertEquals(Math.sqrt(14.0), Vectors.norm(1.0, 2.0, 3.0), EPS);
+        Assert.assertEquals(Math.sqrt(77.0), Vectors.norm(4.0, 5.0, -6.0), EPS);
+        Assert.assertEquals(Math.sqrt(194.0), Vectors.norm(7.0, -8.0, 9.0), EPS);
+        Assert.assertEquals(Math.sqrt(365.0), Vectors.norm(10.0, -11.0, -12.0), EPS);
+        Assert.assertEquals(Math.sqrt(590.0), Vectors.norm(-13.0, 14.0, 15.0), EPS);
+        Assert.assertEquals(Math.sqrt(869.0), Vectors.norm(-16.0, 17.0, -18.0), EPS);
+        Assert.assertEquals(Math.sqrt(1202.0), Vectors.norm(-19.0, -20.0, 21.0), EPS);
+        Assert.assertEquals(Math.sqrt(1589.0), Vectors.norm(-22.0, -23.0, -24.0), EPS);
+    }
+
+    @Test
+    public void testNormSq_oneD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.normSq(0.0), EPS);
+
+        Assert.assertEquals(9.0, Vectors.normSq(-3.0), EPS);
+        Assert.assertEquals(1.0, Vectors.normSq(-1.0), EPS);
+
+        Assert.assertEquals(1.0, Vectors.normSq(1.0), EPS);
+        Assert.assertEquals(9.0, Vectors.normSq(3.0), EPS);
+    }
+
+    @Test
+    public void testNormSq_twoD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.normSq(0.0, 0.0), EPS);
+
+        Assert.assertEquals(5.0, Vectors.normSq(1.0, 2.0), EPS);
+        Assert.assertEquals(25.0, Vectors.normSq(3.0, -4.0), EPS);
+        Assert.assertEquals(61.0, Vectors.normSq(-5.0, 6.0), EPS);
+        Assert.assertEquals(130.0, Vectors.normSq(-7.0, -9.0), EPS);
+    }
+
+    @Test
+    public void testNormSq_threeD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.normSq(0.0, 0.0, 0.0), EPS);
+
+        Assert.assertEquals(14.0, Vectors.normSq(1.0, 2.0, 3.0), EPS);
+        Assert.assertEquals(77.0, Vectors.normSq(4.0, 5.0, -6.0), EPS);
+        Assert.assertEquals(194.0, Vectors.normSq(7.0, -8.0, 9.0), EPS);
+        Assert.assertEquals(365.0, Vectors.normSq(10.0, -11.0, -12.0), EPS);
+        Assert.assertEquals(590.0, Vectors.normSq(-13.0, 14.0, 15.0), EPS);
+        Assert.assertEquals(869.0, Vectors.normSq(-16.0, 17.0, -18.0), EPS);
+        Assert.assertEquals(1202.0, Vectors.normSq(-19.0, -20.0, 21.0), EPS);
+        Assert.assertEquals(1589.0, Vectors.normSq(-22.0, -23.0, -24.0), EPS);
+    }
+
+    @Test
+    public void testNormInf_oneD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.normInf(0.0), EPS);
+
+        Assert.assertEquals(2.0, Vectors.normInf(-2.0), EPS);
+        Assert.assertEquals(1.0, Vectors.normInf(-1.0), EPS);
+
+        Assert.assertEquals(1.0, Vectors.normInf(1.0), EPS);
+        Assert.assertEquals(2.0, Vectors.normInf(2.0), EPS);
+    }
+
+    @Test
+    public void testNormInf_twoD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.normInf(0.0, 0.0), EPS);
+
+        Assert.assertEquals(2.0, Vectors.normInf(2.0, 1.0), EPS);
+        Assert.assertEquals(4.0, Vectors.normInf(3.0, -4.0), EPS);
+        Assert.assertEquals(6.0, Vectors.normInf(-6.0, 5.0), EPS);
+        Assert.assertEquals(9.0, Vectors.normInf(-7.0, -9.0), EPS);
+    }
+
+    @Test
+    public void testNormInf_threeD() {
+        // act/assert
+        Assert.assertEquals(0.0, Vectors.normInf(0.0, 0.0, 0.0), EPS);
+
+        Assert.assertEquals(3.0, Vectors.normInf(1.0, 3.0, 2.0), EPS);
+        Assert.assertEquals(6.0, Vectors.normInf(6.0, 5.0, -4.0), EPS);
+        Assert.assertEquals(9.0, Vectors.normInf(7.0, -9.0, 8.0), EPS);
+        Assert.assertEquals(12.0, Vectors.normInf(10.0, -11.0, -12.0), EPS);
+        Assert.assertEquals(15.0, Vectors.normInf(-13.0, 14.0, 15.0), EPS);
+        Assert.assertEquals(18.0, Vectors.normInf(-16.0, 17.0, -18.0), EPS);
+        Assert.assertEquals(21.0, Vectors.normInf(-21.0, -19.0, 20.0), EPS);
+        Assert.assertEquals(24.0, Vectors.normInf(-22.0, -23.0, -24.0), EPS);
+    }
+}
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
index 0622c89..3d8874b 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
@@ -32,4 +32,27 @@ public interface EuclideanVector<P extends EuclideanPoint<P, V>, V extends Eucli
      * @return point with the same coordinates as this vector
      */
     P asPoint();
+
+    /** Returns the magnitude (i.e. length) of the vector. This is
+     * the same value as returned by {@link #getNorm()}.
+     * @return the magnitude, or length, of the vector
+     * @see #getNorm()
+     */
+    double getMagnitude();
+
+    /** Returns the squared magnitude of the vector. This is the
+     * same value as returned by {@link #getNormSq()}.
+     * @return the squared magnitude of the vector
+     * @see #getMagnitude()
+     * @see #getNormSq()
+     */
+    double getMagnitudeSq();
+
+    /** Returns a vector with the same direction but with the given
+     * magnitude. This is equivalent to calling {@code vec.normalize().scalarMultiply(mag)}
+     * but without the intermediate vector.
+     * @param magnitude The vector magnitude
+     * @return a vector with the same direction as the current instance but the given magnitude
+     */
+    V withMagnitude(double magnitude);
 }
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 1a915f6..11786a5 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
@@ -18,6 +18,7 @@ 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;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
@@ -80,29 +81,49 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public double getNorm1() {
-        return getNorm();
+        return Vectors.norm1(getX());
     }
 
     /** {@inheritDoc} */
     @Override
     public double getNorm() {
-        return Math.abs(getX());
+        return Vectors.norm(getX());
     }
 
     /** {@inheritDoc} */
     @Override
     public double getNormSq() {
-        return getX() * getX();
+        return Vectors.normSq(getX());
     }
 
     /** {@inheritDoc} */
     @Override
     public double getNormInf() {
+        return Vectors.normInf(getX());
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double getMagnitude() {
         return getNorm();
     }
 
     /** {@inheritDoc} */
     @Override
+    public double getMagnitudeSq() {
+        return getNormSq();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Vector1D withMagnitude(double magnitude) {
+        final double invNorm = 1.0 / nonZeroNorm();
+
+        return new Vector1D(magnitude * getX() * invNorm);
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public Vector1D add(Vector1D v) {
         return new Vector1D(getX() + v.getX());
     }
@@ -134,11 +155,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public Vector1D normalize() throws IllegalStateException {
-        double s = getNorm();
-        if (s == 0) {
-            throw new IllegalStateException("Norm is zero");
-        }
-        return scalarMultiply(1.0 / s);
+        return scalarMultiply(1.0 / nonZeroNorm());
     }
 
     /** {@inheritDoc} */
@@ -229,6 +246,19 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
         return false;
     }
 
+    /** Returns the vector norm, throwing an IllegalStateException if the norm is zero.
+     * @return the non-zero norm value
+     * @throws IllegalStateException if the norm is zero
+     */
+    private double nonZeroNorm() throws IllegalStateException {
+        final double n = getNorm();
+        if (n == 0) {
+            throw new IllegalStateException("Norm is zero");
+        }
+
+        return n;
+    }
+
     /** Returns a vector with the given coordinate value.
      * @param x vector coordinate
      * @return vector instance
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Cartesian3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Cartesian3D.java
index 6dbe753..4cb6ce0 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Cartesian3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Cartesian3D.java
@@ -101,17 +101,4 @@ public abstract class Cartesian3D implements Spatial, Serializable {
     public String toString() {
         return SimpleTupleFormat.getDefault().format(getX(), getY(), getZ());
     }
-
-    /** Returns the Euclidean distance from this set of coordinates to the given coordinates.
-     * @param other coordinates to compute the distance to.
-     * @return Euclidean distance value
-     */
-    protected double euclideanDistance(Cartesian3D other) {
-        // there are no cancellation problems here, so we use the straightforward formula
-        final double dx = x - other.x;
-        final double dy = y - other.y;
-        final double dz = z - other.z;
-
-        return Math.sqrt((dx * dx) + (dy * dy) + (dz * dz));
-    }
 }
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 7c2b3f7..39ed989 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
@@ -19,6 +19,7 @@ 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;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
@@ -75,7 +76,10 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D
     /** {@inheritDoc} */
     @Override
     public double distance(Point3D p) {
-        return euclideanDistance(p);
+        return Vectors.norm(
+                getX() - p.getX(),
+                getY() - p.getY(),
+                getZ() - p.getZ());
     }
 
     /** {@inheritDoc} */
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 459b014..41e47e8 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
@@ -18,6 +18,7 @@ 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.EuclideanVector;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
@@ -47,7 +48,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
     /** Opposite of the third canonical vector (coordinates: 0, 0, -1).  */
     public static final Vector3D MINUS_Z = new Vector3D(0, 0, -1);
 
- // CHECKSTYLE: stop ConstantName
+    // CHECKSTYLE: stop ConstantName
     /** A vector with all coordinates set to NaN. */
     public static final Vector3D NaN = new Vector3D(Double.NaN, Double.NaN, Double.NaN);
     // CHECKSTYLE: resume ConstantName
@@ -63,9 +64,6 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
     /** Serializable UID */
     private static final long serialVersionUID = 20180710L;
 
-    /** Error message when norms are zero. */
-    private static final String ZERO_NORM_MSG = "Norm is zero";
-
     /** Factory for delegating instance creation. */
     private static DoubleFunction3N<Vector3D> FACTORY = new DoubleFunction3N<Vector3D>() {
 
@@ -101,33 +99,49 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public double getNorm1() {
-        return Math.abs(getX()) + Math.abs(getY()) + Math.abs(getZ());
+        return Vectors.norm1(getX(), getY(), getZ());
     }
 
     /** {@inheritDoc} */
     @Override
     public double getNorm() {
-        // there are no cancellation problems here, so we use the straightforward formula
-        final double x = getX();
-        final double y = getY();
-        final double z = getZ();
-        return Math.sqrt ((x * x) + (y * y) + (z * z));
+        return Vectors.norm(getX(), getY(), getZ());
     }
 
     /** {@inheritDoc} */
     @Override
     public double getNormSq() {
-        // there are no cancellation problems here, so we use the straightforward formula
-        final double x = getX();
-        final double y = getY();
-        final double z = getZ();
-        return (x * x) + (y * y) + (z * z);
+        return Vectors.normSq(getX(), getY(), getZ());
     }
 
     /** {@inheritDoc} */
     @Override
     public double getNormInf() {
-        return Math.max(Math.max(Math.abs(getX()), Math.abs(getY())), Math.abs(getZ()));
+        return Vectors.normInf(getX(), getY(), getZ());
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double getMagnitude() {
+        return getNorm();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double getMagnitudeSq() {
+        return getNormSq();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Vector3D withMagnitude(double magnitude) {
+        final double invNorm = 1.0 / nonZeroNorm();
+
+        return new Vector3D(
+                    magnitude * getX() * invNorm,
+                    magnitude * getY() * invNorm,
+                    magnitude * getZ() * invNorm
+                );
     }
 
     /** Get the azimuth of the vector.
@@ -193,11 +207,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public Vector3D normalize() throws IllegalStateException {
-        double s = getNorm();
-        if (s == 0) {
-            throw new IllegalStateException(ZERO_NORM_MSG);
-        }
-        return scalarMultiply(1 / s);
+        return scalarMultiply(1 / nonZeroNorm());
     }
 
     /** Get a vector orthogonal to the instance.
@@ -216,10 +226,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      * @exception IllegalStateException if the norm of the instance is zero
      */
     public Vector3D orthogonal() throws IllegalStateException {
-        double threshold = 0.6 * getNorm();
-        if (threshold == 0) {
-            throw new IllegalStateException(ZERO_NORM_MSG);
-        }
+        double threshold = 0.6 * nonZeroNorm();
 
         final double x = getX();
         final double y = getY();
@@ -247,10 +254,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      * @exception IllegalStateException if either vector has a zero norm
      */
     public double angle(Vector3D v) throws IllegalStateException {
-        double normProduct = getNorm() * v.getNorm();
-        if (normProduct == 0) {
-            throw new IllegalStateException(ZERO_NORM_MSG);
-        }
+        double normProduct = nonZeroNorm() * v.nonZeroNorm();
 
         double dot = dotProduct(v);
         double threshold = normProduct * 0.9999;
@@ -286,37 +290,41 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public double distance1(Vector3D v) {
-        double dx = Math.abs(v.getX() - getX());
-        double dy = Math.abs(v.getY() - getY());
-        double dz = Math.abs(v.getZ() - getZ());
-
-        return dx + dy + dz;
+        return Vectors.norm1(
+                    getX() - v.getX(),
+                    getY() - v.getY(),
+                    getZ() - v.getZ()
+                );
     }
 
     /** {@inheritDoc} */
     @Override
     public double distance(Vector3D v) {
-        return euclideanDistance(v);
+        return Vectors.norm(
+                getX() - v.getX(),
+                getY() - v.getY(),
+                getZ() - v.getZ()
+            );
     }
 
     /** {@inheritDoc} */
     @Override
     public double distanceInf(Vector3D v) {
-        double dx = Math.abs(v.getX() - getX());
-        double dy = Math.abs(v.getY() - getY());
-        double dz = Math.abs(v.getZ() - getZ());
-
-        return Math.max(Math.max(dx, dy), dz);
+        return Vectors.normInf(
+                getX() - v.getX(),
+                getY() - v.getY(),
+                getZ() - v.getZ()
+            );
     }
 
     /** {@inheritDoc} */
     @Override
     public double distanceSq(Vector3D v) {
-        double dx = v.getX() - getX();
-        double dy = v.getY() - getY();
-        double dz = v.getZ() - getZ();
-
-        return (dx * dx) + (dy * dy) + (dz * dz);
+        return Vectors.normSq(
+                getX() - v.getX(),
+                getY() - v.getY(),
+                getZ() - v.getZ()
+            );
     }
 
     /** {@inheritDoc}
@@ -382,6 +390,19 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return false;
     }
 
+    /** Returns the vector norm, throwing an IllegalStateException if the norm is zero.
+     * @return the non-zero norm value
+     * @throws IllegalStateException if the norm is zero
+     */
+    private double nonZeroNorm() throws IllegalStateException {
+        final double n = getNorm();
+        if (n == 0) {
+            throw new IllegalStateException("Norm is zero");
+        }
+
+        return n;
+    }
+
     /** Computes the dot product between to vectors. This method simply
      * calls {@code v1.dotProduct(v2)}.
      * @param v1 first vector
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Cartesian2D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Cartesian2D.java
index 8d35fed..dfd375d 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Cartesian2D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Cartesian2D.java
@@ -90,14 +90,4 @@ public abstract class Cartesian2D implements Spatial, Serializable {
     public String toString() {
         return SimpleTupleFormat.getDefault().format(getX(), getY());
     }
-
-    /** Returns the Euclidean distance from this value to the given value.
-     * @param other the set of coordinates to compute the distance to
-     * @return Euclidean distance
-     */
-    protected double euclideanDistance(Cartesian2D other) {
-        double dx = x - other.x;
-        double dy = y - other.y;
-        return Math.sqrt((dx * dx) + (dy * dy));
-    }
 }
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 c9fde1f..cb213f2 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
@@ -18,6 +18,7 @@ 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;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
@@ -73,7 +74,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D
     /** {@inheritDoc} */
     @Override
     public double distance(Point2D p) {
-        return euclideanDistance(p);
+        return Vectors.norm(getX() - p.getX(), getY() - p.getY());
     }
 
     /** {@inheritDoc} */
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 4b435cc..819ba2b 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
@@ -18,6 +18,7 @@ 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.EuclideanVector;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
@@ -57,9 +58,6 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
     /** Serializable UID */
     private static final long serialVersionUID = 20180710L;
 
-    /** Error message when norms are zero. */
-    private static final String ZERO_NORM_MSG = "Norm is zero";
-
     /** Factory for delegating instance creation. */
     private static DoubleFunction2N<Vector2D> FACTORY = new DoubleFunction2N<Vector2D>() {
 
@@ -101,29 +99,48 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public double getNorm1() {
-        return Math.abs(getX()) + Math.abs(getY());
+        return Vectors.norm1(getX(), getY());
     }
 
     /** {@inheritDoc} */
     @Override
     public double getNorm() {
-        final double x = getX();
-        final double y = getY();
-        return Math.sqrt ((x * x) + (y * y));
+        return Vectors.norm(getX(), getY());
     }
 
     /** {@inheritDoc} */
     @Override
     public double getNormSq() {
-        final double x = getX();
-        final double y = getY();
-        return (x * x) + (y * y);
+        return Vectors.normSq(getX(), getY());
     }
 
     /** {@inheritDoc} */
     @Override
     public double getNormInf() {
-        return Math.max(Math.abs(getX()), Math.abs(getY()));
+        return Vectors.normInf(getX(), getY());
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double getMagnitude() {
+        return getNorm();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double getMagnitudeSq() {
+        return getNormSq();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Vector2D withMagnitude(double magnitude) {
+        final double invNorm = 1.0 / nonZeroNorm();
+
+        return new Vector2D(
+                    magnitude * getX() * invNorm,
+                    magnitude * getY() * invNorm
+                );
     }
 
     /** {@inheritDoc} */
@@ -159,11 +176,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public Vector2D normalize() throws IllegalStateException {
-        double n = getNorm();
-        if (n == 0) {
-            throw new IllegalStateException(ZERO_NORM_MSG);
-        }
-        return scalarMultiply(1 / n);
+        return scalarMultiply(1.0 / nonZeroNorm());
     }
 
     /** {@inheritDoc} */
@@ -175,31 +188,25 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public double distance1(Vector2D v) {
-        double dx = Math.abs(getX() - v.getX());
-        double dy = Math.abs(getY() - v.getY());
-        return dx + dy;
+        return Vectors.norm1(getX() - v.getX(), getY() - v.getY());
     }
 
     /** {@inheritDoc} */
     @Override
     public double distance(Vector2D v) {
-        return euclideanDistance(v);
+        return Vectors.norm(getX() - v.getX(), getY() - v.getY());
     }
 
     /** {@inheritDoc} */
     @Override
     public double distanceInf(Vector2D v) {
-        double dx = Math.abs(getX() - v.getX());
-        double dy = Math.abs(getY() - v.getY());
-        return Math.max(dx, dy);
+        return Vectors.normInf(getX() - v.getX(), getY() - v.getY());
     }
 
     /** {@inheritDoc} */
     @Override
     public double distanceSq(Vector2D v) {
-        double dx = getX() - v.getX();
-        double dy = getY() - v.getY();
-        return (dx * dx) + (dy * dy);
+        return Vectors.normSq(getX() - v.getX(), getY() - v.getY());
     }
 
     /** {@inheritDoc} */
@@ -218,13 +225,10 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
      *
      * @param v vector to compute the angle with
      * @return angular separation between this vector and v in radians
-     * @exception IllegalArgumentException if either vector has a zero norm
+     * @exception IllegalStateException if either vector has a zero norm
      */
     public double angle(Vector2D v) throws IllegalArgumentException {
-        double normProduct = getNorm() * v.getNorm();
-        if (normProduct == 0) {
-            throw new IllegalArgumentException(ZERO_NORM_MSG);
-        }
+        double normProduct = nonZeroNorm() * v.nonZeroNorm();
 
         double dot = dotProduct(v);
         double threshold = normProduct * 0.9999;
@@ -320,6 +324,19 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
         return false;
     }
 
+    /** Returns the vector norm, throwing an IllegalStateException if the norm is zero.
+     * @return the non-zero norm value
+     * @throws IllegalStateException if the norm is zero
+     */
+    private double nonZeroNorm() throws IllegalStateException {
+        final double n = getNorm();
+        if (n == 0) {
+            throw new IllegalStateException("Norm is zero");
+        }
+
+        return n;
+    }
+
     /** Computes the dot product between to vectors. This method simply
      * calls {@code v1.dotProduct(v2)}.
      * @param v1 first vector
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
index 15c864f..491b0c0 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
@@ -74,6 +74,40 @@ public class Vector1DTest {
     }
 
     @Test
+    public void testMagnitude() {
+        // act/assert
+        Assert.assertEquals(0.0, Vector1D.ZERO.getMagnitude(), TEST_TOLERANCE);
+        Assert.assertEquals(3.0, Vector1D.of(3).getMagnitude(), TEST_TOLERANCE);
+        Assert.assertEquals(3.0, Vector1D.of(-3).getMagnitude(), TEST_TOLERANCE);
+    }
+
+    @Test
+    public void testMagnitudeSq() {
+        // act/assert
+        Assert.assertEquals(0.0, Vector1D.of(0).getMagnitudeSq(), TEST_TOLERANCE);
+        Assert.assertEquals(9.0, Vector1D.of(3).getMagnitudeSq(), TEST_TOLERANCE);
+        Assert.assertEquals(9.0, Vector1D.of(-3).getMagnitudeSq(), TEST_TOLERANCE);
+    }
+
+    @Test
+    public void testWithMagnitude() {
+        // act/assert
+        checkVector(Vector1D.ONE.withMagnitude(0.0), 0.0);
+
+        checkVector(Vector1D.of(0.5).withMagnitude(2.0), 2.0);
+        checkVector(Vector1D.of(5).withMagnitude(3.0), 3.0);
+
+        checkVector(Vector1D.of(-0.5).withMagnitude(2.0), -2.0);
+        checkVector(Vector1D.of(-5).withMagnitude(3.0), -3.0);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testWithMagnitude_zeroNorm() {
+        // act/assert
+        Vector1D.ZERO.withMagnitude(1.0);
+    }
+
+    @Test
     public void testAdd() {
         // arrange
         Vector1D v1 = Vector1D.of(1);
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 c4017bd..1b029cb 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
@@ -87,7 +87,7 @@ public class Vector3DTest {
     @Test
     public void testNormSq() {
         // act/assert
-        Assert.assertEquals(0.0, Vector3D.ZERO.getNorm(), 0);
+        Assert.assertEquals(0.0, Vector3D.ZERO.getNormSq(), 0);
         Assert.assertEquals(29, Vector3D.of(2, 3, 4).getNormSq(), EPS);
         Assert.assertEquals(29, Vector3D.of(-2, -3, -4).getNormSq(), EPS);
     }
@@ -101,6 +101,55 @@ public class Vector3DTest {
     }
 
     @Test
+    public void testMagnitude() {
+        // act/assert
+        Assert.assertEquals(0.0, Vector3D.ZERO.getMagnitude(), 0);
+        Assert.assertEquals(Math.sqrt(29), Vector3D.of(2, 3, 4).getMagnitude(), EPS);
+        Assert.assertEquals(Math.sqrt(29), Vector3D.of(-2, -3, -4).getMagnitude(), EPS);
+    }
+
+    @Test
+    public void testMagnitudeSq() {
+        // act/assert
+        Assert.assertEquals(0.0, Vector3D.ZERO.getMagnitudeSq(), 0);
+        Assert.assertEquals(29, Vector3D.of(2, 3, 4).getMagnitudeSq(), EPS);
+        Assert.assertEquals(29, Vector3D.of(-2, -3, -4).getMagnitudeSq(), EPS);
+    }
+
+    @Test
+    public void testWithMagnitude() {
+        // arrange
+        double x = 2;
+        double y = 3;
+        double z = 4;
+
+        double len = Math.sqrt((x * x) + (y * y) + (z * z));
+
+        double normX = x / len;
+        double normY = y / len;
+        double normZ = z / len;
+
+        // act/assert
+        checkVector(Vector3D.of(x, y, z).withMagnitude(1.0), normX, normY, normZ);
+        checkVector(Vector3D.of(x, y, -z).withMagnitude(1.0), normX, normY, -normZ);
+        checkVector(Vector3D.of(x, -y, z).withMagnitude(1.0), normX, -normY, normZ);
+        checkVector(Vector3D.of(x, -y, -z).withMagnitude(1.0), normX, -normY, -normZ);
+        checkVector(Vector3D.of(-x, y, z).withMagnitude(1.0), -normX, normY, normZ);
+        checkVector(Vector3D.of(-x, y, -z).withMagnitude(1.0), -normX, normY, -normZ);
+        checkVector(Vector3D.of(-x, -y, z).withMagnitude(1.0), -normX, -normY, normZ);
+        checkVector(Vector3D.of(-x, -y, -z).withMagnitude(1.0), -normX, -normY, -normZ);
+
+        checkVector(Vector3D.of(x, y, z).withMagnitude(0.5), 0.5 * normX, 0.5 * normY, 0.5 * normZ);
+        checkVector(Vector3D.of(x, y, z).withMagnitude(3), 3 * normX, 3 * normY, 3 * normZ);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testWithMagnitude_zeroNorm() {
+        // act/assert
+        Vector3D.ZERO.withMagnitude(1.0);
+    }
+
+    @Test
     public void testAdd() {
         // arrange
         Vector3D v1 = Vector3D.of(1, 2, 3);
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 83d56a1..58f1ee5 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
@@ -104,6 +104,51 @@ public class Vector2DTest {
     }
 
     @Test
+    public void testMagnitude() {
+        // act/assert
+        Assert.assertEquals(0.0, Vector2D.of(0, 0).getMagnitude(), EPS);
+
+        Assert.assertEquals(5.0, Vector2D.of(3, 4).getMagnitude(), EPS);
+        Assert.assertEquals(5.0, Vector2D.of(3, -4).getMagnitude(), EPS);
+        Assert.assertEquals(5.0, Vector2D.of(-3, 4).getMagnitude(), EPS);
+        Assert.assertEquals(5.0, Vector2D.of(-3, -4).getMagnitude(), EPS);
+
+        Assert.assertEquals(Math.sqrt(5.0), Vector2D.of(-1, -2).getMagnitude(), EPS);
+    }
+
+    @Test
+    public void testMagnitudeSq() {
+        // act/assert
+        Assert.assertEquals(0.0, Vector2D.of(0, 0).getMagnitudeSq(), EPS);
+
+        Assert.assertEquals(25.0, Vector2D.of(3, 4).getMagnitudeSq(), EPS);
+        Assert.assertEquals(25.0, Vector2D.of(3, -4).getMagnitudeSq(), EPS);
+        Assert.assertEquals(25.0, Vector2D.of(-3, 4).getMagnitudeSq(), EPS);
+        Assert.assertEquals(25.0, Vector2D.of(-3, -4).getMagnitudeSq(), EPS);
+
+        Assert.assertEquals(5.0, Vector2D.of(-1, -2).getMagnitudeSq(), EPS);
+    }
+
+    @Test
+    public void testWithMagnitude() {
+        // act/assert
+        checkVector(Vector2D.of(3, 4).withMagnitude(1.0), 0.6, 0.8);
+        checkVector(Vector2D.of(4, 3).withMagnitude(1.0), 0.8, 0.6);
+
+        checkVector(Vector2D.of(-3, 4).withMagnitude(0.5), -0.3, 0.4);
+        checkVector(Vector2D.of(3, -4).withMagnitude(2.0), 1.2, -1.6);
+        checkVector(Vector2D.of(-3, -4).withMagnitude(3.0), -1.8, 3.0 * Math.sin(Math.atan2(-4, -3)));
+
+        checkVector(Vector2D.of(0.5, 0.5).withMagnitude(2), Math.sqrt(2), Math.sqrt(2));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testWithMagnitude_zeroNorm() {
+        // act/assert
+        Vector2D.ZERO.withMagnitude(1.0);
+    }
+
+    @Test
     public void testAdd() {
         // arrange
         Vector2D v1 = Vector2D.of(-1, 2);
@@ -353,7 +398,7 @@ public class Vector2DTest {
     }
 
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = IllegalStateException.class)
     public void testAngle_zeroNorm() {
         Vector2D.of(1, 1).angle(Vector2D.ZERO);
     }


[commons-geometry] 10/14: GEOMETRY-9, GEOMETRY-8: removing MultiDimensionalVector class since project, reject, and angle do not require more than one dimension to work mathematically; adding internal ZeroNormException class

Posted by er...@apache.org.
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 204b994e40ba3ce0a917a20a2a8cd41430ae98ec
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Mon Sep 3 15:04:28 2018 -0400

    GEOMETRY-9, GEOMETRY-8: removing MultiDimensionalVector class since project, reject, and angle do not require more than one dimension to work mathematically; adding internal ZeroNormException class
---
 .../geometry/core/MultiDimensionalVector.java      | 60 -------------
 .../org/apache/commons/geometry/core/Vector.java   | 35 ++++++++
 .../commons/geometry/euclidean/EuclideanPoint.java |  4 +-
 .../geometry/euclidean/EuclideanVector.java        |  4 +-
 .../euclidean/internal/ZeroNormException.java      | 50 +++++++++++
 .../geometry/euclidean/internal/package-info.java  | 25 ++++++
 .../commons/geometry/euclidean/oned/Vector1D.java  | 47 +++++++++--
 .../geometry/euclidean/threed/Rotation.java        |  2 +-
 .../geometry/euclidean/threed/Vector3D.java        |  8 +-
 .../commons/geometry/euclidean/twod/Vector2D.java  |  8 +-
 .../geometry/euclidean/oned/Vector1DTest.java      | 97 ++++++++++++++++++++++
 11 files changed, 264 insertions(+), 76 deletions(-)

diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java
deleted file mode 100644
index cf21b56..0000000
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/MultiDimensionalVector.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.geometry.core;
-
-/** Interface representing a vector in a vector space with two or more
- * dimensions.
- *
- * @param <V> Vector implementation type
- */
-public interface MultiDimensionalVector<V extends MultiDimensionalVector<V>> extends Vector<V> {
-
-    /** Get the projection of the instance onto the given base vector. The returned
-     * vector is parallel to {@code base}. Vector projection and rejection onto
-     * a given base are related by the equation
-     * <code>
-     *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
-     * </code>
-     * @param base base vector
-     * @return the vector projection of the instance onto {@code base}
-     * @exception IllegalStateException if the norm of the base vector is zero
-     * @see #reject(MultiDimensionalVector)
-     */
-    V project(V base) throws IllegalStateException;
-
-    /** Get the rejection of the instance from the given base vector. The returned
-     * vector is orthogonal to {@code base}. This operation can be interpreted as
-     * returning the orthogonal projection of the instance onto the hyperplane
-     * orthogonal to {@code base}. Vector projection and rejection onto
-     * a given base are related by the equation
-     * <code>
-     *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
-     * </code>
-     * @param base base vector
-     * @return the vector rejection of the instance from {@code base}
-     * @exception IllegalStateException if the norm of the base vector is zero
-     * @see #project(MultiDimensionalVector)
-     */
-    V reject(V base) throws IllegalStateException;
-
-    /** Compute the angular separation in radians between two vectors.
-     * @param v other vector
-     * @return angular separation between this instance and v in radians
-     * @exception IllegalStateException if either vector has a zero norm
-     */
-    double angle(V v) throws IllegalStateException;
-}
diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java
index 618757a..d4eb296 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java
@@ -171,4 +171,39 @@ public interface Vector<V extends Vector<V>> extends Spatial {
      * @return the dot product this &middot; v
      */
     double dotProduct(V v);
+
+    /** Get the projection of the instance onto the given base vector. The returned
+     * vector is parallel to {@code base}. Vector projection and rejection onto
+     * a given base are related by the equation
+     * <code>
+     *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
+     * </code>
+     * @param base base vector
+     * @return the vector projection of the instance onto {@code base}
+     * @exception IllegalStateException if the norm of the base vector is zero
+     * @see #reject(Vector)
+     */
+    V project(V base) throws IllegalStateException;
+
+    /** Get the rejection of the instance from the given base vector. The returned
+     * vector is orthogonal to {@code base}. This operation can be interpreted as
+     * returning the orthogonal projection of the instance onto the hyperplane
+     * orthogonal to {@code base}. Vector projection and rejection onto
+     * a given base are related by the equation
+     * <code>
+     *      <strong>v</strong> = <strong>v<sub>projection</sub></strong> + <strong>v<sub>rejection</sub></strong>
+     * </code>
+     * @param base base vector
+     * @return the vector rejection of the instance from {@code base}
+     * @exception IllegalStateException if the norm of the base vector is zero
+     * @see #project(Vector)
+     */
+    V reject(V base) throws IllegalStateException;
+
+    /** Compute the angular separation between two vectors in radians.
+     * @param v other vector
+     * @return angular separation between this instance and v in radians
+     * @exception IllegalStateException if either vector has a zero norm
+     */
+    double angle(V v) throws IllegalStateException;
 }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanPoint.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanPoint.java
index 4941306..bde9f67 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanPoint.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanPoint.java
@@ -45,9 +45,11 @@ public interface EuclideanPoint<P extends EuclideanPoint<P, V>, V extends Euclid
      * {@code P = (1 - t)*A + t*B}, where {@code A} is the current point and {@code B}
      * is the given point. This means that if {@code t = 0}, a point equal to the current
      * point will be returned. If {@code t = 1}, a point equal to the argument will be returned.
+     * The {@code t} parameter is not constrained to the range {@code [0, 1]}, meaning that
+     * linear extrapolation can also be performed with this method.
      * @param p other point
      * @param t interpolation parameter
-     * @return interpolated point
+     * @return interpolated or extrapolated point
      */
     P lerp(P p, double t);
 }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
index 8df3a91..ad4f21b 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
@@ -37,9 +37,11 @@ public interface EuclideanVector<P extends EuclideanPoint<P, V>, V extends Eucli
      * {@code V = (1 - t)*A + t*B}, where {@code A} is the current vector and {@code B}
      * is the given vector. This means that if {@code t = 0}, a vector equal to the current
      * vector will be returned. If {@code t = 1}, a vector equal to the argument will be returned.
+     * The {@code t} parameter is not constrained to the range {@code [0, 1]}, meaning that
+     * linear extrapolation can also be performed with this method.
      * @param v other vector
      * @param t interpolation parameter
-     * @return interpolated vector
+     * @return interpolated or extrapolated vector
      */
     V lerp(V v, double t);
 }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/ZeroNormException.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/ZeroNormException.java
new file mode 100644
index 0000000..fe9ecf1
--- /dev/null
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/ZeroNormException.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.geometry.euclidean.internal;
+
+/** Internal exception class with constants for frequently used messages.
+ * This exception is thrown when vector operations requiring a non-zero
+ * vector norm are attempted with a vector with a zero norm.
+ */
+public class ZeroNormException extends IllegalStateException {
+
+    /** Default zero-norm error message. */
+    public static final String ZERO_NORM_MSG = "Norm is zero";
+
+    /** Error message for cases where code is attempting to use a zero-norm vector
+     * as a base vector.
+     */
+    public static final String INVALID_BASE = "Invalid base vector: norm is zero";
+
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = 20180903L;
+
+    /**
+     * Simple constructor, using the default error message.
+     */
+    public ZeroNormException() {
+        this(ZERO_NORM_MSG);
+    }
+
+    /**
+     * Constructs an instance with the given error message.
+     * @param msg error message
+     */
+    public ZeroNormException(String msg) {
+        super(msg);
+    }
+}
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/package-info.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/package-info.java
new file mode 100644
index 0000000..e70a48b
--- /dev/null
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ *
+ * <p>
+ * This package contains Euclidean geometry utilities and classes intended
+ * for internal use only. No guarantees are made for the stability of the
+ * contained APIs.
+ * </p>
+ */
+package org.apache.commons.geometry.euclidean.internal;
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 be97a91..68fec66 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,9 +16,11 @@
  */
 package org.apache.commons.geometry.euclidean.oned;
 
+import org.apache.commons.geometry.core.Geometry;
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
 import org.apache.commons.geometry.core.util.Vectors;
 import org.apache.commons.geometry.euclidean.EuclideanVector;
+import org.apache.commons.geometry.euclidean.internal.ZeroNormException;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
 /** This class represents a vector in one-dimensional Euclidean space.
@@ -51,9 +53,6 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
     /** Serializable UID. */
     private static final long serialVersionUID = 20180710L;
 
-    /** Error message when a norm is zero. */
-    private static final String ZERO_NORM_MSG = "Norm is zero";
-
     /** Simple constructor.
      * @param x abscissa (coordinate value)
      */
@@ -125,7 +124,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
         else if (x < 0.0) {
             return new Vector1D(-magnitude);
         }
-        throw new IllegalStateException(ZERO_NORM_MSG);
+        throw new ZeroNormException();
     }
 
     /** {@inheritDoc} */
@@ -168,7 +167,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
         else if (x < 0.0) {
             return MINUS_ONE;
         }
-        throw new IllegalStateException(ZERO_NORM_MSG);
+        throw new ZeroNormException();
     }
 
     /** {@inheritDoc} */
@@ -207,6 +206,44 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
         return getX() * v.getX();
     }
 
+    /** {@inheritDoc}
+     * <p>For the one-dimensional case, this method simply returns the current instance.</p>
+     */
+    @Override
+    public Vector1D project(final Vector1D base) throws IllegalStateException {
+        if (base.getX() == 0) {
+            throw new ZeroNormException(ZeroNormException.INVALID_BASE);
+        }
+        return this;
+    }
+
+    /** {@inheritDoc}
+     * <p>For the one-dimensional case, this method simply returns the zero vector.</p>
+     */
+    @Override
+    public Vector1D reject(final Vector1D base) throws IllegalStateException {
+        if (base.getX() == 0) {
+            throw new ZeroNormException(ZeroNormException.INVALID_BASE);
+        }
+        return Vector1D.ZERO;
+    }
+
+    /** {@inheritDoc}
+     * <p>For the one-dimensional case, this method returns 0 if the vector x values have
+     * the same sign and {@code pi} if they are opposite.</p>
+     */
+    @Override
+    public double angle(final Vector1D v) throws IllegalStateException {
+        final double sig1 = Math.signum(getX());
+        final double sig2 = Math.signum(v.getX());
+
+        if (sig1 == 0 || sig2 == 0) {
+            throw new ZeroNormException();
+        }
+        // the angle is 0 if the x value signs are the same and pi if not
+        return (sig1 == sig2) ? 0.0 : Geometry.PI;
+    }
+
     /**
      * Get a hashCode for the vector.
      * <p>All NaN values have the same hash code.</p>
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Rotation.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Rotation.java
index a24129c..272d5c0 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Rotation.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Rotation.java
@@ -94,7 +94,7 @@ public class Rotation implements Serializable {
   public static final Rotation IDENTITY = new Rotation(1.0, 0.0, 0.0, 0.0, false);
 
   /** Serializable version identifier */
-  private static final long serialVersionUID = -2153622329907944313L;
+  private static final long serialVersionUID = 20180903L;
 
   /** Error message for Cardan angle singularities */
   private static final String CARDAN_SINGULARITY_MSG = "Cardan angles singularity";
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 640f232..2a1a5f7 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
@@ -16,16 +16,16 @@
  */
 package org.apache.commons.geometry.euclidean.threed;
 
-import org.apache.commons.geometry.core.MultiDimensionalVector;
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
 import org.apache.commons.geometry.core.util.Vectors;
 import org.apache.commons.geometry.euclidean.EuclideanVector;
+import org.apache.commons.geometry.euclidean.internal.ZeroNormException;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
 /** This class represents a vector in three-dimensional Euclidean space.
  * Instances of this class are guaranteed to be immutable.
  */
-public final class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Vector3D>, MultiDimensionalVector<Vector3D> {
+public final class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Vector3D> {
 
     /** Zero (null) vector (coordinates: 0, 0, 0). */
     public static final Vector3D ZERO   = new Vector3D(0, 0, 0);
@@ -389,7 +389,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
     private double getNonZeroNorm() throws IllegalStateException {
         final double n = getNorm();
         if (n == 0) {
-            throw new IllegalStateException("Norm is zero");
+            throw new ZeroNormException();
         }
 
         return n;
@@ -411,7 +411,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
 
         final double baseMagSq = base.getNormSq();
         if (baseMagSq == 0.0) {
-            throw new IllegalStateException("Invalid base vector: norm is zero");
+            throw new ZeroNormException(ZeroNormException.INVALID_BASE);
         }
 
         final double scale = aDotB / baseMagSq;
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 c94b52d..60877cb 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
@@ -16,16 +16,16 @@
  */
 package org.apache.commons.geometry.euclidean.twod;
 
-import org.apache.commons.geometry.core.MultiDimensionalVector;
 import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
 import org.apache.commons.geometry.core.util.Vectors;
 import org.apache.commons.geometry.euclidean.EuclideanVector;
+import org.apache.commons.geometry.euclidean.internal.ZeroNormException;
 import org.apache.commons.numbers.arrays.LinearCombination;
 
 /** This class represents a vector in two-dimensional Euclidean space.
  * Instances of this class are guaranteed to be immutable.
  */
-public final class Vector2D extends Cartesian2D implements EuclideanVector<Point2D, Vector2D>, MultiDimensionalVector<Vector2D> {
+public final class Vector2D extends Cartesian2D implements EuclideanVector<Point2D, Vector2D> {
 
     /** Zero vector (coordinates: 0, 0). */
     public static final Vector2D ZERO   = new Vector2D(0, 0);
@@ -335,7 +335,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
     private double getNonZeroNorm() throws IllegalStateException {
         final double n = getNorm();
         if (n == 0) {
-            throw new IllegalStateException("Norm is zero");
+            throw new ZeroNormException();
         }
 
         return n;
@@ -357,7 +357,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
 
         final double baseMagSq = base.getNormSq();
         if (baseMagSq == 0.0) {
-            throw new IllegalStateException("Invalid base vector: norm is zero");
+            throw new ZeroNormException(ZeroNormException.INVALID_BASE);
         }
 
         final double scale = aDotB / baseMagSq;
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
index 14b40b7..20396fe 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
@@ -18,6 +18,7 @@ package org.apache.commons.geometry.euclidean.oned;
 
 import java.util.regex.Pattern;
 
+import org.apache.commons.geometry.core.Geometry;
 import org.apache.commons.numbers.core.Precision;
 import org.junit.Assert;
 import org.junit.Test;
@@ -292,6 +293,102 @@ public class Vector1DTest {
     }
 
     @Test
+    public void testProject() {
+        // arrange
+        Vector1D v1 = Vector1D.of(2);
+        Vector1D v2 = Vector1D.of(-3);
+        Vector1D v3 = Vector1D.of(4);
+
+        // act/assert
+        checkVector(Vector1D.ZERO.project(v1), 0);
+        checkVector(Vector1D.ZERO.project(v2), 0);
+        checkVector(Vector1D.ZERO.project(v3), 0);
+
+        checkVector(v1.project(v1), 2);
+        checkVector(v1.project(v2), 2);
+        checkVector(v1.project(v3), 2);
+
+        checkVector(v2.project(v1), -3);
+        checkVector(v2.project(v2), -3);
+        checkVector(v2.project(v3), -3);
+
+        checkVector(v3.project(v1), 4);
+        checkVector(v3.project(v2), 4);
+        checkVector(v3.project(v3), 4);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testProject_baseHasZeroNorm() {
+        // act/assert
+        Vector1D.of(2.0).project(Vector1D.ZERO);
+    }
+
+    @Test
+    public void testReject() {
+        // arrange
+        Vector1D v1 = Vector1D.of(2);
+        Vector1D v2 = Vector1D.of(-3);
+
+        // act/assert
+        checkVector(Vector1D.ZERO.reject(v1), 0);
+        checkVector(Vector1D.ZERO.reject(v2), 0);
+
+        checkVector(v1.reject(v1), 0);
+        checkVector(v1.reject(v2), 0);
+
+        checkVector(v2.reject(v1), 0);
+        checkVector(v2.reject(v2), 0);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testReject_baseHasZeroNorm() {
+        // act/assert
+        Vector1D.of(2.0).reject(Vector1D.ZERO);
+    }
+
+    @Test
+    public void testAngle() {
+        // arrange
+        Vector1D v1 = Vector1D.of(2);
+        Vector1D v2 = Vector1D.of(-3);
+        Vector1D v3 = Vector1D.of(4);
+        Vector1D v4 = Vector1D.of(-5);
+
+        // act/assert
+        Assert.assertEquals(0.0, v1.angle(v1), TEST_TOLERANCE);
+        Assert.assertEquals(Geometry.PI, v1.angle(v2), TEST_TOLERANCE);
+        Assert.assertEquals(0.0, v1.angle(v3), TEST_TOLERANCE);
+        Assert.assertEquals(Geometry.PI, v1.angle(v4), TEST_TOLERANCE);
+
+        Assert.assertEquals(Geometry.PI, v2.angle(v1), TEST_TOLERANCE);
+        Assert.assertEquals(0.0, v2.angle(v2), TEST_TOLERANCE);
+        Assert.assertEquals(Geometry.PI, v2.angle(v3), TEST_TOLERANCE);
+        Assert.assertEquals(0.0, v2.angle(v4), TEST_TOLERANCE);
+
+        Assert.assertEquals(0.0, v3.angle(v1), TEST_TOLERANCE);
+        Assert.assertEquals(Geometry.PI, v3.angle(v2), TEST_TOLERANCE);
+        Assert.assertEquals(0.0, v3.angle(v3), TEST_TOLERANCE);
+        Assert.assertEquals(Geometry.PI, v3.angle(v4), TEST_TOLERANCE);
+
+        Assert.assertEquals(Geometry.PI, v4.angle(v1), TEST_TOLERANCE);
+        Assert.assertEquals(0.0, v4.angle(v2), TEST_TOLERANCE);
+        Assert.assertEquals(Geometry.PI, v4.angle(v3), TEST_TOLERANCE);
+        Assert.assertEquals(0.0, v4.angle(v4), TEST_TOLERANCE);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testAngle_firstVectorZero() {
+        // act/assert
+        Vector1D.ZERO.angle(Vector1D.of(1.0));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testAngle_secondVectorZero() {
+        // act/assert
+        Vector1D.of(1.0).angle(Vector1D.ZERO);
+    }
+
+    @Test
     public void testLerp() {
         // arrange
         Vector1D v1 = Vector1D.of(1);


[commons-geometry] 09/14: 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

Posted by er...@apache.org.
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 <ma...@hotmail.com>
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);


[commons-geometry] 04/14: GEOMETRY-9: moving magnitude methods to main Vector interface; simplifying 1D magnitude/normalize methods

Posted by er...@apache.org.
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 03e4ff45785d9a2ec9e6982a5da99c5dcf3411c2
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Sun Jul 29 15:10:22 2018 -0400

    GEOMETRY-9: moving magnitude methods to main Vector interface; simplifying 1D magnitude/normalize methods
---
 .../org/apache/commons/geometry/core/Vector.java   | 23 +++++++++++
 .../geometry/euclidean/EuclideanVector.java        | 23 -----------
 .../commons/geometry/euclidean/oned/Point1D.java   |  3 ++
 .../commons/geometry/euclidean/oned/Vector1D.java  | 48 ++++++++++++----------
 .../geometry/euclidean/threed/Vector3D.java        | 10 ++---
 .../commons/geometry/euclidean/twod/Vector2D.java  |  8 ++--
 .../geometry/euclidean/oned/Point1DTest.java       |  1 +
 .../geometry/euclidean/oned/Vector1DTest.java      |  1 +
 8 files changed, 63 insertions(+), 54 deletions(-)

diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java
index 03bda8f..618757a 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java
@@ -63,6 +63,29 @@ public interface Vector<V extends Vector<V>> extends Spatial {
      */
     double getNormInf();
 
+    /** Returns the magnitude (i.e. length) of the vector. This is
+     * the same value as returned by {@link #getNorm()}.
+     * @return the magnitude, or length, of the vector
+     * @see #getNorm()
+     */
+    double getMagnitude();
+
+    /** Returns the squared magnitude of the vector. This is the
+     * same value as returned by {@link #getNormSq()}.
+     * @return the squared magnitude of the vector
+     * @see #getMagnitude()
+     * @see #getNormSq()
+     */
+    double getMagnitudeSq();
+
+    /** Returns a vector with the same direction but with the given
+     * magnitude. This is equivalent to calling {@code vec.normalize().scalarMultiply(mag)}
+     * but without the intermediate vector.
+     * @param magnitude The vector magnitude
+     * @return a vector with the same direction as the current instance but the given magnitude
+     */
+    V withMagnitude(double magnitude);
+
     /** Add a vector to the instance.
      * @param v vector to add
      * @return a new vector
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
index 3d8874b..0622c89 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/EuclideanVector.java
@@ -32,27 +32,4 @@ public interface EuclideanVector<P extends EuclideanPoint<P, V>, V extends Eucli
      * @return point with the same coordinates as this vector
      */
     P asPoint();
-
-    /** Returns the magnitude (i.e. length) of the vector. This is
-     * the same value as returned by {@link #getNorm()}.
-     * @return the magnitude, or length, of the vector
-     * @see #getNorm()
-     */
-    double getMagnitude();
-
-    /** Returns the squared magnitude of the vector. This is the
-     * same value as returned by {@link #getNormSq()}.
-     * @return the squared magnitude of the vector
-     * @see #getMagnitude()
-     * @see #getNormSq()
-     */
-    double getMagnitudeSq();
-
-    /** Returns a vector with the same direction but with the given
-     * magnitude. This is equivalent to calling {@code vec.normalize().scalarMultiply(mag)}
-     * but without the intermediate vector.
-     * @param magnitude The vector magnitude
-     * @return a vector with the same direction as the current instance but the given magnitude
-     */
-    V withMagnitude(double magnitude);
 }
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 1e6603e..af324c1 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
@@ -32,6 +32,9 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D
     /** Unit (coordinates: 1). */
     public static final Point1D ONE  = new Point1D(1.0);
 
+    /** Negative unit (coordinates: 1). */
+    public static final Point1D MINUS_ONE  = new Point1D(-1.0);
+
     // CHECKSTYLE: stop ConstantName
     /** A vector with all coordinates set to NaN. */
     public static final Point1D NaN = new Point1D(Double.NaN);
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 8ed1194..207f949 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
@@ -33,6 +33,9 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
     /** Unit vector (coordinates: 1). */
     public static final Vector1D ONE  = new Vector1D(1.0);
 
+    /** Negation of unit vector (coordinates: -1). */
+    public static final Vector1D MINUS_ONE = new Vector1D(-1.0);
+
     // CHECKSTYLE: stop ConstantName
     /** A vector with all coordinates set to NaN. */
     public static final Vector1D NaN = new Vector1D(Double.NaN);
@@ -49,6 +52,9 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
     /** Serializable UID. */
     private static final long serialVersionUID = 20180710L;
 
+    /** 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>() {
 
@@ -117,9 +123,14 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public Vector1D withMagnitude(double magnitude) {
-        final double invNorm = 1.0 / nonZeroNorm();
-
-        return new Vector1D(magnitude * getX() * invNorm);
+        final double x = getX();
+        if (x > 0.0) {
+            return new Vector1D(magnitude);
+        }
+        else if (x < 0.0) {
+            return new Vector1D(-magnitude);
+        }
+        throw new IllegalStateException(ZERO_NORM_MSG);
     }
 
     /** {@inheritDoc} */
@@ -155,7 +166,14 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public Vector1D normalize() throws IllegalStateException {
-        return scalarMultiply(1.0 / nonZeroNorm());
+        final double x = getX();
+        if (x > 0.0) {
+            return ONE;
+        }
+        else if (x < 0.0) {
+            return MINUS_ONE;
+        }
+        throw new IllegalStateException(ZERO_NORM_MSG);
     }
 
     /** {@inheritDoc} */
@@ -167,26 +185,25 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public double distance1(Vector1D v) {
-        return distance(v);
+        return Vectors.norm1(getX() - v.getX());
     }
 
     /** {@inheritDoc} */
     @Override
     public double distance(Vector1D v) {
-        return Math.abs(v.getX() - getX());
+        return Vectors.norm(getX() - v.getX());
     }
 
     /** {@inheritDoc} */
     @Override
     public double distanceInf(Vector1D v) {
-        return distance(v);
+        return Vectors.normInf(getX() - v.getX());
     }
 
     /** {@inheritDoc} */
     @Override
     public double distanceSq(Vector1D v) {
-        final double dx = v.getX() - getX();
-        return dx * dx;
+        return Vectors.normSq(getX() - v.getX());
     }
 
     /** {@inheritDoc} */
@@ -246,19 +263,6 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
         return false;
     }
 
-    /** Returns the vector norm, throwing an IllegalStateException if the norm is zero.
-     * @return the non-zero norm value
-     * @throws IllegalStateException if the norm is zero
-     */
-    private double nonZeroNorm() throws IllegalStateException {
-        final double n = getNorm();
-        if (n == 0) {
-            throw new IllegalStateException("Norm is zero");
-        }
-
-        return n;
-    }
-
     /** Returns a vector with the given coordinate value.
      * @param x vector coordinate
      * @return vector instance
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 50fee39..cac3b23 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
@@ -135,7 +135,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public Vector3D withMagnitude(double magnitude) {
-        final double invNorm = 1.0 / nonZeroNorm();
+        final double invNorm = 1.0 / getNonZeroNorm();
 
         return new Vector3D(
                     magnitude * getX() * invNorm,
@@ -193,7 +193,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public Vector3D normalize() throws IllegalStateException {
-        return scalarMultiply(1 / nonZeroNorm());
+        return scalarMultiply(1.0 / getNonZeroNorm());
     }
 
     /** Get a vector orthogonal to the instance.
@@ -212,7 +212,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      * @exception IllegalStateException if the norm of the instance is zero
      */
     public Vector3D orthogonal() throws IllegalStateException {
-        double threshold = 0.6 * nonZeroNorm();
+        double threshold = 0.6 * getNonZeroNorm();
 
         final double x = getX();
         final double y = getY();
@@ -240,7 +240,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      * @exception IllegalStateException if either vector has a zero norm
      */
     public double angle(Vector3D v) throws IllegalStateException {
-        double normProduct = nonZeroNorm() * v.nonZeroNorm();
+        double normProduct = getNonZeroNorm() * v.getNonZeroNorm();
 
         double dot = dotProduct(v);
         double threshold = normProduct * 0.9999;
@@ -380,7 +380,7 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
      * @return the non-zero norm value
      * @throws IllegalStateException if the norm is zero
      */
-    private double nonZeroNorm() throws IllegalStateException {
+    private double getNonZeroNorm() throws IllegalStateException {
         final double n = getNorm();
         if (n == 0) {
             throw new IllegalStateException("Norm is zero");
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 a81dcd7..52a16f3 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
@@ -135,7 +135,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public Vector2D withMagnitude(double magnitude) {
-        final double invNorm = 1.0 / nonZeroNorm();
+        final double invNorm = 1.0 / getNonZeroNorm();
 
         return new Vector2D(
                     magnitude * getX() * invNorm,
@@ -176,7 +176,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
     /** {@inheritDoc} */
     @Override
     public Vector2D normalize() throws IllegalStateException {
-        return scalarMultiply(1.0 / nonZeroNorm());
+        return scalarMultiply(1.0 / getNonZeroNorm());
     }
 
     /** {@inheritDoc} */
@@ -228,7 +228,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
      * @exception IllegalStateException if either vector has a zero norm
      */
     public double angle(Vector2D v) throws IllegalArgumentException {
-        double normProduct = nonZeroNorm() * v.nonZeroNorm();
+        double normProduct = getNonZeroNorm() * v.getNonZeroNorm();
 
         double dot = dotProduct(v);
         double threshold = normProduct * 0.9999;
@@ -328,7 +328,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
      * @return the non-zero norm value
      * @throws IllegalStateException if the norm is zero
      */
-    private double nonZeroNorm() throws IllegalStateException {
+    private double getNonZeroNorm() throws IllegalStateException {
         final double n = getNorm();
         if (n == 0) {
             throw new IllegalStateException("Norm is zero");
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 4b65983..8233d1c 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
@@ -32,6 +32,7 @@ public class Point1DTest {
         // act/assert
         checkPoint(Point1D.ZERO, 0.0);
         checkPoint(Point1D.ONE, 1.0);
+        checkPoint(Point1D.MINUS_ONE, -1.0);
         checkPoint(Point1D.NaN, Double.NaN);
         checkPoint(Point1D.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
         checkPoint(Point1D.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
index cce8abe..2ac2cc7 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
@@ -31,6 +31,7 @@ public class Vector1DTest {
         // act/assert
         checkVector(Vector1D.ZERO, 0.0);
         checkVector(Vector1D.ONE, 1.0);
+        checkVector(Vector1D.MINUS_ONE, -1.0);
         checkVector(Vector1D.NaN, Double.NaN);
         checkVector(Vector1D.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
         checkVector(Vector1D.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);


[commons-geometry] 02/14: merging with master

Posted by er...@apache.org.
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 40a40bc73c32815479f191b75ae0c8f954408d31
Merge: b329f9b d7b4a10
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Sun Jul 22 14:26:28 2018 -0400

    merging with master

 .../org/apache/commons/geometry/core/Geometry.java |  18 +-
 .../apache/commons/geometry/core/GeometryTest.java |  66 ++++
 .../geometry/euclidean/threed/Cartesian3D.java     |   7 +
 .../commons/geometry/euclidean/threed/Point3D.java |  21 +-
 .../euclidean/threed/SphericalCoordinates.java     | 312 ++++++++++++++++
 .../geometry/euclidean/threed/Vector3D.java        |  46 +--
 .../geometry/euclidean/twod/Cartesian2D.java       |   7 +
 .../commons/geometry/euclidean/twod/Point2D.java   |  19 +-
 .../geometry/euclidean/twod/PolarCoordinates.java  | 262 ++++++++++++++
 .../commons/geometry/euclidean/twod/Vector2D.java  |  19 +-
 .../geometry/euclidean/oned/Vector1DTest.java      |  16 +
 .../geometry/euclidean/threed/Cartesian3DTest.java |  45 +++
 .../geometry/euclidean/threed/Point3DTest.java     |  24 +-
 .../euclidean/threed/SphericalCoordinatesTest.java | 399 +++++++++++++++++++++
 .../geometry/euclidean/threed/Vector3DTest.java    |  58 ++-
 .../geometry/euclidean/twod/Cartesian2DTest.java   |  50 ++-
 .../geometry/euclidean/twod/Point2DTest.java       |  31 +-
 .../euclidean/twod/PolarCoordinatesTest.java       | 362 +++++++++++++++++++
 .../geometry/euclidean/twod/Vector2DTest.java      |  47 ++-
 .../geometry/spherical/SphericalCoordinates.java   | 394 --------------------
 .../commons/geometry/spherical/oned/ArcsSet.java   |   4 +-
 .../geometry/spherical/oned/LimitAngle.java        |   2 +-
 .../commons/geometry/spherical/oned/S1Point.java   |  54 ++-
 .../commons/geometry/spherical/package-info.java   |  23 --
 .../commons/geometry/spherical/twod/Circle.java    |   2 +-
 .../commons/geometry/spherical/twod/S2Point.java   | 113 +++---
 .../spherical/SphericalCoordinatesTest.java        |  83 -----
 .../geometry/spherical/SphericalTestUtils.java     |   2 +-
 .../geometry/spherical/oned/LimitAngleTest.java    |   2 +-
 .../geometry/spherical/oned/S1PointTest.java       |   4 +-
 .../geometry/spherical/twod/CircleTest.java        |  10 +-
 .../geometry/spherical/twod/S2PointTest.java       |  20 +-
 .../spherical/twod/SphericalPolygonsSetTest.java   |   4 +-
 33 files changed, 1799 insertions(+), 727 deletions(-)

diff --cc commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
index 41e47e8,078a5d3..f290fdd
--- 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
@@@ -74,6 -70,12 +71,9 @@@ public final class Vector3D extends Car
          }
      };
  
+     /** Serializable UID */
+     private static final long serialVersionUID = 20180710L;
+ 
 -    /** Error message when norms are zero. */
 -    private static final String ZERO_NORM_MSG = "Norm is zero";
 -
      /** Simple constructor.
       * Build a vector from its coordinates
       * @param x abscissa
@@@ -117,47 -127,9 +117,33 @@@
      /** {@inheritDoc} */
      @Override
      public double getNormInf() {
 -        return Math.max(Math.max(Math.abs(getX()), Math.abs(getY())), Math.abs(getZ()));
 +        return Vectors.normInf(getX(), getY(), getZ());
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override
 +    public double getMagnitude() {
 +        return getNorm();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override
 +    public double getMagnitudeSq() {
 +        return getNormSq();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override
 +    public Vector3D withMagnitude(double magnitude) {
 +        final double invNorm = 1.0 / nonZeroNorm();
 +
 +        return new Vector3D(
 +                    magnitude * getX() * invNorm,
 +                    magnitude * getY() * invNorm,
 +                    magnitude * getZ() * invNorm
 +                );
      }
  
-     /** Get the azimuth of the vector.
-      * @return azimuth (&alpha;) of the vector, between -&pi; and +&pi;
-      */
-     public double getAlpha() {
-         return Math.atan2(getY(), getX());
-     }
- 
-     /** Get the elevation of the vector.
-      * @return elevation (&delta;) of the vector, between -&pi;/2 and +&pi;/2
-      */
-     public double getDelta() {
-         return Math.asin(getZ() / getNorm());
-     }
- 
      /** {@inheritDoc} */
      @Override
      public Vector3D add(Vector3D v) {
diff --cc commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java
index 819ba2b,36c300e..3d6fa79
--- 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
@@@ -68,6 -64,12 +65,9 @@@ public final class Vector2D extends Car
          }
      };
  
+     /** Serializable UID */
+     private static final long serialVersionUID = 20180710L;
+ 
 -    /** Error message when norms are zero. */
 -    private static final String ZERO_NORM_MSG = "Norm is zero";
 -
      /** Simple constructor.
       * @param x abscissa (first coordinate)
       * @param y ordinate (second coordinate)


[commons-geometry] 06/14: GEOMETRY-9: adding static project and reject methods

Posted by er...@apache.org.
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 2f44549329dd91bc08438766cc426ba42741a9a6
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Sun Sep 2 22:36:54 2018 -0400

    GEOMETRY-9: adding static project and reject methods
---
 .../geometry/euclidean/threed/Vector3D.java        | 86 +++++++++++++--------
 .../commons/geometry/euclidean/twod/Vector2D.java  | 84 +++++++++++++--------
 .../geometry/euclidean/threed/Vector3DTest.java    | 88 ++++++++++++++++++++++
 .../geometry/euclidean/twod/Vector2DTest.java      | 54 +++++++++++++
 4 files changed, 249 insertions(+), 63 deletions(-)

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 62856a3..a84f3d7 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
@@ -337,38 +337,6 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return getComponent(base, true);
     }
 
-    /** Returns a component of the current instance relative to the given base
-     * vector. If {@code reject} is true, the vector rejection is returned; otherwise,
-     * the projection is returned.
-     * @param base The base vector
-     * @param reject If true, the rejection of this instance from {@code base} is
-     *      returned. If false, the projection of this instance onto {@code base}
-     *      is returned.
-     * @return The projection or rejection of this instance relative to {@code base},
-     *      depending on the value of {@code reject}.
-     * @throws IllegalStateException if {@code base} has a zero norm
-     */
-    private Vector3D getComponent(Vector3D base, boolean reject) throws IllegalStateException {
-        final double aDotB = dotProduct(base);
-
-        final double baseMagSq = base.getNormSq();
-        if (baseMagSq == 0.0) {
-            throw new IllegalStateException("Invalid base vector: norm is zero");
-        }
-
-        final double scale = aDotB / baseMagSq;
-
-        final double projX = scale * base.getX();
-        final double projY = scale * base.getY();
-        final double projZ = scale * base.getZ();
-
-        if (reject) {
-            return new Vector3D(getX() - projX, getY() - projY, getZ() - projZ);
-        }
-
-        return new Vector3D(projX, projY, projZ);
-    }
-
     /**
      * Get a hashCode for the vector.
      * <p>All NaN values have the same hash code.</p>
@@ -432,6 +400,38 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return n;
     }
 
+    /** Returns a component of the current instance relative to the given base
+     * vector. If {@code reject} is true, the vector rejection is returned; otherwise,
+     * the projection is returned.
+     * @param base The base vector
+     * @param reject If true, the rejection of this instance from {@code base} is
+     *      returned. If false, the projection of this instance onto {@code base}
+     *      is returned.
+     * @return The projection or rejection of this instance relative to {@code base},
+     *      depending on the value of {@code reject}.
+     * @throws IllegalStateException if {@code base} has a zero norm
+     */
+    private Vector3D getComponent(Vector3D base, boolean reject) throws IllegalStateException {
+        final double aDotB = dotProduct(base);
+
+        final double baseMagSq = base.getNormSq();
+        if (baseMagSq == 0.0) {
+            throw new IllegalStateException("Invalid base vector: norm is zero");
+        }
+
+        final double scale = aDotB / baseMagSq;
+
+        final double projX = scale * base.getX();
+        final double projY = scale * base.getY();
+        final double projZ = scale * base.getZ();
+
+        if (reject) {
+            return new Vector3D(getX() - projX, getY() - projY, getZ() - projZ);
+        }
+
+        return new Vector3D(projX, projY, projZ);
+    }
+
     /** Computes the dot product between to vectors. This method simply
      * calls {@code v1.dotProduct(v2)}.
      * @param v1 first vector
@@ -454,6 +454,28 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return v1.angle(v2);
     }
 
+    /** Projects the given vector onto {@code base}. This method simply
+     * calls {@code v.project(base)}.
+     * @param v vector to project
+     * @param base the base vector to project onto
+     * @return the projected vector
+     * @see #project(Vector3D)
+     */
+    public static Vector3D project(Vector3D v, Vector3D base) {
+        return v.project(base);
+    }
+
+    /** Returns the vector rejection of {@code v} from {@code base}. This
+     * method simply calls {@code v.reject(base)}.
+     * @param v vector to reject
+     * @param base the base vector to reject from
+     * @return the vector rejection
+     * @see #reject(Vector3D)
+     */
+    public static Vector3D reject(Vector3D v, Vector3D base) {
+        return v.reject(base);
+    }
+
     /** Computes the cross product between two vectors. This method simply
      * calls {@code v1.crossProduct(v2)}.
      * @param v1 first vector
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 004b6c3..2f39b06 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
@@ -228,37 +228,6 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
         return getComponent(base, true);
     }
 
-    /** Returns a component of the current instance relative to the given base
-     * vector. If {@code reject} is true, the vector rejection is returned; otherwise,
-     * the projection is returned.
-     * @param base The base vector
-     * @param reject If true, the rejection of this instance from {@code base} is
-     *      returned. If false, the projection of this instance onto {@code base}
-     *      is returned.
-     * @return The projection or rejection of this instance relative to {@code base},
-     *      depending on the value of {@code reject}.
-     * @throws IllegalStateException if {@code base} has a zero norm
-     */
-    private Vector2D getComponent(Vector2D base, boolean reject) throws IllegalStateException {
-        final double aDotB = dotProduct(base);
-
-        final double baseMagSq = base.getNormSq();
-        if (baseMagSq == 0.0) {
-            throw new IllegalStateException("Invalid base vector: norm is zero");
-        }
-
-        final double scale = aDotB / baseMagSq;
-
-        final double projX = scale * base.getX();
-        final double projY = scale * base.getY();
-
-        if (reject) {
-            return new Vector2D(getX() - projX, getY() - projY);
-        }
-
-        return new Vector2D(projX, projY);
-    }
-
     /** {@inheritDoc}
      * <p>This method computes the angular separation between the two
      * vectors using the dot product for well separated vectors and the
@@ -377,6 +346,37 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
         return n;
     }
 
+    /** Returns a component of the current instance relative to the given base
+     * vector. If {@code reject} is true, the vector rejection is returned; otherwise,
+     * the projection is returned.
+     * @param base The base vector
+     * @param reject If true, the rejection of this instance from {@code base} is
+     *      returned. If false, the projection of this instance onto {@code base}
+     *      is returned.
+     * @return The projection or rejection of this instance relative to {@code base},
+     *      depending on the value of {@code reject}.
+     * @throws IllegalStateException if {@code base} has a zero norm
+     */
+    private Vector2D getComponent(Vector2D base, boolean reject) throws IllegalStateException {
+        final double aDotB = dotProduct(base);
+
+        final double baseMagSq = base.getNormSq();
+        if (baseMagSq == 0.0) {
+            throw new IllegalStateException("Invalid base vector: norm is zero");
+        }
+
+        final double scale = aDotB / baseMagSq;
+
+        final double projX = scale * base.getX();
+        final double projY = scale * base.getY();
+
+        if (reject) {
+            return new Vector2D(getX() - projX, getY() - projY);
+        }
+
+        return new Vector2D(projX, projY);
+    }
+
     /** Computes the dot product between to vectors. This method simply
      * calls {@code v1.dotProduct(v2)}.
      * @param v1 first vector
@@ -388,6 +388,28 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
         return v1.dotProduct(v2);
     }
 
+    /** Projects the given vector onto {@code base}. This method simply
+     * calls {@code v.project(base)}.
+     * @param v vector to project
+     * @param base the base vector to project onto
+     * @return the projected vector
+     * @see #project(Vector2D)
+     */
+    public static Vector2D project(Vector2D v, Vector2D base) {
+        return v.project(base);
+    }
+
+    /** Returns the vector rejection of {@code v} from {@code base}. This
+     * method simply calls {@code v.reject(base)}.
+     * @param v vector to reject
+     * @param base the base vector to reject from
+     * @return the vector rejection
+     * @see #reject(Vector2D)
+     */
+    public static Vector2D reject(Vector2D v, Vector2D base) {
+        return v.reject(base);
+    }
+
     /** Computes the angle in radians between two vectors. This method
      * simply calls {@code v1.angle(v2)}.
      * @param v1 first vector
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 834b472..2abc8f5 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
@@ -623,6 +623,8 @@ public class Vector3DTest {
         Vector3D v2 = Vector3D.of(-5.0, -6.0, -7.0);
 
         // act/assert
+        checkVector(Vector3D.ZERO.project(Vector3D.PLUS_X), 0.0, 0.0, 0.0);
+
         checkVector(v1.project(Vector3D.PLUS_X), 2.0, 0.0, 0.0);
         checkVector(v1.project(Vector3D.MINUS_X), 2.0, 0.0, 0.0);
         checkVector(v1.project(Vector3D.PLUS_Y), 0.0, 3.0, 0.0);
@@ -644,6 +646,48 @@ public class Vector3DTest {
         checkVector(v2.project(Vector3D.of(-1.0, -1.0, -1.0)), -6.0, -6.0, -6.0);
     }
 
+    @Test(expected = IllegalStateException.class)
+    public void testProject_baseHasZeroNorm() {
+        // act/assert
+        Vector3D.of(1.0, 1.0, 1.0).project(Vector3D.ZERO);
+    }
+
+    @Test
+    public void testProject_static() {
+        // arrange
+        Vector3D v1 = Vector3D.of(2.0, 3.0, 4.0);
+        Vector3D v2 = Vector3D.of(-5.0, -6.0, -7.0);
+
+        // act/assert
+        checkVector(Vector3D.project(Vector3D.ZERO, Vector3D.PLUS_X), 0.0, 0.0, 0.0);
+
+        checkVector(Vector3D.project(v1, Vector3D.PLUS_X), 2.0, 0.0, 0.0);
+        checkVector(Vector3D.project(v1, Vector3D.MINUS_X), 2.0, 0.0, 0.0);
+        checkVector(Vector3D.project(v1, Vector3D.PLUS_Y), 0.0, 3.0, 0.0);
+        checkVector(Vector3D.project(v1, Vector3D.MINUS_Y), 0.0, 3.0, 0.0);
+        checkVector(Vector3D.project(v1, Vector3D.PLUS_Z), 0.0, 0.0, 4.0);
+        checkVector(Vector3D.project(v1, Vector3D.MINUS_Z), 0.0, 0.0, 4.0);
+
+        checkVector(Vector3D.project(v2, Vector3D.PLUS_X), -5.0, 0.0, 0.0);
+        checkVector(Vector3D.project(v2, Vector3D.MINUS_X), -5.0, 0.0, 0.0);
+        checkVector(Vector3D.project(v2, Vector3D.PLUS_Y), 0.0, -6.0, 0.0);
+        checkVector(Vector3D.project(v2, Vector3D.MINUS_Y), 0.0, -6.0, 0.0);
+        checkVector(Vector3D.project(v2, Vector3D.PLUS_Z), 0.0, 0.0, -7.0);
+        checkVector(Vector3D.project(v2, Vector3D.MINUS_Z), 0.0, 0.0, -7.0);
+
+        checkVector(Vector3D.project(v1, Vector3D.of(1.0, 1.0, 1.0)), 3.0, 3.0, 3.0);
+        checkVector(Vector3D.project(v1, Vector3D.of(-1.0, -1.0, -1.0)), 3.0, 3.0, 3.0);
+
+        checkVector(Vector3D.project(v2, Vector3D.of(1.0, 1.0, 1.0)), -6.0, -6.0, -6.0);
+        checkVector(Vector3D.project(v2, Vector3D.of(-1.0, -1.0, -1.0)), -6.0, -6.0, -6.0);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testProject_baseHasZeroNorm_static() {
+        // act/assert
+        Vector3D.project(Vector3D.of(1.0, 1.0, 1.0), Vector3D.ZERO);
+    }
+
     @Test
     public void testReject() {
         // arrange
@@ -651,6 +695,8 @@ public class Vector3DTest {
         Vector3D v2 = Vector3D.of(-5.0, -6.0, -7.0);
 
         // act/assert
+        checkVector(Vector3D.ZERO.reject(Vector3D.PLUS_X), 0.0, 0.0, 0.0);
+
         checkVector(v1.reject(Vector3D.PLUS_X), 0.0, 3.0, 4.0);
         checkVector(v1.reject(Vector3D.MINUS_X), 0.0, 3.0, 4.0);
         checkVector(v1.reject(Vector3D.PLUS_Y), 2.0, 0.0, 4.0);
@@ -672,6 +718,48 @@ public class Vector3DTest {
         checkVector(v2.reject(Vector3D.of(-1.0, -1.0, -1.0)), 1.0, 0.0, -1.0);
     }
 
+    @Test(expected = IllegalStateException.class)
+    public void testReject_baseHasZeroNorm() {
+        // act/assert
+        Vector3D.of(1.0, 1.0, 1.0).reject(Vector3D.ZERO);
+    }
+
+    @Test
+    public void testReject_static() {
+        // arrange
+        Vector3D v1 = Vector3D.of(2.0, 3.0, 4.0);
+        Vector3D v2 = Vector3D.of(-5.0, -6.0, -7.0);
+
+        // act/assert
+        checkVector(Vector3D.reject(Vector3D.ZERO, Vector3D.PLUS_X), 0.0, 0.0, 0.0);
+
+        checkVector(Vector3D.reject(v1, Vector3D.PLUS_X), 0.0, 3.0, 4.0);
+        checkVector(Vector3D.reject(v1, Vector3D.MINUS_X), 0.0, 3.0, 4.0);
+        checkVector(Vector3D.reject(v1, Vector3D.PLUS_Y), 2.0, 0.0, 4.0);
+        checkVector(Vector3D.reject(v1, Vector3D.MINUS_Y), 2.0, 0.0, 4.0);
+        checkVector(Vector3D.reject(v1, Vector3D.PLUS_Z), 2.0, 3.0, 0.0);
+        checkVector(Vector3D.reject(v1, Vector3D.MINUS_Z), 2.0, 3.0, 0.0);
+
+        checkVector(Vector3D.reject(v2, Vector3D.PLUS_X), 0.0, -6.0, -7.0);
+        checkVector(Vector3D.reject(v2, Vector3D.MINUS_X), 0.0, -6.0, -7.0);
+        checkVector(Vector3D.reject(v2, Vector3D.PLUS_Y), -5.0, 0.0, -7.0);
+        checkVector(Vector3D.reject(v2, Vector3D.MINUS_Y), -5.0, 0.0, -7.0);
+        checkVector(Vector3D.reject(v2, Vector3D.PLUS_Z), -5.0, -6.0, 0.0);
+        checkVector(Vector3D.reject(v2, Vector3D.MINUS_Z), -5.0, -6.0, 0.0);
+
+        checkVector(Vector3D.reject(v1, Vector3D.of(1.0, 1.0, 1.0)), -1.0, 0.0, 1.0);
+        checkVector(Vector3D.reject(v1, Vector3D.of(-1.0, -1.0, -1.0)), -1.0, 0.0, 1.0);
+
+        checkVector(Vector3D.reject(v2, Vector3D.of(1.0, 1.0, 1.0)), 1.0, 0.0, -1.0);
+        checkVector(Vector3D.reject(v2, Vector3D.of(-1.0, -1.0, -1.0)), 1.0, 0.0, -1.0);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testReject_baseHasZeroNorm_static() {
+        // act/assert
+        Vector3D.reject(Vector3D.of(1.0, 1.0, 1.0), Vector3D.ZERO);
+    }
+
     @Test
     public void testProjectAndReject_areComplementary() {
         // arrange
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 7c31092..3da0318 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
@@ -464,6 +464,33 @@ public class Vector2DTest {
     }
 
     @Test
+    public void testProject_static() {
+     // arrange
+        Vector2D v1 = Vector2D.of(3.0, 4.0);
+        Vector2D v2 = Vector2D.of(1.0, 4.0);
+
+        // act/assert
+        checkVector(Vector2D.project(Vector2D.ZERO, v1), 0.0, 0.0);
+
+        checkVector(Vector2D.project(v1, v1), 3.0, 4.0);
+        checkVector(Vector2D.project(v1, v1.negate()), 3.0, 4.0);
+
+        checkVector(Vector2D.project(v1, Vector2D.PLUS_X), 3.0, 0.0);
+        checkVector(Vector2D.project(v1, Vector2D.MINUS_X), 3.0, 0.0);
+
+        checkVector(Vector2D.project(v1, Vector2D.PLUS_Y), 0.0, 4.0);
+        checkVector(Vector2D.project(v1, Vector2D.MINUS_Y), 0.0, 4.0);
+
+        checkVector(Vector2D.project(v2, v1), (19.0 / 25.0) * 3.0, (19.0 / 25.0) * 4.0);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testProject_baseHasZeroNorm_static() {
+        // act/assert
+        Vector2D.project(Vector2D.of(1.0, 1.0), Vector2D.ZERO);
+    }
+
+    @Test
     public void testReject() {
         // arrange
         Vector2D v1 = Vector2D.of(3.0, 4.0);
@@ -491,6 +518,33 @@ public class Vector2DTest {
     }
 
     @Test
+    public void testReject_static() {
+        // arrange
+        Vector2D v1 = Vector2D.of(3.0, 4.0);
+        Vector2D v2 = Vector2D.of(1.0, 4.0);
+
+        // act/assert
+        checkVector(Vector2D.ZERO.reject(v1), 0.0, 0.0);
+
+        checkVector(Vector2D.reject(v1, v1), 0.0, 0.0);
+        checkVector(Vector2D.reject(v1, v1.negate()), 0.0, 0.0);
+
+        checkVector(Vector2D.reject(v1, Vector2D.PLUS_X), 0.0, 4.0);
+        checkVector(Vector2D.reject(v1, Vector2D.MINUS_X), 0.0, 4.0);
+
+        checkVector(Vector2D.reject(v1, Vector2D.PLUS_Y), 3.0, 0.0);
+        checkVector(Vector2D.reject(v1, Vector2D.MINUS_Y), 3.0, 0.0);
+
+        checkVector(Vector2D.reject(v2, v1), (-32.0 / 25.0), (6.0 / 25.0) * 4.0);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testReject_baseHasZeroNorm_static() {
+        // act/assert
+        Vector2D.reject(Vector2D.of(1.0, 1.0), Vector2D.ZERO);
+    }
+
+    @Test
     public void testProjectAndReject_areComplementary() {
         // arrange
         double eps = 1e-12;


[commons-geometry] 03/14: removing unnecessary Vector?D.of(Cartesian?D) methods; conversion between points and vectors can be accomplished with toPoint() and toVector() methods

Posted by er...@apache.org.
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 9d09f787a3d80bac6cc0972844ba446776ed5e51
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Sun Jul 22 14:33:05 2018 -0400

    removing unnecessary Vector?D.of(Cartesian?D) methods; conversion between points and vectors can be accomplished with toPoint() and toVector() methods
---
 .../org/apache/commons/geometry/euclidean/oned/Point1D.java  |  2 +-
 .../org/apache/commons/geometry/euclidean/oned/Vector1D.java |  8 --------
 .../apache/commons/geometry/euclidean/threed/Vector3D.java   |  8 --------
 .../org/apache/commons/geometry/euclidean/twod/Vector2D.java |  8 --------
 .../apache/commons/geometry/euclidean/oned/Vector1DTest.java | 12 ------------
 .../commons/geometry/euclidean/threed/Vector3DTest.java      | 11 -----------
 .../apache/commons/geometry/euclidean/twod/Vector2DTest.java |  9 ---------
 7 files changed, 1 insertion(+), 57 deletions(-)

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 2100e72..1e6603e 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
@@ -68,7 +68,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D
     /** {@inheritDoc} */
     @Override
     public Vector1D asVector() {
-        return Vector1D.of(this);
+        return Vector1D.of(getX());
     }
 
     /** {@inheritDoc} */
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 11786a5..8ed1194 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
@@ -267,14 +267,6 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point
         return new Vector1D(x);
     }
 
-    /** Returns a vector instance with the given coordinate value.
-     * @param value vector coordinate
-     * @return vector instance
-     */
-    public static Vector1D of(Cartesian1D value) {
-        return new Vector1D(value.getX());
-    }
-
     /** Parses the given string and returns a new vector instance. The expected string
      * format is the same as that returned by {@link #toString()}.
      * @param str the string to parse
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 f290fdd..50fee39 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
@@ -432,14 +432,6 @@ public final class Vector3D extends Cartesian3D implements EuclideanVector<Point
         return new Vector3D(x, y, z);
     }
 
-    /** Returns a vector instance with the given coordinate values.
-     * @param value vector coordinates
-     * @return vector instance
-     */
-    public static Vector3D of(Cartesian3D value) {
-        return new Vector3D(value.getX(), value.getY(), value.getZ());
-    }
-
     /** Creates a vector from the coordinates in the given 3-element array.
      * @param v coordinates array
      * @return new vector
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 3d6fa79..a81dcd7 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
@@ -368,14 +368,6 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point
         return new Vector2D(x, y);
     }
 
-    /** Returns a vector instance with the given coordinate values.
-     * @param value vector coordinates
-     * @return vector instance
-     */
-    public static Vector2D of(Cartesian2D value) {
-        return new Vector2D(value.getX(), value.getY());
-    }
-
     /** Creates a vector from the coordinates in the given 2-element array.
      * @param v coordinates array
      * @return new vector
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
index c86be90..cce8abe 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
@@ -374,18 +374,6 @@ public class Vector1DTest {
     }
 
     @Test
-    public void testOf_coordinateArg() {
-        // act/assert
-        checkVector(Vector1D.of(Vector1D.of(0)), 0.0);
-        checkVector(Vector1D.of(Vector1D.of(-1)), -1.0);
-        checkVector(Vector1D.of(Vector1D.of(1)), 1.0);
-        checkVector(Vector1D.of(Vector1D.of(Math.PI)), Math.PI);
-        checkVector(Vector1D.of(Vector1D.of(Double.NaN)), Double.NaN);
-        checkVector(Vector1D.of(Vector1D.of(Double.NEGATIVE_INFINITY)), Double.NEGATIVE_INFINITY);
-        checkVector(Vector1D.of(Vector1D.of(Double.POSITIVE_INFINITY)), Double.POSITIVE_INFINITY);
-    }
-
-    @Test
     public void testLinearCombination() {
         // act/assert
         checkVector(Vector1D.linearCombination(2, Vector1D.of(3)), 6);
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 9991e0c..a0dfd4b 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
@@ -709,17 +709,6 @@ public class Vector3DTest {
     }
 
     @Test
-    public void testOf_coordinateArg() {
-        // act/assert
-        checkVector(Vector3D.of(Point3D.of(1, 2, 3)), 1, 2, 3);
-        checkVector(Vector3D.of(Point3D.of(-1, -2, -3)), -1, -2, -3);
-        checkVector(Vector3D.of(Point3D.of(Math.PI, Double.NaN, Double.POSITIVE_INFINITY)),
-                Math.PI, Double.NaN, Double.POSITIVE_INFINITY);
-        checkVector(Vector3D.of(Point3D.of(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E)),
-                   Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.E);
-    }
-
-    @Test
     public void testOf_arrayArg() {
         // act/assert
         checkVector(Vector3D.of(new double[] { 1, 2, 3 }), 1, 2, 3);
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 1050ee4..3bf0687 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
@@ -521,15 +521,6 @@ public class Vector2DTest {
     }
 
     @Test
-    public void testOf_coordinateArg() {
-        // act/assert
-        checkVector(Vector2D.of(Point2D.of(0, 1)), 0, 1);
-        checkVector(Vector2D.of(Point2D.of(-1, -2)), -1, -2);
-        checkVector(Vector2D.of(Point2D.of(Math.PI, Double.NaN)), Math.PI, Double.NaN);
-        checkVector(Vector2D.of(Point2D.of(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)), Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY);
-    }
-
-    @Test
     public void testOf_arrayArg() {
         // act/assert
         checkVector(Vector2D.of(new double[] { 0, 1 }), 0, 1);