Remove deprecated Vector#distance(Vector) method.

This commit is contained in:
Thomas Neidhart 2015-03-10 23:00:03 +01:00
parent f5532557b9
commit 7c172a091a
4 changed files with 63 additions and 28 deletions

View File

@ -113,15 +113,6 @@ public interface Vector<S extends Space> extends Point<S> {
*/ */
double distance1(Vector<S> v); 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>&infin;</sub> norm. /** Compute the distance between the instance and another vector according to the L<sub>&infin;</sub> norm.
* <p>Calling this method is equivalent to calling: * <p>Calling this method is equivalent to calling:
* <code>q.subtract(p).getNormInf()</code> except that no intermediate * <code>q.subtract(p).getNormInf()</code> except that no intermediate

View File

@ -129,60 +129,71 @@ public class Vector1D implements Vector<Euclidean1D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Space getSpace() { public Space getSpace() {
return Euclidean1D.getInstance(); return Euclidean1D.getInstance();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector1D getZero() { public Vector1D getZero() {
return ZERO; return ZERO;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNorm1() { public double getNorm1() {
return FastMath.abs(x); return FastMath.abs(x);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNorm() { public double getNorm() {
return FastMath.abs(x); return FastMath.abs(x);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNormSq() { public double getNormSq() {
return x * x; return x * x;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNormInf() { public double getNormInf() {
return FastMath.abs(x); return FastMath.abs(x);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector1D add(Vector<Euclidean1D> v) { public Vector1D add(Vector<Euclidean1D> v) {
Vector1D v1 = (Vector1D) v; Vector1D v1 = (Vector1D) v;
return new Vector1D(x + v1.getX()); return new Vector1D(x + v1.getX());
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector1D add(double factor, Vector<Euclidean1D> v) { public Vector1D add(double factor, Vector<Euclidean1D> v) {
Vector1D v1 = (Vector1D) v; Vector1D v1 = (Vector1D) v;
return new Vector1D(x + factor * v1.getX()); return new Vector1D(x + factor * v1.getX());
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector1D subtract(Vector<Euclidean1D> p) { public Vector1D subtract(Vector<Euclidean1D> p) {
Vector1D p3 = (Vector1D) p; Vector1D p3 = (Vector1D) p;
return new Vector1D(x - p3.x); return new Vector1D(x - p3.x);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector1D subtract(double factor, Vector<Euclidean1D> v) { public Vector1D subtract(double factor, Vector<Euclidean1D> v) {
Vector1D v1 = (Vector1D) v; Vector1D v1 = (Vector1D) v;
return new Vector1D(x - factor * v1.getX()); return new Vector1D(x - factor * v1.getX());
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector1D normalize() throws MathArithmeticException { public Vector1D normalize() throws MathArithmeticException {
double s = getNorm(); double s = getNorm();
if (s == 0) { if (s == 0) {
@ -191,41 +202,39 @@ public class Vector1D implements Vector<Euclidean1D> {
return scalarMultiply(1 / s); return scalarMultiply(1 / s);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector1D negate() { public Vector1D negate() {
return new Vector1D(-x); return new Vector1D(-x);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector1D scalarMultiply(double a) { public Vector1D scalarMultiply(double a) {
return new Vector1D(a * x); return new Vector1D(a * x);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public boolean isNaN() { public boolean isNaN() {
return Double.isNaN(x); return Double.isNaN(x);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public boolean isInfinite() { public boolean isInfinite() {
return !isNaN() && Double.isInfinite(x); return !isNaN() && Double.isInfinite(x);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distance1(Vector<Euclidean1D> p) { public double distance1(Vector<Euclidean1D> p) {
Vector1D p3 = (Vector1D) p; Vector1D p3 = (Vector1D) p;
final double dx = FastMath.abs(p3.x - x); final double dx = FastMath.abs(p3.x - x);
return dx; 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} */ /** {@inheritDoc} */
@Override
public double distance(Point<Euclidean1D> p) { public double distance(Point<Euclidean1D> p) {
Vector1D p3 = (Vector1D) p; Vector1D p3 = (Vector1D) p;
final double dx = p3.x - x; final double dx = p3.x - x;
@ -233,6 +242,7 @@ public class Vector1D implements Vector<Euclidean1D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distanceInf(Vector<Euclidean1D> p) { public double distanceInf(Vector<Euclidean1D> p) {
Vector1D p3 = (Vector1D) p; Vector1D p3 = (Vector1D) p;
final double dx = FastMath.abs(p3.x - x); final double dx = FastMath.abs(p3.x - x);
@ -240,6 +250,7 @@ public class Vector1D implements Vector<Euclidean1D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distanceSq(Vector<Euclidean1D> p) { public double distanceSq(Vector<Euclidean1D> p) {
Vector1D p3 = (Vector1D) p; Vector1D p3 = (Vector1D) p;
final double dx = p3.x - x; final double dx = p3.x - x;
@ -247,6 +258,7 @@ public class Vector1D implements Vector<Euclidean1D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double dotProduct(final Vector<Euclidean1D> v) { public double dotProduct(final Vector<Euclidean1D> v) {
final Vector1D v1 = (Vector1D) v; final Vector1D v1 = (Vector1D) v;
return x * v1.x; return x * v1.x;
@ -349,6 +361,7 @@ public class Vector1D implements Vector<Euclidean1D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public String toString(final NumberFormat format) { public String toString(final NumberFormat format) {
return new Vector1DFormat(format).format(this); return new Vector1DFormat(format).format(this);
} }

View File

@ -223,33 +223,39 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Space getSpace() { public Space getSpace() {
return Euclidean3D.getInstance(); return Euclidean3D.getInstance();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector3D getZero() { public Vector3D getZero() {
return ZERO; return ZERO;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNorm1() { public double getNorm1() {
return FastMath.abs(x) + FastMath.abs(y) + FastMath.abs(z); return FastMath.abs(x) + FastMath.abs(y) + FastMath.abs(z);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNorm() { public double getNorm() {
// there are no cancellation problems here, so we use the straightforward formula // there are no cancellation problems here, so we use the straightforward formula
return FastMath.sqrt (x * x + y * y + z * z); return FastMath.sqrt (x * x + y * y + z * z);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNormSq() { public double getNormSq() {
// there are no cancellation problems here, so we use the straightforward formula // there are no cancellation problems here, so we use the straightforward formula
return x * x + y * y + z * z; return x * x + y * y + z * z;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNormInf() { public double getNormInf() {
return FastMath.max(FastMath.max(FastMath.abs(x), FastMath.abs(y)), FastMath.abs(z)); 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} */ /** {@inheritDoc} */
@Override
public Vector3D add(final Vector<Euclidean3D> v) { public Vector3D add(final Vector<Euclidean3D> v) {
final Vector3D v3 = (Vector3D) v; final Vector3D v3 = (Vector3D) v;
return new Vector3D(x + v3.x, y + v3.y, z + v3.z); return new Vector3D(x + v3.x, y + v3.y, z + v3.z);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector3D add(double factor, final Vector<Euclidean3D> v) { public Vector3D add(double factor, final Vector<Euclidean3D> v) {
return new Vector3D(1, this, factor, (Vector3D) v); return new Vector3D(1, this, factor, (Vector3D) v);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector3D subtract(final Vector<Euclidean3D> v) { public Vector3D subtract(final Vector<Euclidean3D> v) {
final Vector3D v3 = (Vector3D) v; final Vector3D v3 = (Vector3D) v;
return new Vector3D(x - v3.x, y - v3.y, z - v3.z); return new Vector3D(x - v3.x, y - v3.y, z - v3.z);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector3D subtract(final double factor, final Vector<Euclidean3D> v) { public Vector3D subtract(final double factor, final Vector<Euclidean3D> v) {
return new Vector3D(1, this, -factor, (Vector3D) v); return new Vector3D(1, this, -factor, (Vector3D) v);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector3D normalize() throws MathArithmeticException { public Vector3D normalize() throws MathArithmeticException {
double s = getNorm(); double s = getNorm();
if (s == 0) { if (s == 0) {
@ -370,21 +381,25 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector3D negate() { public Vector3D negate() {
return new Vector3D(-x, -y, -z); return new Vector3D(-x, -y, -z);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector3D scalarMultiply(double a) { public Vector3D scalarMultiply(double a) {
return new Vector3D(a * x, a * y, a * z); return new Vector3D(a * x, a * y, a * z);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public boolean isNaN() { public boolean isNaN() {
return Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z); return Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public boolean isInfinite() { public boolean isInfinite() {
return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y) || Double.isInfinite(z)); return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y) || Double.isInfinite(z));
} }
@ -449,6 +464,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> {
* </p> * </p>
* @see MathArrays#linearCombination(double, double, double, double, double, double) * @see MathArrays#linearCombination(double, double, double, double, double, double)
*/ */
@Override
public double dotProduct(final Vector<Euclidean3D> v) { public double dotProduct(final Vector<Euclidean3D> v) {
final Vector3D v3 = (Vector3D) v; final Vector3D v3 = (Vector3D) v;
return MathArrays.linearCombination(x, v3.x, y, v3.y, z, v3.z); return MathArrays.linearCombination(x, v3.x, y, v3.y, z, v3.z);
@ -466,6 +482,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distance1(Vector<Euclidean3D> v) { public double distance1(Vector<Euclidean3D> v) {
final Vector3D v3 = (Vector3D) v; final Vector3D v3 = (Vector3D) v;
final double dx = FastMath.abs(v3.x - x); final double dx = FastMath.abs(v3.x - x);
@ -475,11 +492,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public double distance(Vector<Euclidean3D> v) { @Override
return distance((Point<Euclidean3D>) v);
}
/** {@inheritDoc} */
public double distance(Point<Euclidean3D> v) { public double distance(Point<Euclidean3D> v) {
final Vector3D v3 = (Vector3D) v; final Vector3D v3 = (Vector3D) v;
final double dx = v3.x - x; final double dx = v3.x - x;
@ -489,6 +502,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distanceInf(Vector<Euclidean3D> v) { public double distanceInf(Vector<Euclidean3D> v) {
final Vector3D v3 = (Vector3D) v; final Vector3D v3 = (Vector3D) v;
final double dx = FastMath.abs(v3.x - x); final double dx = FastMath.abs(v3.x - x);
@ -498,6 +512,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distanceSq(Vector<Euclidean3D> v) { public double distanceSq(Vector<Euclidean3D> v) {
final Vector3D v3 = (Vector3D) v; final Vector3D v3 = (Vector3D) v;
final double dx = v3.x - x; final double dx = v3.x - x;
@ -581,6 +596,7 @@ public class Vector3D implements Serializable, Vector<Euclidean3D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public String toString(final NumberFormat format) { public String toString(final NumberFormat format) {
return new Vector3DFormat(format).format(this); return new Vector3DFormat(format).format(this);
} }

View File

@ -168,60 +168,71 @@ public class Vector2D implements Vector<Euclidean2D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Space getSpace() { public Space getSpace() {
return Euclidean2D.getInstance(); return Euclidean2D.getInstance();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector2D getZero() { public Vector2D getZero() {
return ZERO; return ZERO;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNorm1() { public double getNorm1() {
return FastMath.abs(x) + FastMath.abs(y); return FastMath.abs(x) + FastMath.abs(y);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNorm() { public double getNorm() {
return FastMath.sqrt (x * x + y * y); return FastMath.sqrt (x * x + y * y);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNormSq() { public double getNormSq() {
return x * x + y * y; return x * x + y * y;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double getNormInf() { public double getNormInf() {
return FastMath.max(FastMath.abs(x), FastMath.abs(y)); return FastMath.max(FastMath.abs(x), FastMath.abs(y));
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector2D add(Vector<Euclidean2D> v) { public Vector2D add(Vector<Euclidean2D> v) {
Vector2D v2 = (Vector2D) v; Vector2D v2 = (Vector2D) v;
return new Vector2D(x + v2.getX(), y + v2.getY()); return new Vector2D(x + v2.getX(), y + v2.getY());
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector2D add(double factor, Vector<Euclidean2D> v) { public Vector2D add(double factor, Vector<Euclidean2D> v) {
Vector2D v2 = (Vector2D) v; Vector2D v2 = (Vector2D) v;
return new Vector2D(x + factor * v2.getX(), y + factor * v2.getY()); return new Vector2D(x + factor * v2.getX(), y + factor * v2.getY());
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector2D subtract(Vector<Euclidean2D> p) { public Vector2D subtract(Vector<Euclidean2D> p) {
Vector2D p3 = (Vector2D) p; Vector2D p3 = (Vector2D) p;
return new Vector2D(x - p3.x, y - p3.y); return new Vector2D(x - p3.x, y - p3.y);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector2D subtract(double factor, Vector<Euclidean2D> v) { public Vector2D subtract(double factor, Vector<Euclidean2D> v) {
Vector2D v2 = (Vector2D) v; Vector2D v2 = (Vector2D) v;
return new Vector2D(x - factor * v2.getX(), y - factor * v2.getY()); return new Vector2D(x - factor * v2.getX(), y - factor * v2.getY());
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector2D normalize() throws MathArithmeticException { public Vector2D normalize() throws MathArithmeticException {
double s = getNorm(); double s = getNorm();
if (s == 0) { if (s == 0) {
@ -265,26 +276,31 @@ public class Vector2D implements Vector<Euclidean2D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector2D negate() { public Vector2D negate() {
return new Vector2D(-x, -y); return new Vector2D(-x, -y);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public Vector2D scalarMultiply(double a) { public Vector2D scalarMultiply(double a) {
return new Vector2D(a * x, a * y); return new Vector2D(a * x, a * y);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public boolean isNaN() { public boolean isNaN() {
return Double.isNaN(x) || Double.isNaN(y); return Double.isNaN(x) || Double.isNaN(y);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public boolean isInfinite() { public boolean isInfinite() {
return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y)); return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y));
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distance1(Vector<Euclidean2D> p) { public double distance1(Vector<Euclidean2D> p) {
Vector2D p3 = (Vector2D) p; Vector2D p3 = (Vector2D) p;
final double dx = FastMath.abs(p3.x - x); final double dx = FastMath.abs(p3.x - x);
@ -292,13 +308,8 @@ public class Vector2D implements Vector<Euclidean2D> {
return dx + dy; return dx + dy;
} }
/** {@inheritDoc}
*/
public double distance(Vector<Euclidean2D> p) {
return distance((Point<Euclidean2D>) p);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distance(Point<Euclidean2D> p) { public double distance(Point<Euclidean2D> p) {
Vector2D p3 = (Vector2D) p; Vector2D p3 = (Vector2D) p;
final double dx = p3.x - x; final double dx = p3.x - x;
@ -307,6 +318,7 @@ public class Vector2D implements Vector<Euclidean2D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distanceInf(Vector<Euclidean2D> p) { public double distanceInf(Vector<Euclidean2D> p) {
Vector2D p3 = (Vector2D) p; Vector2D p3 = (Vector2D) p;
final double dx = FastMath.abs(p3.x - x); final double dx = FastMath.abs(p3.x - x);
@ -315,6 +327,7 @@ public class Vector2D implements Vector<Euclidean2D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double distanceSq(Vector<Euclidean2D> p) { public double distanceSq(Vector<Euclidean2D> p) {
Vector2D p3 = (Vector2D) p; Vector2D p3 = (Vector2D) p;
final double dx = p3.x - x; final double dx = p3.x - x;
@ -323,6 +336,7 @@ public class Vector2D implements Vector<Euclidean2D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public double dotProduct(final Vector<Euclidean2D> v) { public double dotProduct(final Vector<Euclidean2D> v) {
final Vector2D v2 = (Vector2D) v; final Vector2D v2 = (Vector2D) v;
return MathArrays.linearCombination(x, v2.x, y, v2.y); return MathArrays.linearCombination(x, v2.x, y, v2.y);
@ -453,6 +467,7 @@ public class Vector2D implements Vector<Euclidean2D> {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public String toString(final NumberFormat format) { public String toString(final NumberFormat format) {
return new Vector2DFormat(format).format(this); return new Vector2DFormat(format).format(this);
} }