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 feaf55bc55865f2df0d91164ea520653e1627038 Author: Matt Juntunen <[email protected]> AuthorDate: Thu Dec 20 21:25:22 2018 -0500 minor cleanup: removing unused internal methods, using better test names, adding javadocs --- .../geometry/euclidean/internal/Vectors.java | 29 ---------------------- .../euclidean/threed/rotation/Rotation3D.java | 9 +++++++ .../geometry/euclidean/internal/VectorsTest.java | 25 ------------------- .../threed/rotation/QuaternionRotationTest.java | 16 +++--------- 4 files changed, 13 insertions(+), 66 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 91c5793..ddf5883 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 @@ -99,21 +99,6 @@ public final class Vectors { return Math.sqrt(normSq(x1, x2, 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 x1 first vector component - * @param x2 second vector component - * @param x3 third vector component - * @param x4 fourth 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, final double x4) { - return Math.sqrt(normSq(x1, x2, x3, x4)); - } - - /** 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. @@ -149,18 +134,4 @@ public final class Vectors { public static double normSq(final double x1, final double x2, final double x3) { return (x1 * x1) + (x2 * x2) + (x3 * 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 x1 first vector component - * @param x2 second vector component - * @param x3 third vector component - * @param x4 fourth vector component - * @return square of the L<sub>2</sub> norm for the vector with the given components - * @see #norm(double, double, double, double) - */ - public static double normSq(final double x1, final double x2, final double x3, final double x4) { - return (x1 * x1) + (x2 * x2) + (x3 * x3) + (x4 * x4); - } } diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/Rotation3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/Rotation3D.java index 17eb3bc..40a75b2 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/Rotation3D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/Rotation3D.java @@ -27,6 +27,15 @@ import org.apache.commons.geometry.euclidean.twod.Vector2D; */ public interface Rotation3D extends Transform<Vector3D, Vector2D> { + /** Apply this rotation to the given argument. Since rotations do + * not affect vector magnitudes, this method can be applied to + * both points and vectors. + * @param vec the point or vector to rotate + * @return a new instance representing the rotated point or vector + */ + @Override + Vector3D apply(Vector3D vec); + /** Get the axis of rotation as a normalized {@link Vector3D}. * * <p>All 3-dimensional rotations and sequences of rotations can be reduced 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 d8f6bb4..dbd4551 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 @@ -23,7 +23,6 @@ import org.apache.commons.geometry.euclidean.threed.Vector3D; import org.junit.Assert; import org.junit.Test; - public class VectorsTest { private static final double EPS = Math.ulp(1d); @@ -124,18 +123,6 @@ public class VectorsTest { } @Test - public void testNorm_fourD() { - // act/assert - Assert.assertEquals(0.0, Vectors.norm(0.0, 0.0, 0.0, 0.0), EPS); - - Assert.assertEquals(Math.sqrt(30.0), Vectors.norm(1.0, 2.0, 3.0, 4.0), EPS); - Assert.assertEquals(Math.sqrt(174.0), Vectors.norm(5.0, 6.0, 7.0, -8.0), EPS); - Assert.assertEquals(Math.sqrt(446.0), Vectors.norm(9.0, 10.0, -11.0, 12.0), EPS); - Assert.assertEquals(Math.sqrt(846.0), Vectors.norm(13.0, -14.0, 15.0, 16.0), EPS); - Assert.assertEquals(Math.sqrt(1374.0), Vectors.norm(-17.0, 18.0, 19.0, 20.0), EPS); - } - - @Test public void testNormSq_oneD() { // act/assert Assert.assertEquals(0.0, Vectors.normSq(0.0), EPS); @@ -172,16 +159,4 @@ public class VectorsTest { 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 testNormSq_fourD() { - // act/assert - Assert.assertEquals(0.0, Vectors.normSq(0.0, 0.0, 0.0, 0.0), EPS); - - Assert.assertEquals(30.0, Vectors.normSq(1.0, 2.0, 3.0, 4.0), EPS); - Assert.assertEquals(174.0, Vectors.normSq(5.0, 6.0, 7.0, -8.0), EPS); - Assert.assertEquals(446.0, Vectors.normSq(9.0, 10.0, -11.0, 12.0), EPS); - Assert.assertEquals(846.0, Vectors.normSq(13.0, -14.0, 15.0, 16.0), EPS); - Assert.assertEquals(1374.0, Vectors.normSq(-17.0, 18.0, 19.0, 20.0), EPS); - } } diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotationTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotationTest.java index 1ea4d7f..fcde7f2 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotationTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotationTest.java @@ -19,7 +19,6 @@ package org.apache.commons.geometry.euclidean.threed.rotation; import java.util.Arrays; import java.util.List; import java.util.function.UnaryOperator; -import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.geometry.core.Geometry; @@ -30,9 +29,6 @@ import org.apache.commons.geometry.euclidean.EuclideanTestUtils; import org.apache.commons.geometry.euclidean.internal.Vectors; import org.apache.commons.geometry.euclidean.threed.AffineTransformMatrix3D; import org.apache.commons.geometry.euclidean.threed.Vector3D; -import org.apache.commons.geometry.euclidean.threed.rotation.AxisAngleSequence; -import org.apache.commons.geometry.euclidean.threed.rotation.AxisSequence; -import org.apache.commons.geometry.euclidean.threed.rotation.QuaternionRotation; import org.apache.commons.numbers.angle.PlaneAngleRadians; import org.apache.commons.numbers.core.Precision; import org.apache.commons.numbers.quaternion.Quaternion; @@ -640,7 +636,7 @@ public class QuaternionRotationTest { } @Test - public void testSlerp_quaternionsHaveMinusOneDotProduct() { + public void testSlerp_inputQuaternionsHaveMinusOneDotProduct() { // arrange QuaternionRotation q1 = QuaternionRotation.of(1, 0, 0, 1); // pi/2 around +z QuaternionRotation q2 = QuaternionRotation.of(-1, 0, 0, -1); // 3pi/2 around -z @@ -656,7 +652,7 @@ public class QuaternionRotationTest { } @Test - public void testSlerp_quaternionIsNormalizedForAllT() { + public void testSlerp_outputQuaternionIsNormalizedForAllT() { // arrange QuaternionRotation q1 = QuaternionRotation.fromAxisAngle(Vector3D.PLUS_Z, 0.25 * Geometry.PI); QuaternionRotation q2 = QuaternionRotation.fromAxisAngle(Vector3D.PLUS_Z, 0.75 * Geometry.PI); @@ -670,11 +666,7 @@ public class QuaternionRotationTest { QuaternionRotation result = QuaternionRotation.of(q1.slerp(q2).apply(t)); // assert - Assert.assertEquals(1.0, Vectors.norm(result.getQuaternion().getX(), - result.getQuaternion().getY(), - result.getQuaternion().getZ(), - result.getQuaternion().getW()), - EPS); + Assert.assertEquals(1.0, result.getQuaternion().norm(), EPS); } } @@ -1336,7 +1328,7 @@ public class QuaternionRotationTest { EuclideanTestUtils.assertCoordinatesEqual(transformedZ.normalize(), transformedX.normalize().crossProduct(transformedY.normalize()), EPS); - Assert.assertEquals(1.0, Vectors.norm(q.getQuaternion().getX(), q.getQuaternion().getY(), q.getQuaternion().getZ(), q.getQuaternion().getW()), EPS); + Assert.assertEquals(1.0, q.getQuaternion().norm(), EPS); }); }
