diff --git a/src/main/java/org/apache/commons/math4/geometry/Vector.java b/src/main/java/org/apache/commons/math4/geometry/Vector.java index 9e740b32b..93a66569c 100644 --- a/src/main/java/org/apache/commons/math4/geometry/Vector.java +++ b/src/main/java/org/apache/commons/math4/geometry/Vector.java @@ -113,15 +113,6 @@ public interface Vector extends Point { */ double distance1(Vector v); - /** Compute the distance between the instance and another vector according to the L2 norm. - *

Calling this method is equivalent to calling: - * q.subtract(p).getNorm() except that no intermediate - * vector is built

- * @param v second vector - * @return the distance between the instance and p according to the L2 norm - */ - double distance(Vector v); - /** Compute the distance between the instance and another vector according to the L norm. *

Calling this method is equivalent to calling: * q.subtract(p).getNormInf() except that no intermediate diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java index ca402af65..2b64ff7b0 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java @@ -129,60 +129,71 @@ public class Vector1D implements Vector { } /** {@inheritDoc} */ + @Override public Space getSpace() { return Euclidean1D.getInstance(); } /** {@inheritDoc} */ + @Override public Vector1D getZero() { return ZERO; } /** {@inheritDoc} */ + @Override public double getNorm1() { return FastMath.abs(x); } /** {@inheritDoc} */ + @Override public double getNorm() { return FastMath.abs(x); } /** {@inheritDoc} */ + @Override public double getNormSq() { return x * x; } /** {@inheritDoc} */ + @Override public double getNormInf() { return FastMath.abs(x); } /** {@inheritDoc} */ + @Override public Vector1D add(Vector v) { Vector1D v1 = (Vector1D) v; return new Vector1D(x + v1.getX()); } /** {@inheritDoc} */ + @Override public Vector1D add(double factor, Vector v) { Vector1D v1 = (Vector1D) v; return new Vector1D(x + factor * v1.getX()); } /** {@inheritDoc} */ + @Override public Vector1D subtract(Vector p) { Vector1D p3 = (Vector1D) p; return new Vector1D(x - p3.x); } /** {@inheritDoc} */ + @Override public Vector1D subtract(double factor, Vector v) { Vector1D v1 = (Vector1D) v; return new Vector1D(x - factor * v1.getX()); } /** {@inheritDoc} */ + @Override public Vector1D normalize() throws MathArithmeticException { double s = getNorm(); if (s == 0) { @@ -191,41 +202,39 @@ public class Vector1D implements Vector { return scalarMultiply(1 / s); } /** {@inheritDoc} */ + @Override public Vector1D negate() { return new Vector1D(-x); } /** {@inheritDoc} */ + @Override public Vector1D scalarMultiply(double a) { return new Vector1D(a * x); } /** {@inheritDoc} */ + @Override public boolean isNaN() { return Double.isNaN(x); } /** {@inheritDoc} */ + @Override public boolean isInfinite() { return !isNaN() && Double.isInfinite(x); } /** {@inheritDoc} */ + @Override public double distance1(Vector p) { Vector1D p3 = (Vector1D) p; final double dx = FastMath.abs(p3.x - x); return dx; } - /** {@inheritDoc} - * @deprecated as of 3.3, replaced with {@link #distance(Point)} - */ - @Deprecated - public double distance(Vector p) { - return distance((Point) p); - } - /** {@inheritDoc} */ + @Override public double distance(Point p) { Vector1D p3 = (Vector1D) p; final double dx = p3.x - x; @@ -233,6 +242,7 @@ public class Vector1D implements Vector { } /** {@inheritDoc} */ + @Override public double distanceInf(Vector p) { Vector1D p3 = (Vector1D) p; final double dx = FastMath.abs(p3.x - x); @@ -240,6 +250,7 @@ public class Vector1D implements Vector { } /** {@inheritDoc} */ + @Override public double distanceSq(Vector p) { Vector1D p3 = (Vector1D) p; final double dx = p3.x - x; @@ -247,6 +258,7 @@ public class Vector1D implements Vector { } /** {@inheritDoc} */ + @Override public double dotProduct(final Vector v) { final Vector1D v1 = (Vector1D) v; return x * v1.x; @@ -349,6 +361,7 @@ public class Vector1D implements Vector { } /** {@inheritDoc} */ + @Override public String toString(final NumberFormat format) { return new Vector1DFormat(format).format(this); } diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java index 7a885b66d..7e43245b0 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java @@ -223,33 +223,39 @@ public class Vector3D implements Serializable, Vector { } /** {@inheritDoc} */ + @Override public Space getSpace() { return Euclidean3D.getInstance(); } /** {@inheritDoc} */ + @Override public Vector3D getZero() { return ZERO; } /** {@inheritDoc} */ + @Override public double getNorm1() { return FastMath.abs(x) + FastMath.abs(y) + FastMath.abs(z); } /** {@inheritDoc} */ + @Override public double getNorm() { // there are no cancellation problems here, so we use the straightforward formula return FastMath.sqrt (x * x + y * y + z * z); } /** {@inheritDoc} */ + @Override public double getNormSq() { // there are no cancellation problems here, so we use the straightforward formula return x * x + y * y + z * z; } /** {@inheritDoc} */ + @Override public double getNormInf() { return FastMath.max(FastMath.max(FastMath.abs(x), FastMath.abs(y)), FastMath.abs(z)); } @@ -271,28 +277,33 @@ public class Vector3D implements Serializable, Vector { } /** {@inheritDoc} */ + @Override public Vector3D add(final Vector v) { final Vector3D v3 = (Vector3D) v; return new Vector3D(x + v3.x, y + v3.y, z + v3.z); } /** {@inheritDoc} */ + @Override public Vector3D add(double factor, final Vector v) { return new Vector3D(1, this, factor, (Vector3D) v); } /** {@inheritDoc} */ + @Override public Vector3D subtract(final Vector v) { final Vector3D v3 = (Vector3D) v; return new Vector3D(x - v3.x, y - v3.y, z - v3.z); } /** {@inheritDoc} */ + @Override public Vector3D subtract(final double factor, final Vector v) { return new Vector3D(1, this, -factor, (Vector3D) v); } /** {@inheritDoc} */ + @Override public Vector3D normalize() throws MathArithmeticException { double s = getNorm(); if (s == 0) { @@ -370,21 +381,25 @@ public class Vector3D implements Serializable, Vector { } /** {@inheritDoc} */ + @Override public Vector3D negate() { return new Vector3D(-x, -y, -z); } /** {@inheritDoc} */ + @Override public Vector3D scalarMultiply(double a) { return new Vector3D(a * x, a * y, a * z); } /** {@inheritDoc} */ + @Override public boolean isNaN() { return Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z); } /** {@inheritDoc} */ + @Override public boolean isInfinite() { return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y) || Double.isInfinite(z)); } @@ -449,6 +464,7 @@ public class Vector3D implements Serializable, Vector { *

* @see MathArrays#linearCombination(double, double, double, double, double, double) */ + @Override public double dotProduct(final Vector v) { final Vector3D v3 = (Vector3D) v; return MathArrays.linearCombination(x, v3.x, y, v3.y, z, v3.z); @@ -466,6 +482,7 @@ public class Vector3D implements Serializable, Vector { } /** {@inheritDoc} */ + @Override public double distance1(Vector v) { final Vector3D v3 = (Vector3D) v; final double dx = FastMath.abs(v3.x - x); @@ -475,11 +492,7 @@ public class Vector3D implements Serializable, Vector { } /** {@inheritDoc} */ - public double distance(Vector v) { - return distance((Point) v); - } - - /** {@inheritDoc} */ + @Override public double distance(Point v) { final Vector3D v3 = (Vector3D) v; final double dx = v3.x - x; @@ -489,6 +502,7 @@ public class Vector3D implements Serializable, Vector { } /** {@inheritDoc} */ + @Override public double distanceInf(Vector v) { final Vector3D v3 = (Vector3D) v; final double dx = FastMath.abs(v3.x - x); @@ -498,6 +512,7 @@ public class Vector3D implements Serializable, Vector { } /** {@inheritDoc} */ + @Override public double distanceSq(Vector v) { final Vector3D v3 = (Vector3D) v; final double dx = v3.x - x; @@ -581,6 +596,7 @@ public class Vector3D implements Serializable, Vector { } /** {@inheritDoc} */ + @Override public String toString(final NumberFormat format) { return new Vector3DFormat(format).format(this); } diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java index 3570e393b..fec599bc6 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java @@ -168,60 +168,71 @@ public class Vector2D implements Vector { } /** {@inheritDoc} */ + @Override public Space getSpace() { return Euclidean2D.getInstance(); } /** {@inheritDoc} */ + @Override public Vector2D getZero() { return ZERO; } /** {@inheritDoc} */ + @Override public double getNorm1() { return FastMath.abs(x) + FastMath.abs(y); } /** {@inheritDoc} */ + @Override public double getNorm() { return FastMath.sqrt (x * x + y * y); } /** {@inheritDoc} */ + @Override public double getNormSq() { return x * x + y * y; } /** {@inheritDoc} */ + @Override public double getNormInf() { return FastMath.max(FastMath.abs(x), FastMath.abs(y)); } /** {@inheritDoc} */ + @Override public Vector2D add(Vector v) { Vector2D v2 = (Vector2D) v; return new Vector2D(x + v2.getX(), y + v2.getY()); } /** {@inheritDoc} */ + @Override public Vector2D add(double factor, Vector v) { Vector2D v2 = (Vector2D) v; return new Vector2D(x + factor * v2.getX(), y + factor * v2.getY()); } /** {@inheritDoc} */ + @Override public Vector2D subtract(Vector p) { Vector2D p3 = (Vector2D) p; return new Vector2D(x - p3.x, y - p3.y); } /** {@inheritDoc} */ + @Override public Vector2D subtract(double factor, Vector v) { Vector2D v2 = (Vector2D) v; return new Vector2D(x - factor * v2.getX(), y - factor * v2.getY()); } /** {@inheritDoc} */ + @Override public Vector2D normalize() throws MathArithmeticException { double s = getNorm(); if (s == 0) { @@ -265,26 +276,31 @@ public class Vector2D implements Vector { } /** {@inheritDoc} */ + @Override public Vector2D negate() { return new Vector2D(-x, -y); } /** {@inheritDoc} */ + @Override public Vector2D scalarMultiply(double a) { return new Vector2D(a * x, a * y); } /** {@inheritDoc} */ + @Override public boolean isNaN() { return Double.isNaN(x) || Double.isNaN(y); } /** {@inheritDoc} */ + @Override public boolean isInfinite() { return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y)); } /** {@inheritDoc} */ + @Override public double distance1(Vector p) { Vector2D p3 = (Vector2D) p; final double dx = FastMath.abs(p3.x - x); @@ -292,13 +308,8 @@ public class Vector2D implements Vector { return dx + dy; } - /** {@inheritDoc} - */ - public double distance(Vector p) { - return distance((Point) p); - } - /** {@inheritDoc} */ + @Override public double distance(Point p) { Vector2D p3 = (Vector2D) p; final double dx = p3.x - x; @@ -307,6 +318,7 @@ public class Vector2D implements Vector { } /** {@inheritDoc} */ + @Override public double distanceInf(Vector p) { Vector2D p3 = (Vector2D) p; final double dx = FastMath.abs(p3.x - x); @@ -315,6 +327,7 @@ public class Vector2D implements Vector { } /** {@inheritDoc} */ + @Override public double distanceSq(Vector p) { Vector2D p3 = (Vector2D) p; final double dx = p3.x - x; @@ -323,6 +336,7 @@ public class Vector2D implements Vector { } /** {@inheritDoc} */ + @Override public double dotProduct(final Vector v) { final Vector2D v2 = (Vector2D) v; return MathArrays.linearCombination(x, v2.x, y, v2.y); @@ -453,6 +467,7 @@ public class Vector2D implements Vector { } /** {@inheritDoc} */ + @Override public String toString(final NumberFormat format) { return new Vector2DFormat(format).format(this); }