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 d0aaa27873a9739ef8c180f39ccecf5b0f0cdd22 Author: Matt Juntunen <[email protected]> AuthorDate: Fri Dec 21 23:23:22 2018 -0500 GEOMETRY-31: renaming dotProduct to dot and crossProduct to cross --- .../org/apache/commons/geometry/core/Vector.java | 4 +-- .../commons/geometry/euclidean/oned/Vector1D.java | 2 +- .../commons/geometry/euclidean/threed/Line.java | 16 ++++----- .../euclidean/threed/OutlineExtractor.java | 12 +++---- .../commons/geometry/euclidean/threed/Plane.java | 20 +++++------ .../geometry/euclidean/threed/PolyhedronsSet.java | 2 +- .../geometry/euclidean/threed/SubPlane.java | 4 +-- .../geometry/euclidean/threed/Vector3D.java | 10 +++--- .../threed/rotation/QuaternionRotation.java | 40 ++++++++++----------- .../commons/geometry/euclidean/twod/Vector2D.java | 8 ++--- .../geometry/euclidean/oned/Vector1DTest.java | 8 ++--- .../geometry/euclidean/threed/LineTest.java | 2 +- .../euclidean/threed/PolyhedronsSetTest.java | 2 +- .../geometry/euclidean/threed/Vector3DTest.java | 42 +++++++++++----------- .../threed/rotation/QuaternionRotationTest.java | 14 ++++---- .../geometry/euclidean/twod/Vector2DTest.java | 30 ++++++++-------- .../euclidean/twod/hull/AklToussaintHeuristic.java | 4 +-- .../commons/geometry/spherical/twod/Circle.java | 8 ++--- .../spherical/twod/PropertiesComputer.java | 4 +-- .../spherical/twod/SphericalPolygonsSet.java | 2 +- .../geometry/spherical/twod/CircleTest.java | 8 ++--- 21 files changed, 121 insertions(+), 121 deletions(-) diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java index 1b7aea0..873e24e 100644 --- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java +++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java @@ -124,9 +124,9 @@ public interface Vector<V extends Vector<V>> extends Spatial { /** Compute the dot-product of the instance and another vector. * @param v second vector - * @return the dot product this · v + * @return the dot product (this · v) */ - double dotProduct(V v); + double dot(V v); /** Compute the angular separation between two vectors in radians. * @param v other vector 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 9d59e6b..6556ca0 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 @@ -188,7 +188,7 @@ public class Vector1D extends EuclideanVector<Vector1D> { /** {@inheritDoc} */ @Override - public double dotProduct(Vector1D v) { + public double dot(Vector1D v) { return x * v.x; } diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java index f650215..2f036a3 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Line.java @@ -76,7 +76,7 @@ public class Line implements Embedding<Vector3D, Vector1D> { throw new IllegalArgumentException("Points are equal"); } this.direction = Vector3D.linearCombination(1.0 / Math.sqrt(norm2), delta); - this.zero = Vector3D.linearCombination(1.0, p1, -p1.dotProduct(delta) / norm2, delta); + this.zero = Vector3D.linearCombination(1.0, p1, -p1.dot(delta) / norm2, delta); } /** Get the tolerance below which points are considered identical. @@ -117,7 +117,7 @@ public class Line implements Embedding<Vector3D, Vector1D> { * @return abscissa of the point */ public double getAbscissa(final Vector3D point) { - return point.subtract(zero).dotProduct(direction); + return point.subtract(zero).dot(direction); } /** Get one point from the line. @@ -174,7 +174,7 @@ public class Line implements Embedding<Vector3D, Vector1D> { */ public double distance(final Vector3D p) { final Vector3D d = p.subtract(zero); - final Vector3D n = Vector3D.linearCombination(1.0, d, -d.dotProduct(direction), direction); + final Vector3D n = Vector3D.linearCombination(1.0, d, -d.dot(direction), direction); return n.norm(); } @@ -184,7 +184,7 @@ public class Line implements Embedding<Vector3D, Vector1D> { */ public double distance(final Line line) { - final Vector3D normal = direction.crossProduct(line.direction); + final Vector3D normal = direction.cross(line.direction); final double n = normal.norm(); if (n < Precision.SAFE_MIN) { // lines are parallel @@ -192,7 +192,7 @@ public class Line implements Embedding<Vector3D, Vector1D> { } // signed separation of the two parallel planes that contains the lines - final double offset = line.zero.subtract(zero).dotProduct(normal) / n; + final double offset = line.zero.subtract(zero).dot(normal) / n; return Math.abs(offset); @@ -204,7 +204,7 @@ public class Line implements Embedding<Vector3D, Vector1D> { */ public Vector3D closestPoint(final Line line) { - final double cos = direction.dotProduct(line.direction); + final double cos = direction.dot(line.direction); final double n = 1 - cos * cos; if (n < Precision.EPSILON) { // the lines are parallel @@ -212,8 +212,8 @@ public class Line implements Embedding<Vector3D, Vector1D> { } final Vector3D delta0 = line.zero.subtract(zero); - final double a = delta0.dotProduct(direction); - final double b = delta0.dotProduct(line.direction); + final double a = delta0.dot(direction); + final double b = delta0.dot(line.direction); return Vector3D.linearCombination(1, zero, (a - b * cos) / n, direction); diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/OutlineExtractor.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/OutlineExtractor.java index 0fd8448..3ea8376 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/OutlineExtractor.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/OutlineExtractor.java @@ -49,7 +49,7 @@ public class OutlineExtractor { public OutlineExtractor(final Vector3D u, final Vector3D v) { this.u = u; this.v = v; - this.w = u.crossProduct(v); + this.w = u.cross(v); } /** Extract the outline of a polyhedrons set. @@ -168,7 +168,7 @@ public class OutlineExtractor { (AbstractSubHyperplane<Vector3D, Vector2D>) facet; final Plane plane = (Plane) facet.getHyperplane(); - final double scal = plane.getNormal().dotProduct(w); + final double scal = plane.getNormal().dot(w); if (Math.abs(scal) > 1.0e-3) { Vector2D[][] vertices = ((PolygonsSet) absFacet.getRemainingRegion()).getVertices(); @@ -205,13 +205,13 @@ public class OutlineExtractor { int previous = closed ? (loop.length - 1) : 1; Vector3D previous3D = plane.toSpace(loop[previous]); int current = (previous + 1) % loop.length; - Vector2D pPoint = Vector2D.of(previous3D.dotProduct(u), - previous3D.dotProduct(v)); + Vector2D pPoint = Vector2D.of(previous3D.dot(u), + previous3D.dot(v)); while (current < loop.length) { final Vector3D current3D = plane.toSpace(loop[current]); - final Vector2D cPoint = Vector2D.of(current3D.dotProduct(u), - current3D.dotProduct(v)); + final Vector2D cPoint = Vector2D.of(current3D.dot(u), + current3D.dot(v)); final org.apache.commons.geometry.euclidean.twod.Line line = new org.apache.commons.geometry.euclidean.twod.Line(pPoint, cPoint, tolerance); SubHyperplane<Vector2D> edge = line.wholeHyperplane(); diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java index 963b76d..b1f2955 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Plane.java @@ -70,7 +70,7 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D throws IllegalArgumentException { setNormal(normal); this.tolerance = tolerance; - this.originOffset = -p.dotProduct(w); + this.originOffset = -p.dot(w); setFrame(); } @@ -85,7 +85,7 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D */ public Plane(final Vector3D p1, final Vector3D p2, final Vector3D p3, final double tolerance) throws IllegalArgumentException { - this(p1, p2.subtract(p1).crossProduct(p3.subtract(p1)), tolerance); + this(p1, p2.subtract(p1).cross(p3.subtract(p1)), tolerance); } /** Copy constructor. @@ -121,7 +121,7 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D */ public void reset(final Vector3D p, final Vector3D normal) { setNormal(normal); - originOffset = -p.dotProduct(w); + originOffset = -p.dot(w); setFrame(); } @@ -154,7 +154,7 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D private void setFrame() { origin = Vector3D.linearCombination(-originOffset, w); u = w.orthogonal(); - v = w.crossProduct(u); + v = w.cross(u); } /** Get the origin point of the plane frame. @@ -242,7 +242,7 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D @Override public Vector2D toSubSpace(final Vector3D point) { Vector3D vec = point; - return Vector2D.of(vec.dotProduct(u), vec.dotProduct(v)); + return Vector2D.of(vec.dot(u), vec.dot(v)); } /** Transform an in-plane point into a 3D space point. @@ -323,12 +323,12 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D */ public Vector3D intersection(final Line line) { final Vector3D direction = line.getDirection(); - final double dot = w.dotProduct(direction); + final double dot = w.dot(direction); if (Math.abs(dot) < 1.0e-10) { return null; } final Vector3D point = line.toSpace(Vector1D.ZERO); - final double k = -(originOffset + w.dotProduct(point)) / dot; + final double k = -(originOffset + w.dot(point)) / dot; return Vector3D.linearCombination(1.0, point, k, direction); } @@ -338,7 +338,7 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D * other plane (really a {@link Line Line} instance) */ public Line intersection(final Plane other) { - final Vector3D direction = w.crossProduct(other.w); + final Vector3D direction = w.cross(other.w); if (direction.norm() < tolerance) { return null; } @@ -437,7 +437,7 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D */ @Override public double getOffset(final Vector3D point) { - return point.dotProduct(w) + originOffset; + return point.dot(w) + originOffset; } /** Check if the instance has the same orientation as another hyperplane. @@ -447,7 +447,7 @@ public class Plane implements Hyperplane<Vector3D>, Embedding<Vector3D, Vector2D */ @Override public boolean sameOrientationAs(final Hyperplane<Vector3D> other) { - return (((Plane) other).w).dotProduct(w) > 0.0; + return (((Plane) other).w).dot(w) > 0.0; } } diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java index fd7ded9..58269fe 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java @@ -450,7 +450,7 @@ public class PolyhedronsSet extends AbstractRegion<Vector3D, Vector2D> { // the volume here is actually 3x the actual pyramid volume; we'll apply // the final scaling all at once at the end - double scaledVolume = area * facetBarycenter.dotProduct(plane.getNormal()); + double scaledVolume = area * facetBarycenter.dot(plane.getNormal()); if (reversed) { scaledVolume = -scaledVolume; } diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SubPlane.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SubPlane.java index eece004..485f514 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SubPlane.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/SubPlane.java @@ -74,8 +74,8 @@ public class SubPlane extends AbstractSubHyperplane<Vector3D, Vector2D> { // the hyperplanes do intersect Vector2D p = thisPlane.toSubSpace(inter.toSpace(Vector1D.ZERO)); Vector2D q = thisPlane.toSubSpace(inter.toSpace(Vector1D.ONE)); - Vector3D crossP = inter.getDirection().crossProduct(thisPlane.getNormal()); - if (crossP.dotProduct(otherPlane.getNormal()) < 0) { + Vector3D crossP = inter.getDirection().cross(thisPlane.getNormal()); + if (crossP.dot(otherPlane.getNormal()) < 0) { final Vector2D tmp = p; p = q; q = tmp; 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 4ff6dff..b59793a 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 @@ -271,7 +271,7 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> { * @see LinearCombination#value(double, double, double, double, double, double) */ @Override - public double dotProduct(Vector3D v) { + public double dot(Vector3D v) { return LinearCombination.value(x, v.x, y, v.y, z, v.z); } @@ -286,11 +286,11 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> { public double angle(Vector3D v) { double normProduct = getCheckedNorm() * v.getCheckedNorm(); - double dot = dotProduct(v); + double dot = dot(v); double threshold = normProduct * 0.99; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine - Vector3D cross = crossProduct(v); + Vector3D cross = cross(v); if (dot >= 0) { return Math.asin(cross.norm() / normProduct); } @@ -354,7 +354,7 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> { * @param v other vector * @return the cross product this ^ v as a new Vector3D */ - public Vector3D crossProduct(final Vector3D v) { + public Vector3D cross(final Vector3D v) { return new Vector3D(LinearCombination.value(y, v.z, -z, v.y), LinearCombination.value(z, v.x, -x, v.z), LinearCombination.value(x, v.y, -y, v.x)); @@ -439,7 +439,7 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> { * @throws IllegalNormException if {@code base} has a zero, NaN, or infinite norm */ private Vector3D getComponent(Vector3D base, boolean reject, DoubleFunction3N<Vector3D> factory) { - final double aDotB = dotProduct(base); + final double aDotB = dot(base); // We need to check the norm value here to ensure that it's legal. However, we don't // want to incur the cost or floating point error of getting the actual norm and then diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotation.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotation.java index f9f51c2..957ff56 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotation.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotation.java @@ -384,15 +384,15 @@ public final class QuaternionRotation implements Rotation3D, Serializable { final Vector3D vec3 = apply(axis3); final Vector3D invVec1 = inverse().apply(axis1); - final double angle2Sin = vec3.dotProduct(axis2.crossProduct(axis3)); + final double angle2Sin = vec3.dot(axis2.cross(axis3)); if (angle2Sin < -AXIS_ANGLE_SINGULARITY_THRESHOLD || angle2Sin > AXIS_ANGLE_SINGULARITY_THRESHOLD) { final Vector3D vec2 = apply(axis2); - final double angle1TanY = vec2.dotProduct(axis1.crossProduct(axis2)); - final double angle1TanX = vec2.dotProduct(axis2); + final double angle1TanY = vec2.dot(axis1.cross(axis2)); + final double angle1TanX = vec2.dot(axis2); final double angle2 = angle2Sin > AXIS_ANGLE_SINGULARITY_THRESHOLD ? Geometry.HALF_PI : Geometry.MINUS_HALF_PI; @@ -403,13 +403,13 @@ public final class QuaternionRotation implements Rotation3D, Serializable { }; } - final Vector3D crossAxis13 = axis1.crossProduct(axis3); + final Vector3D crossAxis13 = axis1.cross(axis3); - final double angle1TanY = vec3.dotProduct(crossAxis13); - final double angle1TanX = vec3.dotProduct(axis3); + final double angle1TanY = vec3.dot(crossAxis13); + final double angle1TanX = vec3.dot(axis3); - final double angle3TanY = invVec1.dotProduct(crossAxis13); - final double angle3TanX = invVec1.dotProduct(axis1); + final double angle3TanY = invVec1.dot(crossAxis13); + final double angle3TanX = invVec1.dot(axis1); return new double[] { Math.atan2(angle1TanY, angle1TanX), @@ -445,20 +445,20 @@ public final class QuaternionRotation implements Rotation3D, Serializable { // Use the same overall approach as with the Tait-Bryan angles: get the first two angles by looking // at the transformed rotation axes and the third by using the inverse. - final Vector3D crossAxis = axis1.crossProduct(axis2); + final Vector3D crossAxis = axis1.cross(axis2); final Vector3D vec1 = apply(axis1); final Vector3D invVec1 = inverse().apply(axis1); - final double angle2Cos = vec1.dotProduct(axis1); + final double angle2Cos = vec1.dot(axis1); if (angle2Cos < -AXIS_ANGLE_SINGULARITY_THRESHOLD || angle2Cos > AXIS_ANGLE_SINGULARITY_THRESHOLD) { final Vector3D vec2 = apply(axis2); - final double angle1TanY = vec2.dotProduct(crossAxis); - final double angle1TanX = vec2.dotProduct(axis2); + final double angle1TanY = vec2.dot(crossAxis); + final double angle1TanX = vec2.dot(axis2); final double angle2 = angle2Cos > AXIS_ANGLE_SINGULARITY_THRESHOLD ? Geometry.ZERO_PI : Geometry.PI; @@ -469,11 +469,11 @@ public final class QuaternionRotation implements Rotation3D, Serializable { }; } - final double angle1TanY = vec1.dotProduct(axis2); - final double angle1TanX = -vec1.dotProduct(crossAxis); + final double angle1TanY = vec1.dot(axis2); + final double angle1TanX = -vec1.dot(crossAxis); - final double angle3TanY = invVec1.dotProduct(axis2); - final double angle3TanX = invVec1.dotProduct(crossAxis); + final double angle3TanY = invVec1.dot(axis2); + final double angle3TanX = invVec1.dot(crossAxis); return new double[] { Math.atan2(angle1TanY, angle1TanX), @@ -599,7 +599,7 @@ public final class QuaternionRotation implements Rotation3D, Serializable { public static QuaternionRotation createVectorRotation(final Vector3D u, final Vector3D v) { double normProduct = Vectors.checkedNorm(u) * Vectors.checkedNorm(v); - double dot = u.dotProduct(v); + double dot = u.dot(v); if (dot < ANTIPARALLEL_DOT_THRESHOLD * normProduct) { // Special case where u1 = -u2: @@ -634,7 +634,7 @@ public final class QuaternionRotation implements Rotation3D, Serializable { // // This can be simplified to the expression below. final double vectorialScaleFactor = 1.0 / (2.0 * w * normProduct); - final Vector3D axis = u.crossProduct(v); + final Vector3D axis = u.cross(v); return of(w, vectorialScaleFactor * axis.getX(), @@ -666,11 +666,11 @@ public final class QuaternionRotation implements Rotation3D, Serializable { // calculate orthonormalized bases final Vector3D a = u1.normalize(); final Vector3D b = a.orthogonal(u2); - final Vector3D c = a.crossProduct(b); + final Vector3D c = a.cross(b); final Vector3D d = v1.normalize(); final Vector3D e = d.orthogonal(v2); - final Vector3D f = d.crossProduct(e); + final Vector3D f = d.cross(e); // create an orthogonal rotation matrix representing the change of basis; this matrix will // be the multiplication of the matrix composed of the column vectors d, e, f and the 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 4949335..08b4f1f 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 @@ -219,7 +219,7 @@ public class Vector2D extends MultiDimensionalEuclideanVector<Vector2D> { /** {@inheritDoc} */ @Override - public double dotProduct(Vector2D v) { + public double dot(Vector2D v) { return LinearCombination.value(x, v.x, y, v.y); } @@ -234,7 +234,7 @@ public class Vector2D extends MultiDimensionalEuclideanVector<Vector2D> { public double angle(Vector2D v) { double normProduct = getCheckedNorm() * v.getCheckedNorm(); - double dot = dotProduct(v); + double dot = dot(v); double threshold = normProduct * 0.9999; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine @@ -301,7 +301,7 @@ public class Vector2D extends MultiDimensionalEuclideanVector<Vector2D> { * * @see <a href="http://mathworld.wolfram.com/CrossProduct.html">Cross product (Mathworld)</a> */ - public double crossProduct(final Vector2D p1, final Vector2D p2) { + public double cross(final Vector2D p1, final Vector2D p2) { final double x1 = p2.x - p1.x; final double y1 = y - p1.y; final double x2 = x - p1.x; @@ -389,7 +389,7 @@ public class Vector2D extends MultiDimensionalEuclideanVector<Vector2D> { * @throws IllegalNormException if {@code base} has a zero, NaN, or infinite norm */ private Vector2D getComponent(Vector2D base, boolean reject, DoubleFunction2N<Vector2D> factory) { - final double aDotB = dotProduct(base); + final double aDotB = dot(base); // We need to check the norm value here to ensure that it's legal. However, we don't // want to incur the cost or floating point error of getting the actual norm and then diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java index fda735c..8aa06b7 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java @@ -305,11 +305,11 @@ public class Vector1DTest { Vector1D v3 = Vector1D.of(3); // act/assert - Assert.assertEquals(-6.0, v1.dotProduct(v2), TEST_TOLERANCE); - Assert.assertEquals(-6.0, v2.dotProduct(v1), TEST_TOLERANCE); + Assert.assertEquals(-6.0, v1.dot(v2), TEST_TOLERANCE); + Assert.assertEquals(-6.0, v2.dot(v1), TEST_TOLERANCE); - Assert.assertEquals(6.0, v1.dotProduct(v3), TEST_TOLERANCE); - Assert.assertEquals(6.0, v3.dotProduct(v1), TEST_TOLERANCE); + Assert.assertEquals(6.0, v1.dot(v3), TEST_TOLERANCE); + Assert.assertEquals(6.0, v3.dot(v1), TEST_TOLERANCE); } @Test diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/LineTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/LineTest.java index b0cd043..5779fbd 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/LineTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/LineTest.java @@ -28,7 +28,7 @@ public class LineTest { Assert.assertTrue(l.contains(p1)); Assert.assertTrue(l.contains(Vector3D.linearCombination(1.0, p1, 0.3, l.getDirection()))); Vector3D u = l.getDirection().orthogonal(); - Vector3D v = l.getDirection().crossProduct(u); + Vector3D v = l.getDirection().cross(u); for (double alpha = 0; alpha < 2 * Math.PI; alpha += 0.3) { Assert.assertTrue(! l.contains(p1.add(Vector3D.linearCombination(Math.cos(alpha), u, Math.sin(alpha), v)))); diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java index 90d8b47..efc5a39 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java @@ -910,7 +910,7 @@ public class PolyhedronsSetTest { SubHyperplane<Vector3D> plane = polyset.firstIntersection(origin, line); if (plane != null) { Vector3D intersectionPoint = ((Plane)plane.getHyperplane()).intersection(line); - double dotProduct = direction.dotProduct(intersectionPoint.subtract(origin)); + double dotProduct = direction.dot(intersectionPoint.subtract(origin)); Assert.assertTrue(dotProduct > 0); } } diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java index 6254ef4..c6243d5 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java @@ -365,10 +365,10 @@ public class Vector3DTest { Vector3D v4 = Vector3D.of(4.2, 0.1, -1.8); // act/assert - Assert.assertEquals(0.0, v1.dotProduct(v1.orthogonal()), EPS); - Assert.assertEquals(0.0, v2.dotProduct(v2.orthogonal()), EPS); - Assert.assertEquals(0.0, v3.dotProduct(v3.orthogonal()), EPS); - Assert.assertEquals(0.0, v4.dotProduct(v4.orthogonal()), EPS); + Assert.assertEquals(0.0, v1.dot(v1.orthogonal()), EPS); + Assert.assertEquals(0.0, v2.dot(v2.orthogonal()), EPS); + Assert.assertEquals(0.0, v3.dot(v3.orthogonal()), EPS); + Assert.assertEquals(0.0, v4.dot(v4.orthogonal()), EPS); } @Test @@ -495,16 +495,16 @@ public class Vector3DTest { @Test public void testCrossProduct() { // act/assert - checkVector(Vector3D.PLUS_X.crossProduct(Vector3D.PLUS_Y), 0, 0, 1); - checkVector(Vector3D.PLUS_X.crossProduct(Vector3D.MINUS_Y), 0, 0, -1); + checkVector(Vector3D.PLUS_X.cross(Vector3D.PLUS_Y), 0, 0, 1); + checkVector(Vector3D.PLUS_X.cross(Vector3D.MINUS_Y), 0, 0, -1); - checkVector(Vector3D.MINUS_X.crossProduct(Vector3D.MINUS_Y), 0, 0, 1); - checkVector(Vector3D.MINUS_X.crossProduct(Vector3D.PLUS_Y), 0, 0, -1); + checkVector(Vector3D.MINUS_X.cross(Vector3D.MINUS_Y), 0, 0, 1); + checkVector(Vector3D.MINUS_X.cross(Vector3D.PLUS_Y), 0, 0, -1); - checkVector(Vector3D.of(2, 1, -4).crossProduct(Vector3D.of(3, 1, -1)), 3, -10, -1); + checkVector(Vector3D.of(2, 1, -4).cross(Vector3D.of(3, 1, -1)), 3, -10, -1); double invSqrt6 = 1 / Math.sqrt(6); - checkVector(Vector3D.of(1, 1, 1).crossProduct(Vector3D.of(-1, 0, 1)).normalize(), invSqrt6, - 2 * invSqrt6, invSqrt6); + checkVector(Vector3D.of(1, 1, 1).cross(Vector3D.of(-1, 0, 1)).normalize(), invSqrt6, - 2 * invSqrt6, invSqrt6); } @Test @@ -530,7 +530,7 @@ public class Vector3DTest { Vector3D cNaive = Vector3D.of(u1.getY() * u2.getZ() - u1.getZ() * u2.getY(), u1.getZ() * u2.getX() - u1.getX() * u2.getZ(), u1.getX() * u2.getY() - u1.getY() * u2.getX()); - Vector3D cAccurate = u1.crossProduct(u2); + Vector3D cAccurate = u1.cross(u2); // assert Assert.assertTrue(u3.distance(cNaive) > 2.9 * u3.norm()); @@ -553,7 +553,7 @@ public class Vector3DTest { // act Vector3D cNaive = Vector3D.of(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx); - Vector3D cAccurate = Vector3D.of(ux, uy, uz).crossProduct(Vector3D.of(vx, vy, vz)); + Vector3D cAccurate = Vector3D.of(ux, uy, uz).cross(Vector3D.of(vx, vy, vz)); // assert Assert.assertEquals(0.0, cAccurate.distance(cNaive), 6.0e-15 * cAccurate.norm()); @@ -565,12 +565,12 @@ public class Vector3DTest { // act/assert Vector3D v1 = Vector3D.of(9070467121.0, 4535233560.0, 1); Vector3D v2 = Vector3D.of(9070467123.0, 4535233561.0, 1); - checkVector(v1.crossProduct(v2), -1, 2, 1); + checkVector(v1.cross(v2), -1, 2, 1); double scale = Math.scalb(1.0, 100); Vector3D big1 = Vector3D.linearCombination(scale, v1); Vector3D small2 = Vector3D.linearCombination(1 / scale, v2); - checkVector(big1.crossProduct(small2), -1, 2, 1); + checkVector(big1.cross(small2), -1, 2, 1); } @Test @@ -641,13 +641,13 @@ public class Vector3DTest { Vector3D v3 = Vector3D.of(7, 8, 9); // act/assert - Assert.assertEquals(14, v1.dotProduct(v1), EPS); + Assert.assertEquals(14, v1.dot(v1), EPS); - Assert.assertEquals(-32, v1.dotProduct(v2), EPS); - Assert.assertEquals(-32, v2.dotProduct(v1), EPS); + Assert.assertEquals(-32, v1.dot(v2), EPS); + Assert.assertEquals(-32, v2.dot(v1), EPS); - Assert.assertEquals(18, v1.dotProduct(v3), EPS); - Assert.assertEquals(18, v3.dotProduct(v1), EPS); + Assert.assertEquals(18, v1.dot(v3), EPS); + Assert.assertEquals(18, v3.dot(v1), EPS); } @Test @@ -666,7 +666,7 @@ public class Vector3DTest { // act double sNaive = u1.getX() * u2.getX() + u1.getY() * u2.getY() + u1.getZ() * u2.getZ(); - double sAccurate = u1.dotProduct(u2); + double sAccurate = u1.dot(u2); // assert Assert.assertEquals(0.0, sNaive, 1.0e-30); @@ -689,7 +689,7 @@ public class Vector3DTest { // act double sNaive = ux * vx + uy * vy + uz * vz; - double sAccurate = Vector3D.of(ux, uy, uz).dotProduct(Vector3D.of(vx, vy, vz)); + double sAccurate = Vector3D.of(ux, uy, uz).dot(Vector3D.of(vx, vy, vz)); // assert Assert.assertEquals(sNaive, sAccurate, 2.5e-16 * sAccurate); 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 35175ea..0283700 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 @@ -197,7 +197,7 @@ public class QuaternionRotationTest { Assert.assertTrue(angle <= Geometry.PI); double expected = PlaneAngleRadians.normalizeBetweenMinusPiAndPi(theta); - if (PLUS_DIAGONAL.dotProduct(rot.getAxis()) < 0) { + if (PLUS_DIAGONAL.dot(rot.getAxis()) < 0) { // if the axis ended up being flipped, then negate the expected angle expected *= -1; } @@ -1116,8 +1116,8 @@ public class QuaternionRotationTest { // assert Vector3D axis = q.getAxis(); - Assert.assertEquals(0.0, axis.dotProduct(u1), EPS); - Assert.assertEquals(0.0, axis.dotProduct(u2), EPS); + Assert.assertEquals(0.0, axis.dot(u1), EPS); + Assert.assertEquals(0.0, axis.dot(u2), EPS); Assert.assertEquals(Geometry.PI, q.getAngle(), EPS); EuclideanTestUtils.assertCoordinatesEqual(Vector3D.of(0, -2, 0), q.apply(u1), EPS); @@ -1320,12 +1320,12 @@ public class QuaternionRotationTest { Assert.assertEquals(1.0, transformedY.norm(), EPS); Assert.assertEquals(1.0, transformedZ.norm(), EPS); - Assert.assertEquals(0.0, transformedX.dotProduct(transformedY), EPS); - Assert.assertEquals(0.0, transformedX.dotProduct(transformedZ), EPS); - Assert.assertEquals(0.0, transformedY.dotProduct(transformedZ), EPS); + Assert.assertEquals(0.0, transformedX.dot(transformedY), EPS); + Assert.assertEquals(0.0, transformedX.dot(transformedZ), EPS); + Assert.assertEquals(0.0, transformedY.dot(transformedZ), EPS); EuclideanTestUtils.assertCoordinatesEqual(transformedZ.normalize(), - transformedX.normalize().crossProduct(transformedY.normalize()), EPS); + transformedX.normalize().cross(transformedY.normalize()), EPS); Assert.assertEquals(1.0, q.getQuaternion().norm(), EPS); }); diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java index e106537..5a4c268 100644 --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java @@ -360,20 +360,20 @@ public class Vector2DTest { Vector2D v3 = Vector2D.of(-1, 0); // act/assert - Assert.assertEquals(2, v1.dotProduct(v1), EPS); - Assert.assertEquals(41, v2.dotProduct(v2), EPS); - Assert.assertEquals(1, v3.dotProduct(v3), EPS); + Assert.assertEquals(2, v1.dot(v1), EPS); + Assert.assertEquals(41, v2.dot(v2), EPS); + Assert.assertEquals(1, v3.dot(v3), EPS); - Assert.assertEquals(9, v1.dotProduct(v2), EPS); - Assert.assertEquals(9, v2.dotProduct(v1), EPS); + Assert.assertEquals(9, v1.dot(v2), EPS); + Assert.assertEquals(9, v2.dot(v1), EPS); - Assert.assertEquals(-1, v1.dotProduct(v3), EPS); - Assert.assertEquals(-1, v3.dotProduct(v1), EPS); + Assert.assertEquals(-1, v1.dot(v3), EPS); + Assert.assertEquals(-1, v3.dot(v1), EPS); - Assert.assertEquals(1, Vector2D.PLUS_X.dotProduct(Vector2D.PLUS_X), EPS); - Assert.assertEquals(0, Vector2D.PLUS_X.dotProduct(Vector2D.PLUS_Y), EPS); - Assert.assertEquals(-1, Vector2D.PLUS_X.dotProduct(Vector2D.MINUS_X), EPS); - Assert.assertEquals(0, Vector2D.PLUS_X.dotProduct(Vector2D.MINUS_Y), EPS); + Assert.assertEquals(1, Vector2D.PLUS_X.dot(Vector2D.PLUS_X), EPS); + Assert.assertEquals(0, Vector2D.PLUS_X.dot(Vector2D.PLUS_Y), EPS); + Assert.assertEquals(-1, Vector2D.PLUS_X.dot(Vector2D.MINUS_X), EPS); + Assert.assertEquals(0, Vector2D.PLUS_X.dot(Vector2D.MINUS_Y), EPS); } @Test @@ -406,7 +406,7 @@ public class Vector2DTest { // assert Assert.assertEquals(1.0, ortho.norm(), EPS); - Assert.assertEquals(0.0, v.dotProduct(ortho), EPS); + Assert.assertEquals(0.0, v.dot(ortho), EPS); } } @@ -523,9 +523,9 @@ public class Vector2DTest { Vector2D p5 = Vector2D.of(2, 1); // act/assert - Assert.assertEquals(0.0, p3.crossProduct(p1, p2), EPS); - Assert.assertEquals(1.0, p4.crossProduct(p1, p2), EPS); - Assert.assertEquals(-1.0, p5.crossProduct(p1, p2), EPS); + Assert.assertEquals(0.0, p3.cross(p1, p2), EPS); + Assert.assertEquals(1.0, p4.cross(p1, p2), EPS); + Assert.assertEquals(-1.0, p5.cross(p1, p2), EPS); } @Test diff --git a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/AklToussaintHeuristic.java b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/AklToussaintHeuristic.java index 4616553..af3c034 100644 --- a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/AklToussaintHeuristic.java +++ b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/AklToussaintHeuristic.java @@ -129,7 +129,7 @@ public final class AklToussaintHeuristic { } // get the location of the point relative to the first two vertices - final double last = v0.crossProduct(v1, v2); + final double last = v0.cross(v1, v2); final int size = quadrilateralPoints.size(); // loop through the rest of the vertices for (int i = 1; i < size; i++) { @@ -143,7 +143,7 @@ public final class AklToussaintHeuristic { // do side of line test: multiply the last location with this location // if they are the same sign then the operation will yield a positive result // -x * -y = +xy, x * y = +xy, -x * y = -xy, x * -y = -xy - if (last * v0.crossProduct(v1, v2) < 0) { + if (last * v0.cross(v1, v2) < 0) { return false; } } diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Circle.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Circle.java index 564a69b..9d3c932 100644 --- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Circle.java +++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Circle.java @@ -68,7 +68,7 @@ public class Circle implements Hyperplane<S2Point>, Embedding<S2Point, S1Point> * @param tolerance tolerance below which close sub-arcs are merged together */ public Circle(final S2Point first, final S2Point second, final double tolerance) { - reset(first.getVector().crossProduct(second.getVector())); + reset(first.getVector().cross(second.getVector())); this.tolerance = tolerance; } @@ -109,7 +109,7 @@ public class Circle implements Hyperplane<S2Point>, Embedding<S2Point, S1Point> public void reset(final Vector3D newPole) { this.pole = newPole.normalize(); this.x = newPole.orthogonal(); - this.y = newPole.crossProduct(x).normalize(); + this.y = newPole.cross(x).normalize(); } /** Revert the instance. @@ -160,7 +160,7 @@ public class Circle implements Hyperplane<S2Point>, Embedding<S2Point, S1Point> * @see #toSubSpace(Point) */ public double getPhase(final Vector3D direction) { - return Math.PI + Math.atan2(-direction.dotProduct(y), -direction.dotProduct(x)); + return Math.PI + Math.atan2(-direction.dot(y), -direction.dot(x)); } /** {@inheritDoc} @@ -275,7 +275,7 @@ public class Circle implements Hyperplane<S2Point>, Embedding<S2Point, S1Point> @Override public boolean sameOrientationAs(final Hyperplane<S2Point> other) { final Circle otherC = (Circle) other; - return pole.dotProduct(otherC.pole) >= 0.0; + return pole.dot(otherC.pole) >= 0.0; } /** Get a {@link org.apache.commons.geometry.core.partitioning.Transform diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/PropertiesComputer.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/PropertiesComputer.java index 2781da4..0bd4dca 100644 --- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/PropertiesComputer.java +++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/PropertiesComputer.java @@ -110,8 +110,8 @@ class PropertiesComputer implements BSPTreeVisitor<S2Point> { final Vector3D previousPole = e.getCircle().getPole(); final Vector3D nextPole = e.getEnd().getOutgoing().getCircle().getPole(); final Vector3D point = e.getEnd().getLocation().getVector(); - double alpha = Math.atan2(nextPole.dotProduct(point.crossProduct(previousPole)), - - nextPole.dotProduct(previousPole)); + double alpha = Math.atan2(nextPole.dot(point.cross(previousPole)), + - nextPole.dot(previousPole)); if (alpha < 0) { alpha += Geometry.TWO_PI; } diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSet.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSet.java index 9f09d77..647e448 100644 --- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSet.java +++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/SphericalPolygonsSet.java @@ -157,7 +157,7 @@ public class SphericalPolygonsSet extends AbstractRegion<S2Point, S1Point> { private static S2Point[] createRegularPolygonVertices(final Vector3D center, final Vector3D meridian, final double outsideRadius, final int n) { final S2Point[] array = new S2Point[n]; - final QuaternionRotation r0 = QuaternionRotation.fromAxisAngle(center.crossProduct(meridian), + final QuaternionRotation r0 = QuaternionRotation.fromAxisAngle(center.cross(meridian), outsideRadius); array[0] = S2Point.ofVector(r0.apply(center)); diff --git a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/CircleTest.java b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/CircleTest.java index 6fa4464..de3de2b 100644 --- a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/CircleTest.java +++ b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/CircleTest.java @@ -53,7 +53,7 @@ public class CircleTest { Assert.assertEquals(0.5 * Math.PI, circle.getXAxis().angle(circle.getPole()), 1.0e-10); Assert.assertEquals(0.5 * Math.PI, circle.getPole().angle(circle.getYAxis()), 1.0e-10); Assert.assertEquals(0.0, - circle.getPole().distance(circle.getXAxis().crossProduct(circle.getYAxis())), + circle.getPole().distance(circle.getXAxis().cross(circle.getYAxis())), 1.0e-10); } @@ -67,7 +67,7 @@ public class CircleTest { Assert.assertEquals(0.5 * Math.PI, reversed.getXAxis().angle(reversed.getPole()), 1.0e-10); Assert.assertEquals(0.5 * Math.PI, reversed.getPole().angle(reversed.getYAxis()), 1.0e-10); Assert.assertEquals(0.0, - reversed.getPole().distance(reversed.getXAxis().crossProduct(reversed.getYAxis())), + reversed.getPole().distance(reversed.getXAxis().cross(reversed.getYAxis())), 1.0e-10); Assert.assertEquals(0, circle.getXAxis().angle(reversed.getXAxis()), 1.0e-10); @@ -84,8 +84,8 @@ public class CircleTest { Vector3D p = Vector3D.of(1, 2, -4); Vector3D samePhase = circle.getPointAt(circle.getPhase(p)); Assert.assertEquals(0.0, - circle.getPole().crossProduct(p).angle( - circle.getPole().crossProduct(samePhase)), + circle.getPole().cross(p).angle( + circle.getPole().cross(samePhase)), 1.0e-10); Assert.assertEquals(0.5 * Math.PI, circle.getPole().angle(samePhase), 1.0e-10); Assert.assertEquals(circle.getPhase(p), circle.getPhase(samePhase), 1.0e-10);
