Skip to content
Permalink
Browse files
GEOMETRY-50: using SafeNorm for 3D norm computation
  • Loading branch information
darkma773r committed Jun 26, 2020
1 parent 015f466 commit 4140682cf96dbce16c7965de75b9d045078007f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
@@ -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 static double norm(final double x1, final double x2) {
* @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)
@@ -79,9 +79,9 @@ public void testCheckedNorm_vectorArg() {
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

0 comments on commit 4140682

Please sign in to comment.