This is an automated email from the ASF dual-hosted git repository. mattjuntunen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-geometry.git
The following commit(s) were added to refs/heads/master by this push: new 4140682 GEOMETRY-50: using SafeNorm for 3D norm computation 4140682 is described below commit 4140682cf96dbce16c7965de75b9d045078007f8 Author: Matt Juntunen <mattjuntu...@apache.org> AuthorDate: Fri Jun 26 08:11:16 2020 -0400 GEOMETRY-50: using SafeNorm for 3D norm computation --- .../java/org/apache/commons/geometry/euclidean/internal/Vectors.java | 3 ++- .../org/apache/commons/geometry/euclidean/internal/VectorsTest.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/Vectors.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/Vectors.java index 3e29b44..44589a0 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/Vectors.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/Vectors.java @@ -17,6 +17,7 @@ package org.apache.commons.geometry.euclidean.internal; import org.apache.commons.geometry.core.Vector; +import org.apache.commons.numbers.arrays.SafeNorm; /** This class consists exclusively of static vector utility methods. */ @@ -109,7 +110,7 @@ public final class Vectors { * @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)); + return SafeNorm.value(new double[] {x1, x2, x3}); } /** Get the square of the L<sub>2</sub> norm (also known as the Euclidean norm) diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/internal/VectorsTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/internal/VectorsTest.java index f3be7c1..eb3afbf 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/internal/VectorsTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/internal/VectorsTest.java @@ -79,9 +79,9 @@ public class VectorsTest { GeometryTestUtils.assertThrows(() -> Vectors.checkedNorm(Vector3D.NaN), IllegalArgumentException.class, "Illegal norm: NaN"); GeometryTestUtils.assertThrows(() -> Vectors.checkedNorm(Vector3D.POSITIVE_INFINITY), - IllegalArgumentException.class, "Illegal norm: Infinity"); + IllegalArgumentException.class, "Illegal norm: NaN"); GeometryTestUtils.assertThrows(() -> Vectors.checkedNorm(Vector3D.NEGATIVE_INFINITY), - IllegalArgumentException.class, "Illegal norm: Infinity"); + IllegalArgumentException.class, "Illegal norm: NaN"); } @Test