git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

# [GitHub] darkma773r closed pull request #17: Minor Cleanup

```darkma773r closed pull request #17: Minor Cleanup
URL: https://github.com/apache/commons-geometry/pull/17

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 static double norm(final double x1, final double x2, final double x3) {
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 static double normSq(final double x1, final double x2) {
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 @@
*/
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.junit.Assert;
import org.junit.Test;

-
public class VectorsTest {

private static final double EPS = Math.ulp(1d);
@@ -123,18 +122,6 @@ public void testNorm_threeD() {
Assert.assertEquals(Math.sqrt(1589.0), Vectors.norm(-22.0, -23.0, -24.0), EPS);
}

-    @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
@@ -172,16 +159,4 @@ public void testNormSq_threeD() {
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..bf0d6c3 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 @@
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;
@@ -27,12 +26,8 @@
import org.apache.commons.geometry.core.exception.IllegalNormException;
import org.apache.commons.geometry.core.internal.SimpleTupleFormat;
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 +635,7 @@ public void testSlerp_followsShortestPath() {
}

@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 +651,7 @@ public void testSlerp_quaternionsHaveMinusOneDotProduct() {
}

@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 +665,7 @@ public void testSlerp_quaternionIsNormalizedForAllT() {
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 +1327,7 @@ public void testCreateBasisRotation_permute() {
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);
});
}

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@xxxxxxxxxxxxxxxx

With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: dev-help@xxxxxxxxxxxxxxxxxx

```