Repository: commons-math Updated Branches: refs/heads/master f5532557b -> fbf5a51ea
Remove deprecated Vector#distance(Vector) method. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/7c172a09 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/7c172a09 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/7c172a09 Branch: refs/heads/master Commit: 7c172a091a2c623d264f98a36f141f5726e65296 Parents: f553255 Author: Thomas Neidhart <[email protected]> Authored: Tue Mar 10 23:00:03 2015 +0100 Committer: Thomas Neidhart <[email protected]> Committed: Tue Mar 10 23:00:03 2015 +0100 ---------------------------------------------------------------------- .../apache/commons/math4/geometry/Vector.java | 9 ------ .../math4/geometry/euclidean/oned/Vector1D.java | 29 ++++++++++++++------ .../geometry/euclidean/threed/Vector3D.java | 26 ++++++++++++++---- .../math4/geometry/euclidean/twod/Vector2D.java | 27 ++++++++++++++---- 4 files changed, 63 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/7c172a09/src/main/java/org/apache/commons/math4/geometry/Vector.java ---------------------------------------------------------------------- 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 9e740b3..93a6656 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<S extends Space> extends Point<S> { */ double distance1(Vector<S> v); - /** Compute the distance between the instance and another vector according to the L<sub>2</sub> norm. - * <p>Calling this method is equivalent to calling: - * <code>q.subtract(p).getNorm()</code> except that no intermediate - * vector is built</p> - * @param v second vector - * @return the distance between the instance and p according to the L<sub>2</sub> norm - */ - double distance(Vector<S> v); - /** Compute the distance between the instance and another vector according to the L<sub>∞</sub> norm. * <p>Calling this method is equivalent to calling: * <code>q.subtract(p).getNormInf()</code> except that no intermediate http://git-wip-us.apache.org/repos/asf/commons-math/blob/7c172a09/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java ---------------------------------------------------------------------- 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 ca402af..2b64ff7 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<Euclidean1D> { } /** {@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<Euclidean1D> v) { Vector1D v1 = (Vector1D) v; return new Vector1D(x + v1.getX()); } /** {@inheritDoc} */ + @Override public Vector1D add(double factor, Vector<Euclidean1D> v) { Vector1D v1 = (Vector1D) v; return new Vector1D(x + factor * v1.getX()); } /** {@inheritDoc} */ + @Override public Vector1D subtract(Vector<Euclidean1D> p) { Vector1D p3 = (Vector1D) p; return new Vector1D(x - p3.x); } /** {@inheritDoc} */ + @Override public Vector1D subtract(double factor, Vector<Euclidean1D> 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<Euclidean1D> { 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<Euclidean1D> 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<Euclidean1D> p) { - return distance((Point<Euclidean1D>) p); - } - /** {@inheritDoc} */ + @Override public double distance(Point<Euclidean1D> p) { Vector1D p3 = (Vector1D) p; final double dx = p3.x - x; @@ -233,6 +242,7 @@ public class Vector1D implements Vector<Euclidean1D> { } /** {@inheritDoc} */ + @Override public double distanceInf(Vector<Euclidean1D> p) { Vector1D p3 = (Vector1D) p; final double dx = FastMath.abs(p3.x - x); @@ -240,6 +250,7 @@ public class Vector1D implements Vector<Euclidean1D> { } /** {@inheritDoc} */ + @Override public double distanceSq(Vector<Euclidean1D> p) { Vector1D p3 = (Vector1D) p; final double dx = p3.x - x; @@ -247,6 +258,7 @@ public class Vector1D implements Vector<Euclidean1D> { } /** {@inheritDoc} */ + @Override public double dotProduct(final Vector<Euclidean1D> v) { final Vector1D v1 = (Vector1D) v; return x * v1.x; @@ -349,6 +361,7 @@ public class Vector1D implements Vector<Euclidean1D> { } /** {@inheritDoc} */ + @Override public String toString(final NumberFormat format) { return new Vector1DFormat(format).format(this); } http://git-wip-us.apache.org/repos/asf/commons-math/blob/7c172a09/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java ---------------------------------------------------------------------- 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 7a885b6..7e43245 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<Euclidean3D> { } /** {@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<Euclidean3D> { } /** {@inheritDoc} */ + @Override public Vector3D add(final Vector<Euclidean3D> 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<Euclidean3D> v) { return new Vector3D(1, this, factor, (Vector3D) v); } /** {@inheritDoc} */ + @Override public Vector3D subtract(final Vector<Euclidean3D> 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<Euclidean3D> 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<Euclidean3D> { } /** {@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<Euclidean3D> { * </p> * @see MathArrays#linearCombination(double, double, double, double, double, double) */ + @Override public double dotProduct(final Vector<Euclidean3D> 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<Euclidean3D> { } /** {@inheritDoc} */ + @Override public double distance1(Vector<Euclidean3D> v) { final Vector3D v3 = (Vector3D) v; final double dx = FastMath.abs(v3.x - x); @@ -475,11 +492,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> { } /** {@inheritDoc} */ - public double distance(Vector<Euclidean3D> v) { - return distance((Point<Euclidean3D>) v); - } - - /** {@inheritDoc} */ + @Override public double distance(Point<Euclidean3D> v) { final Vector3D v3 = (Vector3D) v; final double dx = v3.x - x; @@ -489,6 +502,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> { } /** {@inheritDoc} */ + @Override public double distanceInf(Vector<Euclidean3D> v) { final Vector3D v3 = (Vector3D) v; final double dx = FastMath.abs(v3.x - x); @@ -498,6 +512,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> { } /** {@inheritDoc} */ + @Override public double distanceSq(Vector<Euclidean3D> v) { final Vector3D v3 = (Vector3D) v; final double dx = v3.x - x; @@ -581,6 +596,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> { } /** {@inheritDoc} */ + @Override public String toString(final NumberFormat format) { return new Vector3DFormat(format).format(this); } http://git-wip-us.apache.org/repos/asf/commons-math/blob/7c172a09/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java ---------------------------------------------------------------------- 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 3570e39..fec599b 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<Euclidean2D> { } /** {@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<Euclidean2D> v) { Vector2D v2 = (Vector2D) v; return new Vector2D(x + v2.getX(), y + v2.getY()); } /** {@inheritDoc} */ + @Override public Vector2D add(double factor, Vector<Euclidean2D> v) { Vector2D v2 = (Vector2D) v; return new Vector2D(x + factor * v2.getX(), y + factor * v2.getY()); } /** {@inheritDoc} */ + @Override public Vector2D subtract(Vector<Euclidean2D> p) { Vector2D p3 = (Vector2D) p; return new Vector2D(x - p3.x, y - p3.y); } /** {@inheritDoc} */ + @Override public Vector2D subtract(double factor, Vector<Euclidean2D> 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<Euclidean2D> { } /** {@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<Euclidean2D> p) { Vector2D p3 = (Vector2D) p; final double dx = FastMath.abs(p3.x - x); @@ -292,13 +308,8 @@ public class Vector2D implements Vector<Euclidean2D> { return dx + dy; } - /** {@inheritDoc} - */ - public double distance(Vector<Euclidean2D> p) { - return distance((Point<Euclidean2D>) p); - } - /** {@inheritDoc} */ + @Override public double distance(Point<Euclidean2D> p) { Vector2D p3 = (Vector2D) p; final double dx = p3.x - x; @@ -307,6 +318,7 @@ public class Vector2D implements Vector<Euclidean2D> { } /** {@inheritDoc} */ + @Override public double distanceInf(Vector<Euclidean2D> p) { Vector2D p3 = (Vector2D) p; final double dx = FastMath.abs(p3.x - x); @@ -315,6 +327,7 @@ public class Vector2D implements Vector<Euclidean2D> { } /** {@inheritDoc} */ + @Override public double distanceSq(Vector<Euclidean2D> p) { Vector2D p3 = (Vector2D) p; final double dx = p3.x - x; @@ -323,6 +336,7 @@ public class Vector2D implements Vector<Euclidean2D> { } /** {@inheritDoc} */ + @Override public double dotProduct(final Vector<Euclidean2D> v) { final Vector2D v2 = (Vector2D) v; return MathArrays.linearCombination(x, v2.x, y, v2.y); @@ -453,6 +467,7 @@ public class Vector2D implements Vector<Euclidean2D> { } /** {@inheritDoc} */ + @Override public String toString(final NumberFormat format) { return new Vector2DFormat(format).format(this); }
