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 677308ac7d1ee8f8a78686d3aea5b80f4d909302 Author: Gilles Sadowski <[email protected]> AuthorDate: Fri Sep 27 14:22:14 2019 +0200 GEOMETRY-61: Avoid redundant creation. --- .../java/org/apache/commons/geometry/euclidean/oned/Vector1D.java | 4 +++- .../java/org/apache/commons/geometry/euclidean/threed/Vector3D.java | 4 +++- .../java/org/apache/commons/geometry/euclidean/twod/Vector2D.java | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) 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 827afde..896e7db 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 @@ -415,7 +415,9 @@ public class Vector1D extends EuclideanVector<Vector1D> { * @throws IllegalNormException if the norm of the given value is zero, NaN, or infinite */ public static Unit from(Vector1D v) { - return from(v.getX()); + return v instanceof Unit ? + (Unit) v : + from(v.getX()); } /** {@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 dc73b4c..03a85e2 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 @@ -632,7 +632,9 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> { * @throws IllegalNormException if the norm of the given value is zero, NaN, or infinite */ public static Unit from(Vector3D v) { - return from(v.getX(), v.getY(), v.getZ()); + return v instanceof Unit ? + (Unit) v : + from(v.getX(), v.getY(), v.getZ()); } /** {@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 0daf927..b0d6665 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 @@ -562,7 +562,9 @@ public class Vector2D extends MultiDimensionalEuclideanVector<Vector2D> { * @throws IllegalNormException if the norm of the given value is zero, NaN, or infinite */ public static Unit from(Vector2D v) { - return from(v.getX(), v.getY()); + return v instanceof Unit ? + (Unit) v : + from(v.getX(), v.getY()); } /** {@inheritDoc} */
