You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2017/05/12 21:32:17 UTC
[08/31] [math] MATH-1284: Vector no longer extends Point.
Replace/rename Vector?D classes with Coordinate?D classes which implement
both Vector and Point. When there are multiple implementations of the same
method which would confuse the compiler, prefer
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java
index a19a876..7ac90d4 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java
@@ -26,26 +26,26 @@ import org.apache.commons.math4.util.FastMath;
/** Class generating an enclosing ball from its support points.
* @since 3.3
*/
-public class DiskGenerator implements SupportBallGenerator<Euclidean2D, Vector2D> {
+public class DiskGenerator implements SupportBallGenerator<Euclidean2D, Coordinates2D> {
/** {@inheritDoc} */
@Override
- public EnclosingBall<Euclidean2D, Vector2D> ballOnSupport(final List<Vector2D> support) {
+ public EnclosingBall<Euclidean2D, Coordinates2D> ballOnSupport(final List<Coordinates2D> support) {
if (support.size() < 1) {
- return new EnclosingBall<>(Vector2D.ZERO, Double.NEGATIVE_INFINITY);
+ return new EnclosingBall<>(Coordinates2D.ZERO, Double.NEGATIVE_INFINITY);
} else {
- final Vector2D vA = support.get(0);
+ final Coordinates2D vA = support.get(0);
if (support.size() < 2) {
return new EnclosingBall<>(vA, 0, vA);
} else {
- final Vector2D vB = support.get(1);
+ final Coordinates2D vB = support.get(1);
if (support.size() < 3) {
- return new EnclosingBall<>(new Vector2D(0.5, vA, 0.5, vB),
+ return new EnclosingBall<>(new Coordinates2D(0.5, vA, 0.5, vB),
0.5 * vA.distance(vB),
vA, vB);
} else {
- final Vector2D vC = support.get(2);
+ final Coordinates2D vC = support.get(2);
// a disk is 2D can be defined as:
// (1) (x - x_0)^2 + (y - y_0)^2 = r^2
// which can be written:
@@ -86,7 +86,7 @@ public class DiskGenerator implements SupportBallGenerator<Euclidean2D, Vector2D
final BigFraction dx = c2[0].subtract(centerX);
final BigFraction dy = c3[0].subtract(centerY);
final BigFraction r2 = dx.multiply(dx).add(dy.multiply(dy));
- return new EnclosingBall<>(new Vector2D(centerX.doubleValue(),
+ return new EnclosingBall<>(new Coordinates2D(centerX.doubleValue(),
centerY.doubleValue()),
FastMath.sqrt(r2.doubleValue()),
vA, vB, vC);
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java
index dd89296..7df7277 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java
@@ -19,11 +19,10 @@ package org.apache.commons.math4.geometry.euclidean.twod;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.math4.geometry.Point;
-import org.apache.commons.math4.geometry.Vector;
import org.apache.commons.math4.geometry.euclidean.oned.Euclidean1D;
import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet;
import org.apache.commons.math4.geometry.euclidean.oned.OrientedPoint;
-import org.apache.commons.math4.geometry.euclidean.oned.Vector1D;
+import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D;
import org.apache.commons.math4.geometry.partitioning.Embedding;
import org.apache.commons.math4.geometry.partitioning.Hyperplane;
import org.apache.commons.math4.geometry.partitioning.SubHyperplane;
@@ -85,7 +84,7 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @param tolerance tolerance below which points are considered identical
* @since 3.3
*/
- public Line(final Vector2D p1, final Vector2D p2, final double tolerance) {
+ public Line(final Coordinates2D p1, final Coordinates2D p2, final double tolerance) {
reset(p1, p2);
this.tolerance = tolerance;
}
@@ -96,7 +95,7 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @param tolerance tolerance below which points are considered identical
* @since 3.3
*/
- public Line(final Vector2D p, final double angle, final double tolerance) {
+ public Line(final Coordinates2D p, final double angle, final double tolerance) {
reset(p, angle);
this.tolerance = tolerance;
}
@@ -144,7 +143,7 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @param p1 first point
* @param p2 second point
*/
- public void reset(final Vector2D p1, final Vector2D p2) {
+ public void reset(final Coordinates2D p1, final Coordinates2D p2) {
unlinkReverse();
final double dx = p2.getX() - p1.getX();
final double dy = p2.getY() - p1.getY();
@@ -166,7 +165,7 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @param p point belonging to the line
* @param alpha angle of the line with respect to abscissa axis
*/
- public void reset(final Vector2D p, final double alpha) {
+ public void reset(final Coordinates2D p, final double alpha) {
unlinkReverse();
this.angle = MathUtils.normalizeAngle(alpha, FastMath.PI);
cos = FastMath.cos(this.angle);
@@ -226,31 +225,31 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @return (n-1)-dimension point of the sub-space corresponding to
* the specified space point
*/
- public Vector1D toSubSpace(Vector<Euclidean2D> vector) {
- return toSubSpace((Point<Euclidean2D>) vector);
- }
+// public Coordinates1D toSubSpace(Vector<Euclidean2D> vector) {
+// return toSubSpace((Point<Euclidean2D>) vector);
+// }
/** Transform a sub-space point into a space point.
* @param vector (n-1)-dimension point of the sub-space
* @return n-dimension point of the space corresponding to the
* specified sub-space point
*/
- public Vector2D toSpace(Vector<Euclidean1D> vector) {
- return toSpace((Point<Euclidean1D>) vector);
- }
+// public Coordinates2D toSpace(Vector<Euclidean1D> vector) {
+// return toSpace((Point<Euclidean1D>) vector);
+// }
/** {@inheritDoc} */
@Override
- public Vector1D toSubSpace(final Point<Euclidean2D> point) {
- Vector2D p2 = (Vector2D) point;
- return new Vector1D(MathArrays.linearCombination(cos, p2.getX(), sin, p2.getY()));
+ public Coordinates1D toSubSpace(final Point<Euclidean2D> point) {
+ Coordinates2D p2 = (Coordinates2D) point;
+ return new Coordinates1D(MathArrays.linearCombination(cos, p2.getX(), sin, p2.getY()));
}
/** {@inheritDoc} */
@Override
- public Vector2D toSpace(final Point<Euclidean1D> point) {
- final double abscissa = ((Vector1D) point).getX();
- return new Vector2D(MathArrays.linearCombination(abscissa, cos, -originOffset, sin),
+ public Coordinates2D toSpace(final Point<Euclidean1D> point) {
+ final double abscissa = ((Coordinates1D) point).getX();
+ return new Coordinates2D(MathArrays.linearCombination(abscissa, cos, -originOffset, sin),
MathArrays.linearCombination(abscissa, sin, originOffset, cos));
}
@@ -259,12 +258,12 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @return intersection point of the instance and the other line
* or null if there are no intersection points
*/
- public Vector2D intersection(final Line other) {
+ public Coordinates2D intersection(final Line other) {
final double d = MathArrays.linearCombination(sin, other.cos, -other.sin, cos);
if (FastMath.abs(d) < tolerance) {
return null;
}
- return new Vector2D(MathArrays.linearCombination(cos, other.originOffset, -other.cos, originOffset) / d,
+ return new Coordinates2D(MathArrays.linearCombination(cos, other.originOffset, -other.cos, originOffset) / d,
MathArrays.linearCombination(sin, other.originOffset, -other.sin, originOffset) / d);
}
@@ -318,14 +317,14 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @param vector vector to check
* @return offset of the vector
*/
- public double getOffset(Vector<Euclidean2D> vector) {
- return getOffset((Point<Euclidean2D>) vector);
- }
+// public double getOffset(Vector<Euclidean2D> vector) {
+// return getOffset((Point<Euclidean2D>) vector);
+// }
/** {@inheritDoc} */
@Override
public double getOffset(final Point<Euclidean2D> point) {
- Vector2D p2 = (Vector2D) point;
+ Coordinates2D p2 = (Coordinates2D) point;
return MathArrays.linearCombination(sin, p2.getX(), -cos, p2.getY(), 1.0, originOffset);
}
@@ -342,10 +341,10 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @return one point in the plane, with given abscissa and offset
* relative to the line
*/
- public Vector2D getPointAt(final Vector1D abscissa, final double offset) {
+ public Coordinates2D getPointAt(final Coordinates1D abscissa, final double offset) {
final double x = abscissa.getX();
final double dOffset = offset - originOffset;
- return new Vector2D(MathArrays.linearCombination(x, cos, dOffset, sin),
+ return new Coordinates2D(MathArrays.linearCombination(x, cos, dOffset, sin),
MathArrays.linearCombination(x, sin, -dOffset, cos));
}
@@ -353,7 +352,7 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @param p point to check
* @return true if p belongs to the line
*/
- public boolean contains(final Vector2D p) {
+ public boolean contains(final Coordinates2D p) {
return FastMath.abs(getOffset(p)) < tolerance;
}
@@ -366,7 +365,7 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @return distance between the instance and the point
* @since 3.1
*/
- public double distance(final Vector2D p) {
+ public double distance(final Coordinates2D p) {
return FastMath.abs(getOffset(p));
}
@@ -382,7 +381,7 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
/** Translate the line to force it passing by a point.
* @param p point by which the line should pass
*/
- public void translateToPoint(final Vector2D p) {
+ public void translateToPoint(final Coordinates2D p) {
originOffset = MathArrays.linearCombination(cos, p.getY(), -sin, p.getX());
}
@@ -427,7 +426,7 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
* @param cX1 transform addendum for output abscissa
* @param cY1 transform addendum for output ordinate
* @return a new transform that can be applied to either {@link
- * Vector2D Vector2D}, {@link Line Line} or {@link
+ * Coordinates2D Vector2D}, {@link Line Line} or {@link
* org.apache.commons.math4.geometry.partitioning.SubHyperplane
* SubHyperplane} instances
* @exception MathIllegalArgumentException if the transform is non invertible
@@ -512,11 +511,11 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
/** {@inheritDoc} */
@Override
- public Vector2D apply(final Point<Euclidean2D> point) {
- final Vector2D p2D = (Vector2D) point;
+ public Coordinates2D apply(final Point<Euclidean2D> point) {
+ final Coordinates2D p2D = (Coordinates2D) point;
final double x = p2D.getX();
final double y = p2D.getY();
- return new Vector2D(MathArrays.linearCombination(cXX, x, cXY, y, cX1, 1),
+ return new Coordinates2D(MathArrays.linearCombination(cXX, x, cXY, y, cX1, 1),
MathArrays.linearCombination(cYX, x, cYY, y, cY1, 1));
}
@@ -541,7 +540,7 @@ public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euc
final OrientedPoint op = (OrientedPoint) sub.getHyperplane();
final Line originalLine = (Line) original;
final Line transformedLine = (Line) transformed;
- final Vector1D newLoc =
+ final Coordinates1D newLoc =
transformedLine.toSubSpace(apply(originalLine.toSpace(op.getLocation())));
return new OrientedPoint(newLoc, op.isDirect(), originalLine.tolerance).wholeHyperplane();
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java
index a967fb6..5affbfc 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java
@@ -48,7 +48,7 @@ import org.apache.commons.math4.geometry.partitioning.SubHyperplane;
class NestedLoops {
/** Boundary loop. */
- private Vector2D[] loop;
+ private Coordinates2D[] loop;
/** Surrounded loops. */
private List<NestedLoops> surrounded;
@@ -82,7 +82,7 @@ class NestedLoops {
* @exception MathIllegalArgumentException if an outline has an open boundary loop
* @since 3.3
*/
- private NestedLoops(final Vector2D[] loop, final double tolerance)
+ private NestedLoops(final Coordinates2D[] loop, final double tolerance)
throws MathIllegalArgumentException {
if (loop[0] == null) {
@@ -95,9 +95,9 @@ class NestedLoops {
// build the polygon defined by the loop
final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<>();
- Vector2D current = loop[loop.length - 1];
+ Coordinates2D current = loop[loop.length - 1];
for (int i = 0; i < loop.length; ++i) {
- final Vector2D previous = current;
+ final Coordinates2D previous = current;
current = loop[i];
final Line line = new Line(previous, current, tolerance);
final IntervalsSet region =
@@ -123,7 +123,7 @@ class NestedLoops {
* @exception MathIllegalArgumentException if an outline has crossing
* boundary loops or open boundary loops
*/
- public void add(final Vector2D[] bLoop) throws MathIllegalArgumentException {
+ public void add(final Coordinates2D[] bLoop) throws MathIllegalArgumentException {
add(new NestedLoops(bLoop, tolerance));
}
@@ -185,7 +185,7 @@ class NestedLoops {
int min = -1;
int max = loop.length;
while (++min < --max) {
- final Vector2D tmp = loop[min];
+ final Coordinates2D tmp = loop[min];
loop[min] = loop[max];
loop[max] = tmp;
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java
index 38b94f4..eb2d66a 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.geometry.Point;
import org.apache.commons.math4.geometry.euclidean.oned.Euclidean1D;
import org.apache.commons.math4.geometry.euclidean.oned.Interval;
import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet;
-import org.apache.commons.math4.geometry.euclidean.oned.Vector1D;
+import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D;
import org.apache.commons.math4.geometry.partitioning.AbstractRegion;
import org.apache.commons.math4.geometry.partitioning.AbstractSubHyperplane;
import org.apache.commons.math4.geometry.partitioning.BSPTree;
@@ -42,7 +42,7 @@ import org.apache.commons.math4.util.Precision;
public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
/** Vertices organized as boundary loops. */
- private Vector2D[][] vertices;
+ private Coordinates2D[][] vertices;
/** Build a polygons set representing the whole plane.
* @param tolerance tolerance below which points are considered identical
@@ -147,7 +147,7 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
* belong to the hyperplane (which is therefore more a slab)
* @param vertices vertices of the simple loop boundary
*/
- public PolygonsSet(final double hyperplaneThickness, final Vector2D ... vertices) {
+ public PolygonsSet(final double hyperplaneThickness, final Coordinates2D ... vertices) {
super(verticesToTree(hyperplaneThickness, vertices), hyperplaneThickness);
}
@@ -166,10 +166,10 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
// too thin box, build an empty polygons set
return null;
}
- final Vector2D minMin = new Vector2D(xMin, yMin);
- final Vector2D minMax = new Vector2D(xMin, yMax);
- final Vector2D maxMin = new Vector2D(xMax, yMin);
- final Vector2D maxMax = new Vector2D(xMax, yMax);
+ final Coordinates2D minMin = new Coordinates2D(xMin, yMin);
+ final Coordinates2D minMax = new Coordinates2D(xMin, yMax);
+ final Coordinates2D maxMin = new Coordinates2D(xMax, yMin);
+ final Coordinates2D maxMax = new Coordinates2D(xMax, yMax);
return new Line[] {
new Line(minMin, maxMin, tolerance),
new Line(maxMin, maxMax, tolerance),
@@ -194,7 +194,7 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
* @return the BSP tree of the input vertices
*/
private static BSPTree<Euclidean2D> verticesToTree(final double hyperplaneThickness,
- final Vector2D ... vertices) {
+ final Coordinates2D ... vertices) {
final int n = vertices.length;
if (n == 0) {
@@ -347,7 +347,7 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
private static class Vertex {
/** Vertex location. */
- private final Vector2D location;
+ private final Coordinates2D location;
/** Incoming edge. */
private Edge incoming;
@@ -361,7 +361,7 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
/** Build a non-processed vertex not owned by any node yet.
* @param location vertex location
*/
- Vertex(final Vector2D location) {
+ Vertex(final Coordinates2D location) {
this.location = location;
this.incoming = null;
this.outgoing = null;
@@ -371,7 +371,7 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
/** Get Vertex location.
* @return vertex location
*/
- public Vector2D getLocation() {
+ public Coordinates2D getLocation() {
return location;
}
@@ -543,22 +543,22 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
@Override
protected void computeGeometricalProperties() {
- final Vector2D[][] v = getVertices();
+ final Coordinates2D[][] v = getVertices();
if (v.length == 0) {
final BSPTree<Euclidean2D> tree = getTree(false);
if (tree.getCut() == null && (Boolean) tree.getAttribute()) {
// the instance covers the whole space
setSize(Double.POSITIVE_INFINITY);
- setBarycenter((Point<Euclidean2D>) Vector2D.NaN);
+ setBarycenter((Point<Euclidean2D>) Coordinates2D.NaN);
} else {
setSize(0);
- setBarycenter((Point<Euclidean2D>) new Vector2D(0, 0));
+ setBarycenter((Point<Euclidean2D>) new Coordinates2D(0, 0));
}
} else if (v[0][0] == null) {
// there is at least one open-loop: the polygon is infinite
setSize(Double.POSITIVE_INFINITY);
- setBarycenter((Point<Euclidean2D>) Vector2D.NaN);
+ setBarycenter((Point<Euclidean2D>) Coordinates2D.NaN);
} else {
// all loops are closed, we compute some integrals around the shape
@@ -566,10 +566,10 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
double sumX = 0;
double sumY = 0;
- for (Vector2D[] loop : v) {
+ for (Coordinates2D[] loop : v) {
double x1 = loop[loop.length - 1].getX();
double y1 = loop[loop.length - 1].getY();
- for (final Vector2D point : loop) {
+ for (final Coordinates2D point : loop) {
final double x0 = x1;
final double y0 = y1;
x1 = point.getX();
@@ -584,10 +584,10 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
if (sum < 0) {
// the polygon as a finite outside surrounded by an infinite inside
setSize(Double.POSITIVE_INFINITY);
- setBarycenter((Point<Euclidean2D>) Vector2D.NaN);
+ setBarycenter((Point<Euclidean2D>) Coordinates2D.NaN);
} else {
setSize(sum / 2);
- setBarycenter((Point<Euclidean2D>) new Vector2D(sumX / (3 * sum), sumY / (3 * sum)));
+ setBarycenter((Point<Euclidean2D>) new Coordinates2D(sumX / (3 * sum), sumY / (3 * sum)));
}
}
@@ -617,10 +617,10 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
* loops with the open loops first (the returned value is guaranteed
* to be non-null)
*/
- public Vector2D[][] getVertices() {
+ public Coordinates2D[][] getVertices() {
if (vertices == null) {
if (getTree(false).getCut() == null) {
- vertices = new Vector2D[0][];
+ vertices = new Coordinates2D[0][];
} else {
// build the unconnected segments
@@ -655,7 +655,7 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
}
// transform the loops in an array of arrays of points
- vertices = new Vector2D[loops.size()][];
+ vertices = new Coordinates2D[loops.size()][];
int i = 0;
for (final List<Segment> loop : loops) {
@@ -663,14 +663,14 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
(loop.size() == 2 && loop.get(0).getStart() == null && loop.get(1).getEnd() == null)) {
// single infinite line
final Line line = loop.get(0).getLine();
- vertices[i++] = new Vector2D[] {
+ vertices[i++] = new Coordinates2D[] {
null,
- line.toSpace((Point<Euclidean1D>) new Vector1D(-Float.MAX_VALUE)),
- line.toSpace((Point<Euclidean1D>) new Vector1D(+Float.MAX_VALUE))
+ line.toSpace((Point<Euclidean1D>) new Coordinates1D(-Float.MAX_VALUE)),
+ line.toSpace((Point<Euclidean1D>) new Coordinates1D(+Float.MAX_VALUE))
};
} else if (loop.get(0).getStart() == null) {
// open loop with at least one real point
- final Vector2D[] array = new Vector2D[loop.size() + 2];
+ final Coordinates2D[] array = new Coordinates2D[loop.size() + 2];
int j = 0;
for (Segment segment : loop) {
@@ -679,7 +679,7 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
double x = segment.getLine().toSubSpace((Point<Euclidean2D>) segment.getEnd()).getX();
x -= FastMath.max(1.0, FastMath.abs(x / 2));
array[j++] = null;
- array[j++] = segment.getLine().toSpace((Point<Euclidean1D>) new Vector1D(x));
+ array[j++] = segment.getLine().toSpace((Point<Euclidean1D>) new Coordinates1D(x));
}
if (j < (array.length - 1)) {
@@ -691,13 +691,13 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
// last dummy point
double x = segment.getLine().toSubSpace((Point<Euclidean2D>) segment.getStart()).getX();
x += FastMath.max(1.0, FastMath.abs(x / 2));
- array[j++] = segment.getLine().toSpace((Point<Euclidean1D>) new Vector1D(x));
+ array[j++] = segment.getLine().toSpace((Point<Euclidean1D>) new Coordinates1D(x));
}
}
vertices[i++] = array;
} else {
- final Vector2D[] array = new Vector2D[loop.size()];
+ final Coordinates2D[] array = new Coordinates2D[loop.size()];
int j = 0;
for (Segment segment : loop) {
array[j++] = segment.getStart();
@@ -777,12 +777,12 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
int connected = 0;
for (final ConnectableSegment segment : segments) {
if (segment.getNext() == null && segment.getEnd() != null) {
- final Vector2D end = segment.getEnd();
+ final Coordinates2D end = segment.getEnd();
ConnectableSegment selectedNext = null;
double min = Double.POSITIVE_INFINITY;
for (final ConnectableSegment candidateNext : segments) {
if (candidateNext.getPrevious() == null && candidateNext.getStart() != null) {
- final double distance = Vector2D.distance(end, candidateNext.getStart());
+ final double distance = Coordinates2D.distance(end, candidateNext.getStart());
if (distance < min) {
selectedNext = candidateNext;
min = distance;
@@ -906,7 +906,7 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
* @param startNode node whose intersection with current node defines start point
* @param endNode node whose intersection with current node defines end point
*/
- ConnectableSegment(final Vector2D start, final Vector2D end, final Line line,
+ ConnectableSegment(final Coordinates2D start, final Coordinates2D end, final Line line,
final BSPTree<Euclidean2D> node,
final BSPTree<Euclidean2D> startNode,
final BSPTree<Euclidean2D> endNode) {
@@ -1044,10 +1044,10 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
for (final Interval i : intervals) {
// find the 2D points
- final Vector2D startV = Double.isInfinite(i.getInf()) ?
- null : (Vector2D) line.toSpace((Point<Euclidean1D>) new Vector1D(i.getInf()));
- final Vector2D endV = Double.isInfinite(i.getSup()) ?
- null : (Vector2D) line.toSpace((Point<Euclidean1D>) new Vector1D(i.getSup()));
+ final Coordinates2D startV = Double.isInfinite(i.getInf()) ?
+ null : (Coordinates2D) line.toSpace((Point<Euclidean1D>) new Coordinates1D(i.getInf()));
+ final Coordinates2D endV = Double.isInfinite(i.getSup()) ?
+ null : (Coordinates2D) line.toSpace((Point<Euclidean1D>) new Coordinates1D(i.getSup()));
// recover the connectivity information
final BSPTree<Euclidean2D> startN = selectClosest(startV, splitters);
@@ -1069,7 +1069,7 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
* @param candidates candidate nodes
* @return node closest to point, or null if no node is closer than tolerance
*/
- private BSPTree<Euclidean2D> selectClosest(final Vector2D point, final Iterable<BSPTree<Euclidean2D>> candidates) {
+ private BSPTree<Euclidean2D> selectClosest(final Coordinates2D point, final Iterable<BSPTree<Euclidean2D>> candidates) {
BSPTree<Euclidean2D> selected = null;
double min = Double.POSITIVE_INFINITY;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Segment.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Segment.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Segment.java
index 32e5c6b..2e48541 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Segment.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Segment.java
@@ -25,10 +25,10 @@ import org.apache.commons.math4.util.FastMath;
public class Segment {
/** Start point of the segment. */
- private final Vector2D start;
+ private final Coordinates2D start;
/** End point of the segment. */
- private final Vector2D end;
+ private final Coordinates2D end;
/** Line containing the segment. */
private final Line line;
@@ -38,7 +38,7 @@ public class Segment {
* @param end end point of the segment
* @param line line containing the segment
*/
- public Segment(final Vector2D start, final Vector2D end, final Line line) {
+ public Segment(final Coordinates2D start, final Coordinates2D end, final Line line) {
this.start = start;
this.end = end;
this.line = line;
@@ -47,14 +47,14 @@ public class Segment {
/** Get the start point of the segment.
* @return start point of the segment
*/
- public Vector2D getStart() {
+ public Coordinates2D getStart() {
return start;
}
/** Get the end point of the segment.
* @return end point of the segment
*/
- public Vector2D getEnd() {
+ public Coordinates2D getEnd() {
return end;
}
@@ -80,7 +80,7 @@ public class Segment {
* @return distance between the instance and the point
* @since 3.1
*/
- public double distance(final Vector2D p) {
+ public double distance(final Coordinates2D p) {
final double deltaX = end.getX() - start.getX();
final double deltaY = end.getY() - start.getY();
@@ -105,7 +105,7 @@ public class Segment {
final double px = start.getX() + r * deltaX;
final double py = start.getY() + r * deltaY;
- final Vector2D interPt = new Vector2D(px, py);
+ final Coordinates2D interPt = new Coordinates2D(px, py);
return interPt.distance((Point<Euclidean2D>) p);
}
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/SubLine.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/SubLine.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/SubLine.java
index eb24760..c7c0530 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/SubLine.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/SubLine.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.geometry.euclidean.oned.Euclidean1D;
import org.apache.commons.math4.geometry.euclidean.oned.Interval;
import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet;
import org.apache.commons.math4.geometry.euclidean.oned.OrientedPoint;
-import org.apache.commons.math4.geometry.euclidean.oned.Vector1D;
+import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D;
import org.apache.commons.math4.geometry.partitioning.AbstractSubHyperplane;
import org.apache.commons.math4.geometry.partitioning.BSPTree;
import org.apache.commons.math4.geometry.partitioning.Hyperplane;
@@ -53,7 +53,7 @@ public class SubLine extends AbstractSubHyperplane<Euclidean2D, Euclidean1D> {
* @param tolerance tolerance below which points are considered identical
* @since 3.3
*/
- public SubLine(final Vector2D start, final Vector2D end, final double tolerance) {
+ public SubLine(final Coordinates2D start, final Coordinates2D end, final double tolerance) {
super(new Line(start, end, tolerance), buildIntervalSet(start, end, tolerance));
}
@@ -86,8 +86,8 @@ public class SubLine extends AbstractSubHyperplane<Euclidean2D, Euclidean1D> {
final List<Segment> segments = new ArrayList<>(list.size());
for (final Interval interval : list) {
- final Vector2D start = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getInf()));
- final Vector2D end = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getSup()));
+ final Coordinates2D start = line.toSpace((Point<Euclidean1D>) new Coordinates1D(interval.getInf()));
+ final Coordinates2D end = line.toSpace((Point<Euclidean1D>) new Coordinates1D(interval.getSup()));
segments.add(new Segment(start, end, line));
}
@@ -109,14 +109,14 @@ public class SubLine extends AbstractSubHyperplane<Euclidean2D, Euclidean1D> {
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
- public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
+ public Coordinates2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
- Vector2D v2D = line1.intersection(line2);
+ Coordinates2D v2D = line1.intersection(line2);
if (v2D == null) {
return null;
}
@@ -141,10 +141,10 @@ public class SubLine extends AbstractSubHyperplane<Euclidean2D, Euclidean1D> {
* @param tolerance tolerance below which points are considered identical
* @return an interval set
*/
- private static IntervalsSet buildIntervalSet(final Vector2D start, final Vector2D end, final double tolerance) {
+ private static IntervalsSet buildIntervalSet(final Coordinates2D start, final Coordinates2D end, final double tolerance) {
final Line line = new Line(start, end, tolerance);
- return new IntervalsSet(line.toSubSpace((Point<Euclidean2D>) start).getX(),
- line.toSubSpace((Point<Euclidean2D>) end).getX(),
+ return new IntervalsSet(line.toSubSpace(start).getX(),
+ line.toSubSpace(end).getX(),
tolerance);
}
@@ -161,7 +161,7 @@ public class SubLine extends AbstractSubHyperplane<Euclidean2D, Euclidean1D> {
final Line thisLine = (Line) getHyperplane();
final Line otherLine = (Line) hyperplane;
- final Vector2D crossing = thisLine.intersection(otherLine);
+ final Coordinates2D crossing = thisLine.intersection(otherLine);
final double tolerance = thisLine.getTolerance();
if (crossing == null) {
@@ -178,7 +178,7 @@ public class SubLine extends AbstractSubHyperplane<Euclidean2D, Euclidean1D> {
// the lines do intersect
final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0;
- final Vector1D x = thisLine.toSubSpace((Point<Euclidean2D>) crossing);
+ final Coordinates1D x = thisLine.toSubSpace((Point<Euclidean2D>) crossing);
final SubHyperplane<Euclidean1D> subPlus =
new OrientedPoint(x, !direct, tolerance).wholeHyperplane();
final SubHyperplane<Euclidean1D> subMinus =
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/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
deleted file mode 100644
index fec599b..0000000
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java
+++ /dev/null
@@ -1,475 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.geometry.euclidean.twod;
-
-import java.text.NumberFormat;
-
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.geometry.Point;
-import org.apache.commons.math4.geometry.Space;
-import org.apache.commons.math4.geometry.Vector;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
-import org.apache.commons.math4.util.MathUtils;
-
-/** This class represents a 2D vector.
- * <p>Instances of this class are guaranteed to be immutable.</p>
- * @since 3.0
- */
-public class Vector2D implements Vector<Euclidean2D> {
-
- /** Origin (coordinates: 0, 0). */
- public static final Vector2D ZERO = new Vector2D(0, 0);
-
- // CHECKSTYLE: stop ConstantName
- /** A vector with all coordinates set to NaN. */
- public static final Vector2D NaN = new Vector2D(Double.NaN, Double.NaN);
- // CHECKSTYLE: resume ConstantName
-
- /** A vector with all coordinates set to positive infinity. */
- public static final Vector2D POSITIVE_INFINITY =
- new Vector2D(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
-
- /** A vector with all coordinates set to negative infinity. */
- public static final Vector2D NEGATIVE_INFINITY =
- new Vector2D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
-
- /** Serializable UID. */
- private static final long serialVersionUID = 266938651998679754L;
-
- /** Abscissa. */
- private final double x;
-
- /** Ordinate. */
- private final double y;
-
- /** Simple constructor.
- * Build a vector from its coordinates
- * @param x abscissa
- * @param y ordinate
- * @see #getX()
- * @see #getY()
- */
- public Vector2D(double x, double y) {
- this.x = x;
- this.y = y;
- }
-
- /** Simple constructor.
- * Build a vector from its coordinates
- * @param v coordinates array
- * @exception DimensionMismatchException if array does not have 2 elements
- * @see #toArray()
- */
- public Vector2D(double[] v) throws DimensionMismatchException {
- if (v.length != 2) {
- throw new DimensionMismatchException(v.length, 2);
- }
- this.x = v[0];
- this.y = v[1];
- }
-
- /** Multiplicative constructor
- * Build a vector from another one and a scale factor.
- * The vector built will be a * u
- * @param a scale factor
- * @param u base (unscaled) vector
- */
- public Vector2D(double a, Vector2D u) {
- this.x = a * u.x;
- this.y = a * u.y;
- }
-
- /** Linear constructor
- * Build a vector from two other ones and corresponding scale factors.
- * The vector built will be a1 * u1 + a2 * u2
- * @param a1 first scale factor
- * @param u1 first base (unscaled) vector
- * @param a2 second scale factor
- * @param u2 second base (unscaled) vector
- */
- public Vector2D(double a1, Vector2D u1, double a2, Vector2D u2) {
- this.x = a1 * u1.x + a2 * u2.x;
- this.y = a1 * u1.y + a2 * u2.y;
- }
-
- /** Linear constructor
- * Build a vector from three other ones and corresponding scale factors.
- * The vector built will be a1 * u1 + a2 * u2 + a3 * u3
- * @param a1 first scale factor
- * @param u1 first base (unscaled) vector
- * @param a2 second scale factor
- * @param u2 second base (unscaled) vector
- * @param a3 third scale factor
- * @param u3 third base (unscaled) vector
- */
- public Vector2D(double a1, Vector2D u1, double a2, Vector2D u2,
- double a3, Vector2D u3) {
- this.x = a1 * u1.x + a2 * u2.x + a3 * u3.x;
- this.y = a1 * u1.y + a2 * u2.y + a3 * u3.y;
- }
-
- /** Linear constructor
- * Build a vector from four other ones and corresponding scale factors.
- * The vector built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4
- * @param a1 first scale factor
- * @param u1 first base (unscaled) vector
- * @param a2 second scale factor
- * @param u2 second base (unscaled) vector
- * @param a3 third scale factor
- * @param u3 third base (unscaled) vector
- * @param a4 fourth scale factor
- * @param u4 fourth base (unscaled) vector
- */
- public Vector2D(double a1, Vector2D u1, double a2, Vector2D u2,
- double a3, Vector2D u3, double a4, Vector2D u4) {
- this.x = a1 * u1.x + a2 * u2.x + a3 * u3.x + a4 * u4.x;
- this.y = a1 * u1.y + a2 * u2.y + a3 * u3.y + a4 * u4.y;
- }
-
- /** Get the abscissa of the vector.
- * @return abscissa of the vector
- * @see #Vector2D(double, double)
- */
- public double getX() {
- return x;
- }
-
- /** Get the ordinate of the vector.
- * @return ordinate of the vector
- * @see #Vector2D(double, double)
- */
- public double getY() {
- return y;
- }
-
- /** Get the vector coordinates as a dimension 2 array.
- * @return vector coordinates
- * @see #Vector2D(double[])
- */
- public double[] toArray() {
- return new double[] { x, y };
- }
-
- /** {@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) {
- throw new MathArithmeticException(LocalizedFormats.CANNOT_NORMALIZE_A_ZERO_NORM_VECTOR);
- }
- return scalarMultiply(1 / s);
- }
-
- /** Compute the angular separation between two vectors.
- * <p>This method computes the angular separation between two
- * vectors using the dot product for well separated vectors and the
- * cross product for almost aligned vectors. This allows to have a
- * good accuracy in all cases, even for vectors very close to each
- * other.</p>
- * @param v1 first vector
- * @param v2 second vector
- * @return angular separation between v1 and v2
- * @exception MathArithmeticException if either vector has a null norm
- */
- public static double angle(Vector2D v1, Vector2D v2) throws MathArithmeticException {
-
- double normProduct = v1.getNorm() * v2.getNorm();
- if (normProduct == 0) {
- throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
- }
-
- double dot = v1.dotProduct(v2);
- double threshold = normProduct * 0.9999;
- if ((dot < -threshold) || (dot > threshold)) {
- // the vectors are almost aligned, compute using the sine
- final double n = FastMath.abs(MathArrays.linearCombination(v1.x, v2.y, -v1.y, v2.x));
- if (dot >= 0) {
- return FastMath.asin(n / normProduct);
- }
- return FastMath.PI - FastMath.asin(n / normProduct);
- }
-
- // the vectors are sufficiently separated to use the cosine
- return FastMath.acos(dot / normProduct);
-
- }
-
- /** {@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);
- final double dy = FastMath.abs(p3.y - y);
- return dx + dy;
- }
-
- /** {@inheritDoc} */
- @Override
- public double distance(Point<Euclidean2D> p) {
- Vector2D p3 = (Vector2D) p;
- final double dx = p3.x - x;
- final double dy = p3.y - y;
- return FastMath.sqrt(dx * dx + dy * dy);
- }
-
- /** {@inheritDoc} */
- @Override
- public double distanceInf(Vector<Euclidean2D> p) {
- Vector2D p3 = (Vector2D) p;
- final double dx = FastMath.abs(p3.x - x);
- final double dy = FastMath.abs(p3.y - y);
- return FastMath.max(dx, dy);
- }
-
- /** {@inheritDoc} */
- @Override
- public double distanceSq(Vector<Euclidean2D> p) {
- Vector2D p3 = (Vector2D) p;
- final double dx = p3.x - x;
- final double dy = p3.y - y;
- return dx * dx + dy * dy;
- }
-
- /** {@inheritDoc} */
- @Override
- public double dotProduct(final Vector<Euclidean2D> v) {
- final Vector2D v2 = (Vector2D) v;
- return MathArrays.linearCombination(x, v2.x, y, v2.y);
- }
-
- /**
- * Compute the cross-product of the instance and the given points.
- * <p>
- * The cross product can be used to determine the location of a point
- * with regard to the line formed by (p1, p2) and is calculated as:
- * \[
- * P = (x_2 - x_1)(y_3 - y_1) - (y_2 - y_1)(x_3 - x_1)
- * \]
- * with \(p3 = (x_3, y_3)\) being this instance.
- * <p>
- * If the result is 0, the points are collinear, i.e. lie on a single straight line L;
- * if it is positive, this point lies to the left, otherwise to the right of the line
- * formed by (p1, p2).
- *
- * @param p1 first point of the line
- * @param p2 second point of the line
- * @return the cross-product
- *
- * @see <a href="http://en.wikipedia.org/wiki/Cross_product">Cross product (Wikipedia)</a>
- */
- public double crossProduct(final Vector2D p1, final Vector2D p2) {
- 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 MathArrays.linearCombination(x1, y1, -x2, y2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>2</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>p1.subtract(p2).getNorm()</code> except that no intermediate
- * vector is built</p>
- * @param p1 first vector
- * @param p2 second vector
- * @return the distance between p1 and p2 according to the L<sub>2</sub> norm
- */
- public static double distance(Vector2D p1, Vector2D p2) {
- return p1.distance(p2);
- }
-
- /** Compute the distance between two vectors according to the L<sub>∞</sub> norm.
- * <p>Calling this method is equivalent to calling:
- * <code>p1.subtract(p2).getNormInf()</code> except that no intermediate
- * vector is built</p>
- * @param p1 first vector
- * @param p2 second vector
- * @return the distance between p1 and p2 according to the L<sub>∞</sub> norm
- */
- public static double distanceInf(Vector2D p1, Vector2D p2) {
- return p1.distanceInf(p2);
- }
-
- /** Compute the square of the distance between two vectors.
- * <p>Calling this method is equivalent to calling:
- * <code>p1.subtract(p2).getNormSq()</code> except that no intermediate
- * vector is built</p>
- * @param p1 first vector
- * @param p2 second vector
- * @return the square of the distance between p1 and p2
- */
- public static double distanceSq(Vector2D p1, Vector2D p2) {
- return p1.distanceSq(p2);
- }
-
- /**
- * Test for the equality of two 2D vectors.
- * <p>
- * If all coordinates of two 2D vectors are exactly the same, and none are
- * <code>Double.NaN</code>, the two 2D vectors are considered to be equal.
- * </p>
- * <p>
- * <code>NaN</code> coordinates are considered to affect globally the vector
- * and be equals to each other - i.e, if either (or all) coordinates of the
- * 2D vector are equal to <code>Double.NaN</code>, the 2D vector is equal to
- * {@link #NaN}.
- * </p>
- *
- * @param other Object to test for equality to this
- * @return true if two 2D vector objects are equal, false if
- * object is null, not an instance of Vector2D, or
- * not equal to this Vector2D instance
- *
- */
- @Override
- public boolean equals(Object other) {
-
- if (this == other) {
- return true;
- }
-
- if (other instanceof Vector2D) {
- final Vector2D rhs = (Vector2D)other;
- if (rhs.isNaN()) {
- return this.isNaN();
- }
-
- return (x == rhs.x) && (y == rhs.y);
- }
- return false;
- }
-
- /**
- * Get a hashCode for the 2D vector.
- * <p>
- * All NaN values have the same hash code.</p>
- *
- * @return a hash code value for this object
- */
- @Override
- public int hashCode() {
- if (isNaN()) {
- return 542;
- }
- return 122 * (76 * MathUtils.hash(x) + MathUtils.hash(y));
- }
-
- /** Get a string representation of this vector.
- * @return a string representation of this vector
- */
- @Override
- public String toString() {
- return Vector2DFormat.getInstance().format(this);
- }
-
- /** {@inheritDoc} */
- @Override
- public String toString(final NumberFormat format) {
- return new Vector2DFormat(format).format(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java
index af54313..04e825b 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java
@@ -108,31 +108,31 @@ public class Vector2DFormat extends VectorFormat<Euclidean2D> {
@Override
public StringBuffer format(final Vector<Euclidean2D> vector, final StringBuffer toAppendTo,
final FieldPosition pos) {
- final Vector2D p2 = (Vector2D) vector;
+ final Coordinates2D p2 = (Coordinates2D) vector;
return format(toAppendTo, pos, p2.getX(), p2.getY());
}
/** {@inheritDoc} */
@Override
- public Vector2D parse(final String source) throws MathParseException {
+ public Coordinates2D parse(final String source) throws MathParseException {
ParsePosition parsePosition = new ParsePosition(0);
- Vector2D result = parse(source, parsePosition);
+ Coordinates2D result = parse(source, parsePosition);
if (parsePosition.getIndex() == 0) {
throw new MathParseException(source,
parsePosition.getErrorIndex(),
- Vector2D.class);
+ Coordinates2D.class);
}
return result;
}
/** {@inheritDoc} */
@Override
- public Vector2D parse(final String source, final ParsePosition pos) {
+ public Coordinates2D parse(final String source, final ParsePosition pos) {
final double[] coordinates = parseCoordinates(2, source, pos);
if (coordinates == null) {
return null;
}
- return new Vector2D(coordinates[0], coordinates[1]);
+ return new Coordinates2D(coordinates[0], coordinates[1]);
}
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AbstractConvexHullGenerator2D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AbstractConvexHullGenerator2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AbstractConvexHullGenerator2D.java
index 9293b4e..38b5b4a 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AbstractConvexHullGenerator2D.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AbstractConvexHullGenerator2D.java
@@ -21,7 +21,7 @@ import java.util.Collection;
import org.apache.commons.math4.exception.ConvergenceException;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
+import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D;
import org.apache.commons.math4.util.MathUtils;
/**
@@ -86,12 +86,12 @@ abstract class AbstractConvexHullGenerator2D implements ConvexHullGenerator2D {
/** {@inheritDoc} */
@Override
- public ConvexHull2D generate(final Collection<Vector2D> points)
+ public ConvexHull2D generate(final Collection<Coordinates2D> points)
throws NullArgumentException, ConvergenceException {
// check for null points
MathUtils.checkNotNull(points);
- Collection<Vector2D> hullVertices = null;
+ Collection<Coordinates2D> hullVertices = null;
if (points.size() < 2) {
hullVertices = points;
} else {
@@ -99,7 +99,7 @@ abstract class AbstractConvexHullGenerator2D implements ConvexHullGenerator2D {
}
try {
- return new ConvexHull2D(hullVertices.toArray(new Vector2D[hullVertices.size()]),
+ return new ConvexHull2D(hullVertices.toArray(new Coordinates2D[hullVertices.size()]),
tolerance);
} catch (MathIllegalArgumentException e) {
// the hull vertices may not form a convex hull if the tolerance value is to large
@@ -112,6 +112,6 @@ abstract class AbstractConvexHullGenerator2D implements ConvexHullGenerator2D {
* @param points the set of input points
* @return the convex hull vertices in CCW winding
*/
- protected abstract Collection<Vector2D> findHullVertices(Collection<Vector2D> points);
+ protected abstract Collection<Coordinates2D> findHullVertices(Collection<Coordinates2D> points);
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AklToussaintHeuristic.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AklToussaintHeuristic.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AklToussaintHeuristic.java
index 84be4ac..49c399f 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AklToussaintHeuristic.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/AklToussaintHeuristic.java
@@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
+import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D;
/**
* A simple heuristic to improve the performance of convex hull algorithms.
@@ -50,15 +50,15 @@ public final class AklToussaintHeuristic {
* @param points the original point set
* @return a reduced point set, useful as input for convex hull algorithms
*/
- public static Collection<Vector2D> reducePoints(final Collection<Vector2D> points) {
+ public static Collection<Coordinates2D> reducePoints(final Collection<Coordinates2D> points) {
// find the leftmost point
int size = 0;
- Vector2D minX = null;
- Vector2D maxX = null;
- Vector2D minY = null;
- Vector2D maxY = null;
- for (Vector2D p : points) {
+ Coordinates2D minX = null;
+ Coordinates2D maxX = null;
+ Coordinates2D minY = null;
+ Coordinates2D maxY = null;
+ for (Coordinates2D p : points) {
if (minX == null || p.getX() < minX.getX()) {
minX = p;
}
@@ -78,14 +78,14 @@ public final class AklToussaintHeuristic {
return points;
}
- final List<Vector2D> quadrilateral = buildQuadrilateral(minY, maxX, maxY, minX);
+ final List<Coordinates2D> quadrilateral = buildQuadrilateral(minY, maxX, maxY, minX);
// if the quadrilateral is not well formed, e.g. only 2 points, do not attempt to reduce
if (quadrilateral.size() < 3) {
return points;
}
- final List<Vector2D> reducedPoints = new ArrayList<>(quadrilateral);
- for (final Vector2D p : points) {
+ final List<Coordinates2D> reducedPoints = new ArrayList<>(quadrilateral);
+ for (final Coordinates2D p : points) {
// check all points if they are within the quadrilateral
// in which case they can not be part of the convex hull
if (!insideQuadrilateral(p, quadrilateral)) {
@@ -102,9 +102,9 @@ public final class AklToussaintHeuristic {
* @param points the respective points with min/max x/y coordinate
* @return the quadrilateral
*/
- private static List<Vector2D> buildQuadrilateral(final Vector2D... points) {
- List<Vector2D> quadrilateral = new ArrayList<>();
- for (Vector2D p : points) {
+ private static List<Coordinates2D> buildQuadrilateral(final Coordinates2D... points) {
+ List<Coordinates2D> quadrilateral = new ArrayList<>();
+ for (Coordinates2D p : points) {
if (!quadrilateral.contains(p)) {
quadrilateral.add(p);
}
@@ -118,11 +118,11 @@ public final class AklToussaintHeuristic {
* @param quadrilateralPoints the convex quadrilateral, represented by 4 points
* @return {@code true} if the point is inside the quadrilateral, {@code false} otherwise
*/
- private static boolean insideQuadrilateral(final Vector2D point,
- final List<Vector2D> quadrilateralPoints) {
+ private static boolean insideQuadrilateral(final Coordinates2D point,
+ final List<Coordinates2D> quadrilateralPoints) {
- Vector2D p1 = quadrilateralPoints.get(0);
- Vector2D p2 = quadrilateralPoints.get(1);
+ Coordinates2D p1 = quadrilateralPoints.get(0);
+ Coordinates2D p2 = quadrilateralPoints.get(1);
if (point.equals(p1) || point.equals(p2)) {
return true;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHull2D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHull2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHull2D.java
index 7356da1..801f4d7 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHull2D.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHull2D.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D;
import org.apache.commons.math4.geometry.euclidean.twod.Line;
import org.apache.commons.math4.geometry.euclidean.twod.Segment;
-import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
+import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D;
import org.apache.commons.math4.geometry.hull.ConvexHull;
import org.apache.commons.math4.geometry.partitioning.Region;
import org.apache.commons.math4.geometry.partitioning.RegionFactory;
@@ -36,13 +36,13 @@ import org.apache.commons.math4.util.Precision;
*
* @since 3.3
*/
-public class ConvexHull2D implements ConvexHull<Euclidean2D, Vector2D>, Serializable {
+public class ConvexHull2D implements ConvexHull<Euclidean2D, Coordinates2D>, Serializable {
/** Serializable UID. */
private static final long serialVersionUID = 20140129L;
/** Vertices of the hull. */
- private final Vector2D[] vertices;
+ private final Coordinates2D[] vertices;
/** Tolerance threshold used during creation of the hull vertices. */
private final double tolerance;
@@ -59,7 +59,7 @@ public class ConvexHull2D implements ConvexHull<Euclidean2D, Vector2D>, Serializ
* @param tolerance tolerance below which points are considered identical
* @throws MathIllegalArgumentException if the vertices do not form a convex hull
*/
- public ConvexHull2D(final Vector2D[] vertices, final double tolerance)
+ public ConvexHull2D(final Coordinates2D[] vertices, final double tolerance)
throws MathIllegalArgumentException {
// assign tolerance as it will be used by the isConvex method
@@ -77,19 +77,19 @@ public class ConvexHull2D implements ConvexHull<Euclidean2D, Vector2D>, Serializ
* @param hullVertices the hull vertices
* @return {@code true} if the vertices form a convex hull, {@code false} otherwise
*/
- private boolean isConvex(final Vector2D[] hullVertices) {
+ private boolean isConvex(final Coordinates2D[] hullVertices) {
if (hullVertices.length < 3) {
return true;
}
int sign = 0;
for (int i = 0; i < hullVertices.length; i++) {
- final Vector2D p1 = hullVertices[i == 0 ? hullVertices.length - 1 : i - 1];
- final Vector2D p2 = hullVertices[i];
- final Vector2D p3 = hullVertices[i == hullVertices.length - 1 ? 0 : i + 1];
+ final Coordinates2D p1 = hullVertices[i == 0 ? hullVertices.length - 1 : i - 1];
+ final Coordinates2D p2 = hullVertices[i];
+ final Coordinates2D p3 = hullVertices[i == hullVertices.length - 1 ? 0 : i + 1];
- final Vector2D d1 = p2.subtract(p1);
- final Vector2D d2 = p3.subtract(p2);
+ final Coordinates2D d1 = p2.subtract(p1);
+ final Coordinates2D d2 = p3.subtract(p2);
final double crossProduct = MathArrays.linearCombination(d1.getX(), d2.getY(), -d1.getY(), d2.getX());
final int cmp = Precision.compareTo(crossProduct, 0.0, tolerance);
@@ -107,7 +107,7 @@ public class ConvexHull2D implements ConvexHull<Euclidean2D, Vector2D>, Serializ
/** {@inheritDoc} */
@Override
- public Vector2D[] getVertices() {
+ public Coordinates2D[] getVertices() {
return vertices.clone();
}
@@ -132,15 +132,15 @@ public class ConvexHull2D implements ConvexHull<Euclidean2D, Vector2D>, Serializ
this.lineSegments = new Segment[0];
} else if (size == 2) {
this.lineSegments = new Segment[1];
- final Vector2D p1 = vertices[0];
- final Vector2D p2 = vertices[1];
+ final Coordinates2D p1 = vertices[0];
+ final Coordinates2D p2 = vertices[1];
this.lineSegments[0] = new Segment(p1, p2, new Line(p1, p2, tolerance));
} else {
this.lineSegments = new Segment[size];
- Vector2D firstPoint = null;
- Vector2D lastPoint = null;
+ Coordinates2D firstPoint = null;
+ Coordinates2D lastPoint = null;
int index = 0;
- for (Vector2D point : vertices) {
+ for (Coordinates2D point : vertices) {
if (lastPoint == null) {
firstPoint = point;
lastPoint = point;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2D.java
index 3557147..310cb0d 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2D.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2D.java
@@ -21,7 +21,7 @@ import java.util.Collection;
import org.apache.commons.math4.exception.ConvergenceException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D;
-import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
+import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D;
import org.apache.commons.math4.geometry.hull.ConvexHullGenerator;
/**
@@ -29,10 +29,10 @@ import org.apache.commons.math4.geometry.hull.ConvexHullGenerator;
*
* @since 3.3
*/
-public interface ConvexHullGenerator2D extends ConvexHullGenerator<Euclidean2D, Vector2D> {
+public interface ConvexHullGenerator2D extends ConvexHullGenerator<Euclidean2D, Coordinates2D> {
/** {@inheritDoc} */
@Override
- ConvexHull2D generate(Collection<Vector2D> points) throws NullArgumentException, ConvergenceException;
+ ConvexHull2D generate(Collection<Coordinates2D> points) throws NullArgumentException, ConvergenceException;
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/MonotoneChain.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/MonotoneChain.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/MonotoneChain.java
index 5746c7f..08d27f8 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/MonotoneChain.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/hull/MonotoneChain.java
@@ -23,7 +23,7 @@ import java.util.Comparator;
import java.util.List;
import org.apache.commons.math4.geometry.euclidean.twod.Line;
-import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
+import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.Precision;
@@ -75,15 +75,15 @@ public class MonotoneChain extends AbstractConvexHullGenerator2D {
/** {@inheritDoc} */
@Override
- public Collection<Vector2D> findHullVertices(final Collection<Vector2D> points) {
+ public Collection<Coordinates2D> findHullVertices(final Collection<Coordinates2D> points) {
- final List<Vector2D> pointsSortedByXAxis = new ArrayList<>(points);
+ final List<Coordinates2D> pointsSortedByXAxis = new ArrayList<>(points);
// sort the points in increasing order on the x-axis
- Collections.sort(pointsSortedByXAxis, new Comparator<Vector2D>() {
+ Collections.sort(pointsSortedByXAxis, new Comparator<Coordinates2D>() {
/** {@inheritDoc} */
@Override
- public int compare(final Vector2D o1, final Vector2D o2) {
+ public int compare(final Coordinates2D o1, final Coordinates2D o2) {
final double tolerance = getTolerance();
// need to take the tolerance value into account, otherwise collinear points
// will not be handled correctly when building the upper/lower hull
@@ -97,21 +97,21 @@ public class MonotoneChain extends AbstractConvexHullGenerator2D {
});
// build lower hull
- final List<Vector2D> lowerHull = new ArrayList<>();
- for (Vector2D p : pointsSortedByXAxis) {
+ final List<Coordinates2D> lowerHull = new ArrayList<>();
+ for (Coordinates2D p : pointsSortedByXAxis) {
updateHull(p, lowerHull);
}
// build upper hull
- final List<Vector2D> upperHull = new ArrayList<>();
+ final List<Coordinates2D> upperHull = new ArrayList<>();
for (int idx = pointsSortedByXAxis.size() - 1; idx >= 0; idx--) {
- final Vector2D p = pointsSortedByXAxis.get(idx);
+ final Coordinates2D p = pointsSortedByXAxis.get(idx);
updateHull(p, upperHull);
}
// concatenate the lower and upper hulls
// the last point of each list is omitted as it is repeated at the beginning of the other list
- final List<Vector2D> hullVertices = new ArrayList<>(lowerHull.size() + upperHull.size() - 2);
+ final List<Coordinates2D> hullVertices = new ArrayList<>(lowerHull.size() + upperHull.size() - 2);
for (int idx = 0; idx < lowerHull.size() - 1; idx++) {
hullVertices.add(lowerHull.get(idx));
}
@@ -133,12 +133,12 @@ public class MonotoneChain extends AbstractConvexHullGenerator2D {
* @param point the current point
* @param hull the partial hull
*/
- private void updateHull(final Vector2D point, final List<Vector2D> hull) {
+ private void updateHull(final Coordinates2D point, final List<Coordinates2D> hull) {
final double tolerance = getTolerance();
if (hull.size() == 1) {
// ensure that we do not add an identical point
- final Vector2D p1 = hull.get(0);
+ final Coordinates2D p1 = hull.get(0);
if (p1.distance(point) < tolerance) {
return;
}
@@ -146,8 +146,8 @@ public class MonotoneChain extends AbstractConvexHullGenerator2D {
while (hull.size() >= 2) {
final int size = hull.size();
- final Vector2D p1 = hull.get(size - 2);
- final Vector2D p2 = hull.get(size - 1);
+ final Coordinates2D p1 = hull.get(size - 2);
+ final Coordinates2D p2 = hull.get(size - 1);
final double offset = new Line(p1, p2, tolerance).getOffset(point);
if (FastMath.abs(offset) < tolerance) {
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/partitioning/AbstractRegion.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/partitioning/AbstractRegion.java b/src/main/java/org/apache/commons/math4/geometry/partitioning/AbstractRegion.java
index 9463bb8..a52c38f 100644
--- a/src/main/java/org/apache/commons/math4/geometry/partitioning/AbstractRegion.java
+++ b/src/main/java/org/apache/commons/math4/geometry/partitioning/AbstractRegion.java
@@ -321,9 +321,9 @@ public abstract class AbstractRegion<S extends Space, T extends Space> implement
* Region.Location#INSIDE}, {@link Region.Location#OUTSIDE} or
* {@link Region.Location#BOUNDARY}
*/
- public Location checkPoint(final Vector<S> point) {
- return checkPoint((Point<S>) point);
- }
+// public Location checkPoint(final Vector<S> point) {
+// return checkPoint((Point<S>) point);
+// }
/** {@inheritDoc} */
@Override
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/spherical/oned/S1Point.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/spherical/oned/S1Point.java b/src/main/java/org/apache/commons/math4/geometry/spherical/oned/S1Point.java
index 2395fd2..841d1db 100644
--- a/src/main/java/org/apache/commons/math4/geometry/spherical/oned/S1Point.java
+++ b/src/main/java/org/apache/commons/math4/geometry/spherical/oned/S1Point.java
@@ -18,7 +18,7 @@ package org.apache.commons.math4.geometry.spherical.oned;
import org.apache.commons.math4.geometry.Point;
import org.apache.commons.math4.geometry.Space;
-import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
+import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathUtils;
@@ -30,7 +30,7 @@ public class S1Point implements Point<Sphere1D> {
// CHECKSTYLE: stop ConstantName
/** A vector with all coordinates set to NaN. */
- public static final S1Point NaN = new S1Point(Double.NaN, Vector2D.NaN);
+ public static final S1Point NaN = new S1Point(Double.NaN, Coordinates2D.NaN);
// CHECKSTYLE: resume ConstantName
/** Serializable UID. */
@@ -40,7 +40,7 @@ public class S1Point implements Point<Sphere1D> {
private final double alpha;
/** Corresponding 2D normalized vector. */
- private final Vector2D vector;
+ private final Coordinates2D vector;
/** Simple constructor.
* Build a vector from its coordinates
@@ -49,14 +49,14 @@ public class S1Point implements Point<Sphere1D> {
*/
public S1Point(final double alpha) {
this(MathUtils.normalizeAngle(alpha, FastMath.PI),
- new Vector2D(FastMath.cos(alpha), FastMath.sin(alpha)));
+ new Coordinates2D(FastMath.cos(alpha), FastMath.sin(alpha)));
}
/** Build a point from its internal components.
* @param alpha azimuthal angle \( \alpha \)
* @param vector corresponding vector
*/
- private S1Point(final double alpha, final Vector2D vector) {
+ private S1Point(final double alpha, final Coordinates2D vector) {
this.alpha = alpha;
this.vector = vector;
}
@@ -72,7 +72,7 @@ public class S1Point implements Point<Sphere1D> {
/** Get the corresponding normalized vector in the 2D euclidean space.
* @return normalized vector
*/
- public Vector2D getVector() {
+ public Coordinates2D getVector() {
return vector;
}
@@ -100,7 +100,7 @@ public class S1Point implements Point<Sphere1D> {
* @return the angular separation between p1 and p2
*/
public static double distance(S1Point p1, S1Point p2) {
- return Vector2D.angle(p1.vector, p2.vector);
+ return Coordinates2D.angle(p1.vector, p2.vector);
}
/**
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Circle.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Circle.java b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Circle.java
index 62eba43..871f729 100644
--- a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Circle.java
+++ b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Circle.java
@@ -18,7 +18,7 @@ package org.apache.commons.math4.geometry.spherical.twod;
import org.apache.commons.math4.geometry.Point;
import org.apache.commons.math4.geometry.euclidean.threed.Rotation;
-import org.apache.commons.math4.geometry.euclidean.threed.Vector3D;
+import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D;
import org.apache.commons.math4.geometry.partitioning.Embedding;
import org.apache.commons.math4.geometry.partitioning.Hyperplane;
import org.apache.commons.math4.geometry.partitioning.SubHyperplane;
@@ -45,13 +45,13 @@ import org.apache.commons.math4.util.FastMath;
public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1D> {
/** Pole or circle center. */
- private Vector3D pole;
+ private Coordinates3D pole;
/** First axis in the equator plane, origin of the phase angles. */
- private Vector3D x;
+ private Coordinates3D x;
/** Second axis in the equator plane, in quadrature with respect to x. */
- private Vector3D y;
+ private Coordinates3D y;
/** Tolerance below which close sub-arcs are merged together. */
private final double tolerance;
@@ -61,7 +61,7 @@ public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1
* @param pole circle pole
* @param tolerance tolerance below which close sub-arcs are merged together
*/
- public Circle(final Vector3D pole, final double tolerance) {
+ public Circle(final Coordinates3D pole, final double tolerance) {
reset(pole);
this.tolerance = tolerance;
}
@@ -84,7 +84,7 @@ public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1
* @param y second axis in the equator plane
* @param tolerance tolerance below which close sub-arcs are merged together
*/
- private Circle(final Vector3D pole, final Vector3D x, final Vector3D y,
+ private Circle(final Coordinates3D pole, final Coordinates3D x, final Coordinates3D y,
final double tolerance) {
this.pole = pole;
this.x = x;
@@ -111,10 +111,10 @@ public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1
* <p>The circle is oriented in the trigonometric direction around pole.</p>
* @param newPole circle pole
*/
- public void reset(final Vector3D newPole) {
+ public void reset(final Coordinates3D newPole) {
this.pole = newPole.normalize();
this.x = newPole.orthogonal();
- this.y = Vector3D.crossProduct(newPole, x).normalize();
+ this.y = Coordinates3D.crossProduct(newPole, x).normalize();
}
/** Revert the instance.
@@ -164,7 +164,7 @@ public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1
* @return phase angle of the direction around the circle
* @see #toSubSpace(Point)
*/
- public double getPhase(final Vector3D direction) {
+ public double getPhase(final Coordinates3D direction) {
return FastMath.PI + FastMath.atan2(-direction.dotProduct(y), -direction.dotProduct(x));
}
@@ -183,8 +183,8 @@ public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1
* @see #getXAxis()
* @see #getYAxis()
*/
- public Vector3D getPointAt(final double alpha) {
- return new Vector3D(FastMath.cos(alpha), x, FastMath.sin(alpha), y);
+ public Coordinates3D getPointAt(final double alpha) {
+ return new Coordinates3D(FastMath.cos(alpha), x, FastMath.sin(alpha), y);
}
/** Get the X axis of the circle.
@@ -198,7 +198,7 @@ public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1
* @see #getYAxis()
* @see #getPole()
*/
- public Vector3D getXAxis() {
+ public Coordinates3D getXAxis() {
return x;
}
@@ -213,7 +213,7 @@ public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1
* @see #getXAxis()
* @see #getPole()
*/
- public Vector3D getYAxis() {
+ public Coordinates3D getYAxis() {
return y;
}
@@ -226,7 +226,7 @@ public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1
* @see #getXAxis()
* @see #getYAxis()
*/
- public Vector3D getPole() {
+ public Coordinates3D getPole() {
return pole;
}
@@ -272,15 +272,15 @@ public class Circle implements Hyperplane<Sphere2D>, Embedding<Sphere2D, Sphere1
* @return offset of the direction
* @see #getOffset(Point)
*/
- public double getOffset(final Vector3D direction) {
- return Vector3D.angle(pole, direction) - 0.5 * FastMath.PI;
+ public double getOffset(final Coordinates3D direction) {
+ return Coordinates3D.angle(pole, direction) - 0.5 * FastMath.PI;
}
/** {@inheritDoc} */
@Override
public boolean sameOrientationAs(final Hyperplane<Sphere2D> other) {
final Circle otherC = (Circle) other;
- return Vector3D.dotProduct(pole, otherC.pole) >= 0.0;
+ return Coordinates3D.dotProduct(pole, otherC.pole) >= 0.0;
}
/** Get a {@link org.apache.commons.math4.geometry.partitioning.Transform
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Edge.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Edge.java b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Edge.java
index 8c13baa..6fe2635 100644
--- a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Edge.java
+++ b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/Edge.java
@@ -18,7 +18,7 @@ package org.apache.commons.math4.geometry.spherical.twod;
import java.util.List;
-import org.apache.commons.math4.geometry.euclidean.threed.Vector3D;
+import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D;
import org.apache.commons.math4.geometry.spherical.oned.Arc;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathUtils;
@@ -99,7 +99,7 @@ public class Edge {
* @param alpha angle along the edge, counted from {@link #getStart()}
* @return an intermediate point
*/
- public Vector3D getPointAt(final double alpha) {
+ public Coordinates3D getPointAt(final double alpha) {
return circle.getPointAt(alpha + circle.getPhase(start.getLocation().getVector()));
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/spherical/twod/EdgesBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/EdgesBuilder.java b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/EdgesBuilder.java
index 86f12c6..5e3f918 100644
--- a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/EdgesBuilder.java
+++ b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/EdgesBuilder.java
@@ -23,7 +23,7 @@ import java.util.Map;
import org.apache.commons.math4.exception.MathIllegalStateException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.geometry.euclidean.threed.Vector3D;
+import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D;
import org.apache.commons.math4.geometry.partitioning.BSPTree;
import org.apache.commons.math4.geometry.partitioning.BSPTreeVisitor;
import org.apache.commons.math4.geometry.partitioning.BoundaryAttribute;
@@ -128,8 +128,8 @@ class EdgesBuilder implements BSPTreeVisitor<Sphere2D> {
for (final BSPTree<Sphere2D> node : candidates) {
for (final Edge edge : nodeToEdgesList.get(node)) {
if (edge != previous && edge.getStart().getIncoming() == null) {
- final Vector3D edgeStart = edge.getStart().getLocation().getVector();
- final double gap = Vector3D.angle(point.getVector(), edgeStart);
+ final Coordinates3D edgeStart = edge.getStart().getLocation().getVector();
+ final double gap = Coordinates3D.angle(point.getVector(), edgeStart);
if (gap <= closest) {
closest = gap;
following = edge;
@@ -139,8 +139,8 @@ class EdgesBuilder implements BSPTreeVisitor<Sphere2D> {
}
if (following == null) {
- final Vector3D previousStart = previous.getStart().getLocation().getVector();
- if (Vector3D.angle(point.getVector(), previousStart) <= tolerance) {
+ final Coordinates3D previousStart = previous.getStart().getLocation().getVector();
+ if (Coordinates3D.angle(point.getVector(), previousStart) <= tolerance) {
// the edge connects back to itself
return previous;
}