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
The following commit(s) were added to refs/heads/master by this push: new de8ff25 GEOMETRY-6: Making CartesianXD fields private new 0f636b5 Merge branch 'GEOMETRY-6__matt' de8ff25 is described below commit de8ff25d9f372f7f8f97ce5d01122019ef884b54 Author: Matt Juntunen <matt.juntu...@hotmail.com> AuthorDate: Tue May 22 15:17:00 2018 -0400 GEOMETRY-6: Making CartesianXD fields private --- .../geometry/euclidean/oned/Cartesian1D.java | 2 +- .../commons/geometry/euclidean/oned/Point1D.java | 22 ++--- .../commons/geometry/euclidean/oned/Vector1D.java | 38 ++++---- .../geometry/euclidean/threed/Cartesian3D.java | 6 +- .../commons/geometry/euclidean/threed/Point3D.java | 42 ++++----- .../geometry/euclidean/threed/Vector3D.java | 102 +++++++++++---------- .../geometry/euclidean/twod/Cartesian2D.java | 4 +- .../commons/geometry/euclidean/twod/Point2D.java | 28 +++--- .../commons/geometry/euclidean/twod/Vector2D.java | 71 +++++++------- 9 files changed, 164 insertions(+), 151 deletions(-) diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Cartesian1D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Cartesian1D.java index 7cfbf9d..53e2879 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Cartesian1D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Cartesian1D.java @@ -27,7 +27,7 @@ public abstract class Cartesian1D implements Spatial { private static final long serialVersionUID = -1178039568877797126L; /** Abscissa (coordinate value). */ - protected final double x; + private final double x; /** * Simple constructor. diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Point1D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Point1D.java index 8983598..eeeed9f 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Point1D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Point1D.java @@ -63,13 +63,13 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D /** {@inheritDoc} */ @Override public double distance(Point1D p) { - return Math.abs(p.x - x); + return Math.abs(p.getX() - getX()); } /** {@inheritDoc} */ @Override public Vector1D subtract(Point1D p) { - return Vector1D.of(x - p.x); + return Vector1D.of(getX() - p.getX()); } /** {@inheritDoc} */ @@ -81,7 +81,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D /** {@inheritDoc} */ @Override public Point1D add(Vector1D v) { - return new Point1D(x + v.x); + return new Point1D(getX() + v.getX()); } /** @@ -95,7 +95,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D if (isNaN()) { return 7785; } - return 997 * Double.hashCode(x); + return 997 * Double.hashCode(getX()); } /** @@ -129,7 +129,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D return this.isNaN(); } - return x == rhs.x; + return getX() == rhs.getX(); } return false; } @@ -137,7 +137,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D /** {@inheritDoc} */ @Override public String toString() { - return "(" + x + ")"; + return "(" + getX() + ")"; } /** Returns a point with the given coordinate value. @@ -153,7 +153,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D * @return point instance */ public static Point1D of(Cartesian1D value) { - return new Point1D(value.x); + return new Point1D(value.getX()); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -176,7 +176,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D * @see {@link Vector1D#linearCombination(double, Vector1D)} */ public static Point1D vectorCombination(double a, Cartesian1D c) { - return new Point1D(a * c.x); + return new Point1D(a * c.getX()); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -202,7 +202,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D */ public static Point1D vectorCombination(double a1, Cartesian1D c1, double a2, Cartesian1D c2) { return new Point1D( - LinearCombination.value(a1, c1.x, a2, c2.x)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX())); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -231,7 +231,7 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D public static Point1D vectorCombination(double a1, Cartesian1D c1, double a2, Cartesian1D c2, double a3, Cartesian1D c3) { return new Point1D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX())); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -262,6 +262,6 @@ public final class Point1D extends Cartesian1D implements EuclideanPoint<Point1D public static Point1D vectorCombination(double a1, Cartesian1D c1, double a2, Cartesian1D c2, double a3, Cartesian1D c3, double a4, Cartesian1D c4) { return new Point1D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x, a4, c4.x)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX(), a4, c4.getX())); } } 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 f2adbad..1e6ab7d 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 @@ -74,13 +74,13 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public double getNorm() { - return Math.abs(x); + return Math.abs(getX()); } /** {@inheritDoc} */ @Override public double getNormSq() { - return x * x; + return getX() * getX(); } /** {@inheritDoc} */ @@ -92,31 +92,31 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public Vector1D add(Vector1D v) { - return new Vector1D(x + v.x); + return new Vector1D(getX() + v.getX()); } /** {@inheritDoc} */ @Override public Vector1D add(double factor, Vector1D v) { - return new Vector1D(x + (factor * v.x)); + return new Vector1D(getX() + (factor * v.getX())); } /** {@inheritDoc} */ @Override public Vector1D subtract(Vector1D v) { - return new Vector1D(x - v.x); + return new Vector1D(getX() - v.getX()); } /** {@inheritDoc} */ @Override public Vector1D subtract(double factor, Vector1D v) { - return new Vector1D(x - (factor * v.x)); + return new Vector1D(getX() - (factor * v.getX())); } /** {@inheritDoc} */ @Override public Vector1D negate() { - return new Vector1D(-x); + return new Vector1D(-getX()); } /** {@inheritDoc} */ @@ -132,7 +132,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public Vector1D scalarMultiply(double a) { - return new Vector1D(a * x); + return new Vector1D(a * getX()); } /** {@inheritDoc} */ @@ -144,7 +144,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public double distance(Vector1D v) { - return Math.abs(v.x - x); + return Math.abs(v.getX() - getX()); } /** {@inheritDoc} */ @@ -156,14 +156,14 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public double distanceSq(Vector1D v) { - final double dx = v.x - x; + final double dx = v.getX() - getX(); return dx * dx; } /** {@inheritDoc} */ @Override public double dotProduct(Vector1D v) { - return x * v.x; + return getX() * v.getX(); } /** @@ -177,7 +177,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point if (isNaN()) { return 857; } - return 403 * Double.hashCode(x); + return 403 * Double.hashCode(getX()); } /** @@ -212,7 +212,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point return this.isNaN(); } - return x == rhs.x; + return getX() == rhs.getX(); } return false; } @@ -220,7 +220,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public String toString() { - return "{" + x + "}"; + return "{" + getX() + "}"; } /** Returns a vector with the given coordinate value. @@ -236,7 +236,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point * @return vector instance */ public static Vector1D of(Cartesian1D value) { - return new Vector1D(value.x); + return new Vector1D(value.getX()); } /** Returns a vector consisting of the linear combination of the inputs. @@ -252,7 +252,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point * @return vector with coordinates calculated by {@code a * c} */ public static Vector1D linearCombination(double a, Cartesian1D c) { - return new Vector1D(a * c.x); + return new Vector1D(a * c.getX()); } /** Returns a vector consisting of the linear combination of the inputs. @@ -271,7 +271,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point */ public static Vector1D linearCombination(double a1, Cartesian1D c1, double a2, Cartesian1D c2) { return new Vector1D( - LinearCombination.value(a1, c1.x, a2, c2.x)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX())); } /** Returns a vector consisting of the linear combination of the inputs. @@ -293,7 +293,7 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point public static Vector1D linearCombination(double a1, Cartesian1D c1, double a2, Cartesian1D c2, double a3, Cartesian1D c3) { return new Vector1D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX())); } /** Returns a vector consisting of the linear combination of the inputs. @@ -317,6 +317,6 @@ public final class Vector1D extends Cartesian1D implements EuclideanVector<Point public static Vector1D linearCombination(double a1, Cartesian1D c1, double a2, Cartesian1D c2, double a3, Cartesian1D c3, double a4, Cartesian1D c4) { return new Vector1D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x, a4, c4.x)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX(), a4, c4.getX())); } } diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Cartesian3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Cartesian3D.java index b57c108..4640b23 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Cartesian3D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Cartesian3D.java @@ -28,13 +28,13 @@ public abstract class Cartesian3D implements Spatial { private static final long serialVersionUID = 6249091865814886817L; /** Abscissa (first coordinate value) */ - protected final double x; + private final double x; /** Ordinate (second coordinate value) */ - protected final double y; + private final double y; /** Height (third coordinate value)*/ - protected final double z; + private final double z; /** Simple constructor. * @param x abscissa (first coordinate value) diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Point3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Point3D.java index a91f03e..46de33d 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Point3D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Point3D.java @@ -57,7 +57,7 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D /** {@inheritDoc} */ @Override public Vector3D asVector() { - return Vector3D.of(x, y, z); + return Vector3D.of(getX(), getY(), getZ()); } /** {@inheritDoc} */ @@ -70,9 +70,9 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D @Override public Vector3D subtract(Point3D p) { return new Vector3D( - x - p.x, - y - p.y, - z - p.z + getX() - p.getX(), + getY() - p.getY(), + getZ() - p.getZ() ); } @@ -86,9 +86,9 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D @Override public Point3D add(Vector3D v) { return new Point3D( - x + v.x, - y + v.y, - z + v.z + getX() + v.getX(), + getY() + v.getY(), + getZ() + v.getZ() ); } @@ -103,7 +103,7 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D if (isNaN()) { return 642; } - return 643 * (164 * Double.hashCode(x) + 3 * Double.hashCode(y) + Double.hashCode(z)); + return 643 * (164 * Double.hashCode(getX()) + 3 * Double.hashCode(getY()) + Double.hashCode(getZ())); } /** Test for the equality of two points. @@ -137,7 +137,7 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D return this.isNaN(); } - return (x == rhs.x) && (y == rhs.y) && (z == rhs.z); + return (getX() == rhs.getX()) && (getY() == rhs.getY()) && (getZ() == rhs.getZ()); } return false; } @@ -145,7 +145,7 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D /** {@inheritDoc} */ @Override public String toString() { - return "(" + x + "; " + y + "; " + z + ")"; + return "(" + getX() + "; " + getY() + "; " + getZ() + ")"; } /** Returns a point with the given coordinate values @@ -163,7 +163,7 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D * @return point instance */ public static Point3D of(Cartesian3D value) { - return new Point3D(value.x, value.y, value.z); + return new Point3D(value.getX(), value.getY(), value.getZ()); } /** Creates a point from the coordinates in the given 3-element array. @@ -197,7 +197,7 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D * @return point with coordinates calculated by {@code a * c} */ public static Point3D vectorCombination(double a, Cartesian3D c) { - return new Point3D(a * c.x, a * c.y, a * c.z); + return new Point3D(a * c.getX(), a * c.getY(), a * c.getZ()); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -222,9 +222,9 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D */ public static Point3D vectorCombination(double a1, Cartesian3D c1, double a2, Cartesian3D c2) { return new Point3D( - LinearCombination.value(a1, c1.x, a2, c2.x), - LinearCombination.value(a1, c1.y, a2, c2.y), - LinearCombination.value(a1, c1.z, a2, c2.z)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY()), + LinearCombination.value(a1, c1.getZ(), a2, c2.getZ())); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -252,9 +252,9 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D public static Point3D vectorCombination(double a1, Cartesian3D c1, double a2, Cartesian3D c2, double a3, Cartesian3D c3) { return new Point3D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x), - LinearCombination.value(a1, c1.y, a2, c2.y, a3, c3.y), - LinearCombination.value(a1, c1.z, a2, c2.z, a3, c3.z)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY(), a3, c3.getY()), + LinearCombination.value(a1, c1.getZ(), a2, c2.getZ(), a3, c3.getZ())); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -284,8 +284,8 @@ public final class Point3D extends Cartesian3D implements EuclideanPoint<Point3D public static Point3D vectorCombination(double a1, Cartesian3D c1, double a2, Cartesian3D c2, double a3, Cartesian3D c3, double a4, Cartesian3D c4) { return new Point3D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x, a4, c4.x), - LinearCombination.value(a1, c1.y, a2, c2.y, a3, c3.y, a4, c4.y), - LinearCombination.value(a1, c1.z, a2, c2.z, a3, c3.z, a4, c4.z)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX(), a4, c4.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY(), a3, c3.getY(), a4, c4.getY()), + LinearCombination.value(a1, c1.getZ(), a2, c2.getZ(), a3, c3.getZ(), a4, c4.getZ())); } } 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 9e9d39d..5a9e0ac 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 @@ -83,19 +83,22 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve /** {@inheritDoc} */ @Override public Point3D asPoint() { - return Point3D.of(x, y, z); + return Point3D.of(getX(), getY(), getZ()); } /** {@inheritDoc} */ @Override public double getNorm1() { - return Math.abs(x) + Math.abs(y) + Math.abs(z); + return Math.abs(getX()) + Math.abs(getY()) + Math.abs(getZ()); } /** {@inheritDoc} */ @Override public double getNorm() { // there are no cancellation problems here, so we use the straightforward formula + final double x = getX(); + final double y = getY(); + final double z = getZ(); return Math.sqrt ((x * x) + (y * y) + (z * z)); } @@ -103,36 +106,39 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve @Override public double getNormSq() { // there are no cancellation problems here, so we use the straightforward formula + final double x = getX(); + final double y = getY(); + final double z = getZ(); return (x * x) + (y * y) + (z * z); } /** {@inheritDoc} */ @Override public double getNormInf() { - return Math.max(Math.max(Math.abs(x), Math.abs(y)), Math.abs(z)); + return Math.max(Math.max(Math.abs(getX()), Math.abs(getY())), Math.abs(getZ())); } /** Get the azimuth of the vector. * @return azimuth (α) of the vector, between -π and +π */ public double getAlpha() { - return Math.atan2(y, x); + return Math.atan2(getY(), getX()); } /** Get the elevation of the vector. * @return elevation (δ) of the vector, between -π/2 and +π/2 */ public double getDelta() { - return Math.asin(z / getNorm()); + return Math.asin(getZ() / getNorm()); } /** {@inheritDoc} */ @Override public Vector3D add(Vector3D v) { return new Vector3D( - x + v.x, - y + v.y, - z + v.z + getX() + v.getX(), + getY() + v.getY(), + getZ() + v.getZ() ); } @@ -140,9 +146,9 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve @Override public Vector3D add(double factor, Vector3D v) { return new Vector3D( - x + (factor * v.x), - y + (factor * v.y), - z + (factor * v.z) + getX() + (factor * v.getX()), + getY() + (factor * v.getY()), + getZ() + (factor * v.getZ()) ); } @@ -150,9 +156,9 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve @Override public Vector3D subtract(Vector3D v) { return new Vector3D( - x - v.x, - y - v.y, - z - v.z + getX() - v.getX(), + getY() - v.getY(), + getZ() - v.getZ() ); } @@ -160,16 +166,16 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve @Override public Vector3D subtract(double factor, Vector3D v) { return new Vector3D( - x - (factor * v.x), - y - (factor * v.y), - z - (factor * v.z) + getX() - (factor * v.getX()), + getY() - (factor * v.getY()), + getZ() - (factor * v.getZ()) ); } /** {@inheritDoc} */ @Override public Vector3D negate() { - return new Vector3D(-x, -y, -z); + return new Vector3D(-getX(), -getY(), -getZ()); } /** {@inheritDoc} */ @@ -203,6 +209,10 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve throw new IllegalStateException(ZERO_NORM_MSG); } + final double x = getX(); + final double y = getY(); + final double z = getZ(); + if (Math.abs(x) <= threshold) { double inverse = 1 / Math.sqrt(y * y + z * z); return new Vector3D(0, inverse * z, -inverse * y); @@ -250,23 +260,23 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve * @return the cross product this ^ v as a new Cartesian3D */ public Vector3D crossProduct(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)); + return new Vector3D(LinearCombination.value(getY(), v.getZ(), -getZ(), v.getY()), + LinearCombination.value(getZ(), v.getX(), -getX(), v.getZ()), + LinearCombination.value(getX(), v.getY(), -getY(), v.getX())); } /** {@inheritDoc} */ @Override public Vector3D scalarMultiply(double a) { - return new Vector3D(a * x, a * y, a * z); + return new Vector3D(a * getX(), a * getY(), a * getZ()); } /** {@inheritDoc} */ @Override public double distance1(Vector3D v) { - double dx = Math.abs(v.x - x); - double dy = Math.abs(v.y - y); - double dz = Math.abs(v.z - z); + double dx = Math.abs(v.getX() - getX()); + double dy = Math.abs(v.getY() - getY()); + double dz = Math.abs(v.getZ() - getZ()); return dx + dy + dz; } @@ -280,9 +290,9 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve /** {@inheritDoc} */ @Override public double distanceInf(Vector3D v) { - double dx = Math.abs(v.x - x); - double dy = Math.abs(v.y - y); - double dz = Math.abs(v.z - z); + double dx = Math.abs(v.getX() - getX()); + double dy = Math.abs(v.getY() - getY()); + double dz = Math.abs(v.getZ() - getZ()); return Math.max(Math.max(dx, dy), dz); } @@ -290,9 +300,9 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve /** {@inheritDoc} */ @Override public double distanceSq(Vector3D v) { - double dx = v.x - x; - double dy = v.y - y; - double dz = v.z - z; + double dx = v.getX() - getX(); + double dy = v.getY() - getY(); + double dz = v.getZ() - getZ(); return (dx * dx) + (dy * dy) + (dz * dz); } @@ -307,7 +317,7 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve */ @Override public double dotProduct(Vector3D v) { - return LinearCombination.value(x, v.x, y, v.y, z, v.z); + return LinearCombination.value(getX(), v.getX(), getY(), v.getY(), getZ(), v.getZ()); } /** @@ -321,7 +331,7 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve if (isNaN()) { return 642; } - return 643 * (164 * Double.hashCode(x) + 3 * Double.hashCode(y) + Double.hashCode(z)); + return 643 * (164 * Double.hashCode(getX()) + 3 * Double.hashCode(getY()) + Double.hashCode(getZ())); } /** @@ -355,7 +365,7 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve return this.isNaN(); } - return (x == rhs.x) && (y == rhs.y) && (z == rhs.z); + return (getX() == rhs.getX()) && (getY() == rhs.getY()) && (getZ() == rhs.getZ()); } return false; } @@ -363,7 +373,7 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve /** {@inheritDoc} */ @Override public String toString() { - return "{" + x + "; " + y + "; " + z + "}"; + return "{" + getX() + "; " + getY() + "; " + getZ() + "}"; } /** Computes the dot product between to vectors. This method simply @@ -414,7 +424,7 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve * @return vector instance */ public static Vector3D of(Cartesian3D value) { - return new Vector3D(value.x, value.y, value.z); + return new Vector3D(value.getX(), value.getY(), value.getZ()); } /** Creates a vector from the coordinates in the given 3-element array. @@ -461,7 +471,7 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve * @return vector with coordinates calculated by {@code a * c} */ public static Vector3D linearCombination(double a, Cartesian3D c) { - return new Vector3D(a * c.x, a * c.y, a * c.z); + return new Vector3D(a * c.getX(), a * c.getY(), a * c.getZ()); } /** Returns a vector consisting of the linear combination of the inputs. @@ -480,9 +490,9 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve */ public static Vector3D linearCombination(double a1, Cartesian3D c1, double a2, Cartesian3D c2) { return new Vector3D( - LinearCombination.value(a1, c1.x, a2, c2.x), - LinearCombination.value(a1, c1.y, a2, c2.y), - LinearCombination.value(a1, c1.z, a2, c2.z)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY()), + LinearCombination.value(a1, c1.getZ(), a2, c2.getZ())); } /** Returns a vector consisting of the linear combination of the inputs. @@ -504,9 +514,9 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve public static Vector3D linearCombination(double a1, Cartesian3D c1, double a2, Cartesian3D c2, double a3, Cartesian3D c3) { return new Vector3D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x), - LinearCombination.value(a1, c1.y, a2, c2.y, a3, c3.y), - LinearCombination.value(a1, c1.z, a2, c2.z, a3, c3.z)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY(), a3, c3.getY()), + LinearCombination.value(a1, c1.getZ(), a2, c2.getZ(), a3, c3.getZ())); } /** Returns a vector consisting of the linear combination of the inputs. @@ -530,8 +540,8 @@ public class Vector3D extends Cartesian3D implements EuclideanVector<Point3D, Ve public static Vector3D linearCombination(double a1, Cartesian3D c1, double a2, Cartesian3D c2, double a3, Cartesian3D c3, double a4, Cartesian3D c4) { return new Vector3D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x, a4, c4.x), - LinearCombination.value(a1, c1.y, a2, c2.y, a3, c3.y, a4, c4.y), - LinearCombination.value(a1, c1.z, a2, c2.z, a3, c3.z, a4, c4.z)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX(), a4, c4.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY(), a3, c3.getY(), a4, c4.getY()), + LinearCombination.value(a1, c1.getZ(), a2, c2.getZ(), a3, c3.getZ(), a4, c4.getZ())); } } diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Cartesian2D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Cartesian2D.java index 29aedcd..ba3b462 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Cartesian2D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Cartesian2D.java @@ -28,10 +28,10 @@ public abstract class Cartesian2D implements Spatial { private static final long serialVersionUID = 2918583078965478552L; /** Abscissa (first coordinate) */ - protected final double x; + private final double x; /** Ordinate (second coordinate) */ - protected final double y; + private final double y; /** * Simple Cartesian constructor. diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Point2D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Point2D.java index 2d73d72..e062b89 100644 --- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Point2D.java +++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Point2D.java @@ -55,7 +55,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D /** {@inheritDoc} */ @Override public Vector2D asVector() { - return new Vector2D(x, y); + return new Vector2D(getX(), getY()); } /** {@inheritDoc} */ @@ -67,7 +67,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D /** {@inheritDoc} */ @Override public Vector2D subtract(Point2D p) { - return Vector2D.of(x - p.x, y - p.y); + return Vector2D.of(getX() - p.getX(), getY() - p.getY()); } /** {@inheritDoc} */ @@ -79,7 +79,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D /** {@inheritDoc} */ @Override public Point2D add(Vector2D v) { - return new Point2D(x + v.x, y + v.y); + return new Point2D(getX() + v.getX(), getY() + v.getY()); } /** @@ -93,7 +93,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D if (isNaN()) { return 542; } - return 122 * (76 * Double.hashCode(x) + Double.hashCode(y)); + return 122 * (76 * Double.hashCode(getX()) + Double.hashCode(getY())); } /** Test for the equality of two points. @@ -126,7 +126,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D return this.isNaN(); } - return (x == rhs.x) && (y == rhs.y); + return (getX() == rhs.getX()) && (getY() == rhs.getY()); } return false; } @@ -134,7 +134,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D /** {@inheritDoc} */ @Override public String toString() { - return "(" + x + "; " + y + ")"; + return "(" + getX() + "; " + getY() + ")"; } /** Returns a point with the given coordinate values @@ -151,7 +151,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D * @return point instance */ public static Point2D of(Cartesian2D value) { - return new Point2D(value.x, value.y); + return new Point2D(value.getX(), value.getY()); } /** Returns a point with the coordinates from the given 2-element array. @@ -185,7 +185,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D * @return point with coordinates calculated by {@code a * c} */ public static Point2D vectorCombination(double a, Cartesian2D c) { - return new Point2D(a * c.x, a * c.y); + return new Point2D(a * c.getX(), a * c.getY()); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -210,8 +210,8 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D */ public static Point2D vectorCombination(double a1, Cartesian2D c1, double a2, Cartesian2D c2) { return new Point2D( - LinearCombination.value(a1, c1.x, a2, c2.x), - LinearCombination.value(a1, c1.y, a2, c2.y)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY())); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -239,8 +239,8 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D public static Point2D vectorCombination(double a1, Cartesian2D c1, double a2, Cartesian2D c2, double a3, Cartesian2D c3) { return new Point2D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x), - LinearCombination.value(a1, c1.y, a2, c2.y, a3, c3.y)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY(), a3, c3.getY())); } /** Returns a point with coordinates calculated by multiplying each input coordinate @@ -270,7 +270,7 @@ public final class Point2D extends Cartesian2D implements EuclideanPoint<Point2D public static Point2D vectorCombination(double a1, Cartesian2D c1, double a2, Cartesian2D c2, double a3, Cartesian2D c3, double a4, Cartesian2D c4) { return new Point2D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x, a4, c4.x), - LinearCombination.value(a1, c1.y, a2, c2.y, a3, c3.y, a4, c4.y)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX(), a4, c4.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY(), a3, c3.getY(), a4, c4.getY())); } } 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 1a7e5bd..0bc84d2 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 @@ -68,17 +68,16 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point /** Get the vector coordinates as a dimension 2 array. * @return vector coordinates - * @see #Cartesian2D(double[]) */ @Override public double[] toArray() { - return new double[] { x, y }; + return new double[] { getX(), getY() }; } /** {@inheritDoc} */ @Override public Point2D asPoint() { - return new Point2D(x, y); + return new Point2D(getX(), getY()); } /** {@inheritDoc} */ @@ -90,55 +89,59 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public double getNorm1() { - return Math.abs(x) + Math.abs(y); + return Math.abs(getX()) + Math.abs(getY()); } /** {@inheritDoc} */ @Override public double getNorm() { + final double x = getX(); + final double y = getY(); return Math.sqrt ((x * x) + (y * y)); } /** {@inheritDoc} */ @Override public double getNormSq() { + final double x = getX(); + final double y = getY(); return (x * x) + (y * y); } /** {@inheritDoc} */ @Override public double getNormInf() { - return Math.max(Math.abs(x), Math.abs(y)); + return Math.max(Math.abs(getX()), Math.abs(getY())); } /** {@inheritDoc} */ @Override public Vector2D add(Vector2D v) { - return new Vector2D(x + v.x, y + v.y); + return new Vector2D(getX() + v.getX(), getY() + v.getY()); } /** {@inheritDoc} */ @Override public Vector2D add(double factor, Vector2D v) { - return new Vector2D(x + (factor * v.x), y + (factor * v.y)); + return new Vector2D(getX() + (factor * v.getX()), getY() + (factor * v.getY())); } /** {@inheritDoc} */ @Override public Vector2D subtract(Vector2D v) { - return new Vector2D(x - v.x, y - v.y); + return new Vector2D(getX() - v.getX(), getY() - v.getY()); } /** {@inheritDoc} */ @Override public Vector2D subtract(double factor, Vector2D v) { - return new Vector2D(x - (factor * v.x), y - (factor * v.y)); + return new Vector2D(getX() - (factor * v.getX()), getY() - (factor * v.getY())); } /** {@inheritDoc} */ @Override public Vector2D negate() { - return new Vector2D(-x, -y); + return new Vector2D(-getX(), -getY()); } /** {@inheritDoc} */ @@ -154,14 +157,14 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public Vector2D scalarMultiply(double a) { - return new Vector2D(a * x, a * y); + return new Vector2D(a * getX(), a * getY()); } /** {@inheritDoc} */ @Override public double distance1(Vector2D v) { - double dx = Math.abs(x - v.x); - double dy = Math.abs(y - v.y); + double dx = Math.abs(getX() - v.getX()); + double dy = Math.abs(getY() - v.getY()); return dx + dy; } @@ -174,23 +177,23 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public double distanceInf(Vector2D v) { - double dx = Math.abs(x - v.x); - double dy = Math.abs(y - v.y); + double dx = Math.abs(getX() - v.getX()); + double dy = Math.abs(getY() - v.getY()); return Math.max(dx, dy); } /** {@inheritDoc} */ @Override public double distanceSq(Vector2D v) { - double dx = x - v.x; - double dy = y - v.y; + double dx = getX() - v.getX(); + double dy = getY() - v.getY(); return (dx * dx) + (dy * dy); } /** {@inheritDoc} */ @Override public double dotProduct(Vector2D v) { - return LinearCombination.value(x, v.x, y, v.y); + return LinearCombination.value(getX(), v.getX(), getY(), v.getY()); } /** Compute the angular separation in radians between this vector @@ -215,7 +218,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point double threshold = normProduct * 0.9999; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine - final double n = Math.abs(LinearCombination.value(x, v.y, -y, v.x)); + final double n = Math.abs(LinearCombination.value(getX(), v.getY(), -getY(), v.getX())); if (dot >= 0) { return Math.asin(n / normProduct); } @@ -247,10 +250,10 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point * @see <a href="http://mathworld.wolfram.com/CrossProduct.html">Cross product (Mathworld)</a> */ public double crossProduct(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; - final double y2 = p2.y - p1.y; + final double x1 = p2.getX() - p1.getX(); + final double y1 = getY() - p1.getY(); + final double x2 = getX() - p1.getX(); + final double y2 = p2.getY() - p1.getY(); return LinearCombination.value(x1, y1, -x2, y2); } @@ -266,7 +269,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point if (isNaN()) { return 542; } - return 122 * (76 * Double.hashCode(x) + Double.hashCode(y)); + return 122 * (76 * Double.hashCode(getX()) + Double.hashCode(getY())); } /** @@ -300,7 +303,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point return this.isNaN(); } - return (x == rhs.x) && (y == rhs.y); + return (getX() == rhs.getX()) && (getY() == rhs.getY()); } return false; } @@ -308,7 +311,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point /** {@inheritDoc} */ @Override public String toString() { - return "{" + x + "; " + y + "}"; + return "{" + getX() + "; " + getY() + "}"; } /** Computes the dot product between to vectors. This method simply @@ -347,7 +350,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point * @return vector instance */ public static Vector2D of(Cartesian2D value) { - return new Vector2D(value.x, value.y); + return new Vector2D(value.getX(), value.getY()); } /** Creates a vector from the coordinates in the given 2-element array. @@ -375,7 +378,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point * @return vector with coordinates calculated by {@code a * c} */ public static Vector2D linearCombination(double a, Cartesian2D c) { - return new Vector2D(a * c.x, a * c.y); + return new Vector2D(a * c.getX(), a * c.getY()); } /** Returns a vector consisting of the linear combination of the inputs. @@ -394,8 +397,8 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point */ public static Vector2D linearCombination(double a1, Cartesian2D c1, double a2, Cartesian2D c2) { return new Vector2D( - LinearCombination.value(a1, c1.x, a2, c2.x), - LinearCombination.value(a1, c1.y, a2, c2.y)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY())); } /** Returns a vector consisting of the linear combination of the inputs. @@ -417,8 +420,8 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point public static Vector2D linearCombination(double a1, Cartesian2D c1, double a2, Cartesian2D c2, double a3, Cartesian2D c3) { return new Vector2D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x), - LinearCombination.value(a1, c1.y, a2, c2.y, a3, c3.y)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY(), a3, c3.getY())); } /** Returns a vector consisting of the linear combination of the inputs. @@ -442,7 +445,7 @@ public final class Vector2D extends Cartesian2D implements EuclideanVector<Point public static Vector2D linearCombination(double a1, Cartesian2D c1, double a2, Cartesian2D c2, double a3, Cartesian2D c3, double a4, Cartesian2D c4) { return new Vector2D( - LinearCombination.value(a1, c1.x, a2, c2.x, a3, c3.x, a4, c4.x), - LinearCombination.value(a1, c1.y, a2, c2.y, a3, c3.y, a4, c4.y)); + LinearCombination.value(a1, c1.getX(), a2, c2.getX(), a3, c3.getX(), a4, c4.getX()), + LinearCombination.value(a1, c1.getY(), a2, c2.getY(), a3, c3.getY(), a4, c4.getY())); } } -- To stop receiving notification emails like this one, please contact er...@apache.org.