diff --git a/src/main/java/org/apache/commons/math3/geometry/Point.java b/src/main/java/org/apache/commons/math3/geometry/Point.java index 7ac892c32..85c057ef5 100644 --- a/src/main/java/org/apache/commons/math3/geometry/Point.java +++ b/src/main/java/org/apache/commons/math3/geometry/Point.java @@ -38,4 +38,10 @@ public interface Point extends Serializable { */ boolean isNaN(); + /** Compute the distance between the instance and another point. + * @param p second point + * @return the distance between the instance and p + */ + double distance(Point p); + } diff --git a/src/main/java/org/apache/commons/math3/geometry/Vector.java b/src/main/java/org/apache/commons/math3/geometry/Vector.java index 8ab965f5e..20fb6b95b 100644 --- a/src/main/java/org/apache/commons/math3/geometry/Vector.java +++ b/src/main/java/org/apache/commons/math3/geometry/Vector.java @@ -120,7 +120,9 @@ public interface Vector extends Point { * vector is built

* @param v second vector * @return the distance between the instance and p according to the L2 norm + * @deprecated as of 3.3 replaced with {@link Point#distance(Point)} */ + @Deprecated double distance(Vector v); /** Compute the distance between the instance and another vector according to the L norm. diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java index efad25805..77ed14496 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.geometry.partitioning.AbstractRegion; import org.apache.commons.math3.geometry.partitioning.BSPTree; import org.apache.commons.math3.geometry.partitioning.SubHyperplane; @@ -73,7 +74,7 @@ public class IntervalsSet extends AbstractRegion { * boundary does not really separate an inside open from an outside * open (open having here its topological meaning), then subsequent * calls to the {@link - * org.apache.commons.math3.geometry.partitioning.Region#checkPoint(org.apache.commons.math3.geometry.Vector) + * org.apache.commons.math3.geometry.partitioning.Region#checkPoint(org.apache.commons.math3.geometry.Point) * checkPoint} method will not be meaningful anymore.

*

If the boundary is empty, the region will represent the whole * space.

@@ -137,7 +138,7 @@ public class IntervalsSet extends AbstractRegion { @Override protected void computeGeometricalProperties() { if (getTree(false).getCut() == null) { - setBarycenter(Vector1D.NaN); + setBarycenter((Point) Vector1D.NaN); setSize(((Boolean) getTree(false).getAttribute()) ? Double.POSITIVE_INFINITY : 0); } else { double size = 0.0; @@ -148,11 +149,11 @@ public class IntervalsSet extends AbstractRegion { } setSize(size); if (Double.isInfinite(size)) { - setBarycenter(Vector1D.NaN); + setBarycenter((Point) Vector1D.NaN); } else if (size >= Precision.SAFE_MIN) { - setBarycenter(new Vector1D(sum / size)); + setBarycenter((Point) new Vector1D(sum / size)); } else { - setBarycenter(((OrientedPoint) getTree(false).getCut().getHyperplane()).getLocation()); + setBarycenter((Point) ((OrientedPoint) getTree(false).getCut().getHyperplane()).getLocation()); } } } @@ -238,8 +239,8 @@ public class IntervalsSet extends AbstractRegion { op.isDirect() ? node.getPlus() : node.getMinus(); recurseList(low, list, lower, x); - if ((checkPoint(low, loc) == Location.INSIDE) && - (checkPoint(high, loc) == Location.INSIDE)) { + if ((checkPoint(low, (Point) loc) == Location.INSIDE) && + (checkPoint(high, (Point) loc) == Location.INSIDE)) { // merge the last interval added and the first one of the high sub-tree x = list.remove(list.size() - 1).getInf(); } diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/OrientedPoint.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/OrientedPoint.java index 68d867649..d56e0cef8 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/OrientedPoint.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/OrientedPoint.java @@ -17,6 +17,7 @@ package org.apache.commons.math3.geometry.euclidean.oned; import org.apache.commons.math3.geometry.Point; +import org.apache.commons.math3.geometry.Vector; import org.apache.commons.math3.geometry.partitioning.Hyperplane; /** This class represents a 1D oriented hyperplane. @@ -53,6 +54,16 @@ public class OrientedPoint implements Hyperplane { return this; } + /** Get the offset (oriented distance) of a vector. + * @param vector vector to check + * @return offset of the vector + * @deprecated as of 3.3, replaced with {@link #getOffset(Point)} + */ + @Deprecated + public double getOffset(Vector vector) { + return getOffset((Point) vector); + } + /** {@inheritDoc} */ public double getOffset(final Point point) { final double delta = ((Vector1D) point).getX() - location.getX(); diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Vector1D.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Vector1D.java index a6cc428ad..ae4151d32 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Vector1D.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Vector1D.java @@ -20,6 +20,7 @@ import java.text.NumberFormat; import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.exception.util.LocalizedFormats; +import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.geometry.Space; import org.apache.commons.math3.geometry.Vector; import org.apache.commons.math3.util.FastMath; @@ -217,8 +218,16 @@ public class Vector1D implements Vector { return dx; } - /** {@inheritDoc} */ + /** {@inheritDoc} + * @deprecated as of 3.3, replaced with {@link #distance(Point)} + */ + @Deprecated public double distance(Vector p) { + return distance((Point) p); + } + + /** {@inheritDoc} */ + public double distance(Point p) { Vector1D p3 = (Vector1D) p; final double dx = p3.x - x; return FastMath.abs(dx); diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java index d55a53b35..07d1f59ba 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java @@ -19,6 +19,7 @@ package org.apache.commons.math3.geometry.euclidean.threed; import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.util.LocalizedFormats; import org.apache.commons.math3.geometry.Point; +import org.apache.commons.math3.geometry.Vector; import org.apache.commons.math3.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math3.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math3.geometry.euclidean.oned.Vector1D; @@ -122,6 +123,28 @@ public class Line implements Embedding { return new Vector3D(1.0, zero, abscissa, direction); } + /** Transform a space point into a sub-space point. + * @param vector n-dimension point of the space + * @return (n-1)-dimension point of the sub-space corresponding to + * the specified space point + * @deprecated as of 3.3, replaced with {@link #toSubSpace(Point)} + */ + @Deprecated + public Vector1D toSubSpace(Vector vector) { + return toSubSpace((Point) 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 + * @deprecated as of 3.3, replaced with {@link #toSpace(Point)} + */ + @Deprecated + public Vector3D toSpace(Vector vector) { + return toSpace((Point) vector); + } + /** {@inheritDoc} * @see #getAbscissa(Vector3D) */ diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/OutlineExtractor.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/OutlineExtractor.java index f652420e9..6ad6b6eed 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/OutlineExtractor.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/OutlineExtractor.java @@ -18,6 +18,7 @@ package org.apache.commons.math3.geometry.euclidean.threed; import java.util.ArrayList; +import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.geometry.euclidean.twod.Euclidean2D; import org.apache.commons.math3.geometry.euclidean.twod.PolygonsSet; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; @@ -199,13 +200,13 @@ public class OutlineExtractor { for (Vector2D[] loop : vertices) { final boolean closed = loop[0] != null; int previous = closed ? (loop.length - 1) : 1; - Vector3D previous3D = plane.toSpace(loop[previous]); + Vector3D previous3D = plane.toSpace((Point) loop[previous]); int current = (previous + 1) % loop.length; Vector2D pPoint = new Vector2D(previous3D.dotProduct(u), previous3D.dotProduct(v)); while (current < loop.length) { - final Vector3D current3D = plane.toSpace(loop[current]); + final Vector3D current3D = plane.toSpace((Point) loop[current]); final Vector2D cPoint = new Vector2D(current3D.dotProduct(u), current3D.dotProduct(v)); final org.apache.commons.math3.geometry.euclidean.twod.Line line = diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Plane.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Plane.java index d39414064..6a7369fbf 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Plane.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Plane.java @@ -19,6 +19,8 @@ package org.apache.commons.math3.geometry.euclidean.threed; import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.exception.util.LocalizedFormats; import org.apache.commons.math3.geometry.Point; +import org.apache.commons.math3.geometry.Vector; +import org.apache.commons.math3.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math3.geometry.euclidean.oned.Vector1D; import org.apache.commons.math3.geometry.euclidean.twod.Euclidean2D; import org.apache.commons.math3.geometry.euclidean.twod.PolygonsSet; @@ -216,6 +218,28 @@ public class Plane implements Hyperplane, Embedding vector) { + return toSubSpace((Point) 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 + * @deprecated as of 3.3, replaced with {@link #toSpace(Point)} + */ + @Deprecated + public Vector3D toSpace(Vector vector) { + return toSpace((Point) vector); + } + /** Transform a 3D space point into an in-plane point. * @param point point of the space (must be a {@link Vector3D * Vector3D} instance) @@ -311,7 +335,7 @@ public class Plane implements Hyperplane, Embedding) Vector1D.ZERO); final double k = -(originOffset + w.dotProduct(point)) / dot; return new Vector3D(1.0, point, k, direction); } @@ -409,6 +433,16 @@ public class Plane implements Hyperplane, Embedding vector) { + return getOffset((Point) vector); + } + /** Get the offset (oriented distance) of a point. *

The offset is 0 if the point is on the underlying hyperplane, * it is positive if the point is on one particular side of the diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java index 3a19048f3..f43c15604 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java @@ -72,7 +72,7 @@ public class PolyhedronsSet extends AbstractRegion { * (their topological connections are not used here). However, if the * boundary does not really separate an inside open from an outside * open (open having here its topological meaning), then subsequent - * calls to the {@link Region#checkPoint(Vector) checkPoint} method will + * calls to the {@link Region#checkPoint(Point) checkPoint} method will * not be meaningful anymore.

*

If the boundary is empty, the region will represent the whole * space.

@@ -138,11 +138,11 @@ public class PolyhedronsSet extends AbstractRegion { // the polyhedrons set as a finite outside // surrounded by an infinite inside setSize(Double.POSITIVE_INFINITY); - setBarycenter(Vector3D.NaN); + setBarycenter((Point) Vector3D.NaN); } else { // the polyhedrons set is finite, apply the remaining scaling factors setSize(getSize() / 3.0); - setBarycenter(new Vector3D(1.0 / (4 * getSize()), (Vector3D) getBarycenter())); + setBarycenter((Point) new Vector3D(1.0 / (4 * getSize()), (Vector3D) getBarycenter())); } } @@ -153,7 +153,7 @@ public class PolyhedronsSet extends AbstractRegion { /** Simple constructor. */ public FacetsContributionVisitor() { setSize(0); - setBarycenter(new Vector3D(0, 0, 0)); + setBarycenter((Point) new Vector3D(0, 0, 0)); } /** {@inheritDoc} */ @@ -189,7 +189,7 @@ public class PolyhedronsSet extends AbstractRegion { if (Double.isInfinite(area)) { setSize(Double.POSITIVE_INFINITY); - setBarycenter(Vector3D.NaN); + setBarycenter((Point) Vector3D.NaN); } else { final Plane plane = (Plane) facet.getHyperplane(); @@ -200,7 +200,7 @@ public class PolyhedronsSet extends AbstractRegion { } setSize(getSize() + scaled); - setBarycenter(new Vector3D(1.0, (Vector3D) getBarycenter(), scaled, facetB)); + setBarycenter((Point) new Vector3D(1.0, (Vector3D) getBarycenter(), scaled, facetB)); } @@ -240,7 +240,7 @@ public class PolyhedronsSet extends AbstractRegion { final Plane plane = (Plane) cut.getHyperplane(); // establish search order - final double offset = plane.getOffset(point); + final double offset = plane.getOffset((Point) point); final boolean in = FastMath.abs(offset) < 1.0e-10; final BSPTree near; final BSPTree far; @@ -290,7 +290,7 @@ public class PolyhedronsSet extends AbstractRegion { */ private SubHyperplane boundaryFacet(final Vector3D point, final BSPTree node) { - final Vector2D point2D = ((Plane) node.getCut().getHyperplane()).toSubSpace(point); + final Vector2D point2D = ((Plane) node.getCut().getHyperplane()).toSubSpace((Point) point); @SuppressWarnings("unchecked") final BoundaryAttribute attribute = (BoundaryAttribute) node.getAttribute(); @@ -360,11 +360,11 @@ public class PolyhedronsSet extends AbstractRegion { final Plane oPlane = (Plane) original; final Plane tPlane = (Plane) transformed; final Vector3D p00 = oPlane.getOrigin(); - final Vector3D p10 = oPlane.toSpace(new Vector2D(1.0, 0.0)); - final Vector3D p01 = oPlane.toSpace(new Vector2D(0.0, 1.0)); - final Vector2D tP00 = tPlane.toSubSpace(apply(p00)); - final Vector2D tP10 = tPlane.toSubSpace(apply(p10)); - final Vector2D tP01 = tPlane.toSubSpace(apply(p01)); + final Vector3D p10 = oPlane.toSpace((Point) new Vector2D(1.0, 0.0)); + final Vector3D p01 = oPlane.toSpace((Point) new Vector2D(0.0, 1.0)); + final Vector2D tP00 = tPlane.toSubSpace((Point) apply(p00)); + final Vector2D tP10 = tPlane.toSubSpace((Point) apply(p10)); + final Vector2D tP01 = tPlane.toSubSpace((Point) apply(p01)); final AffineTransform at = new AffineTransform(tP10.getX() - tP00.getX(), tP10.getY() - tP00.getY(), tP01.getX() - tP00.getX(), tP01.getY() - tP00.getY(), @@ -426,7 +426,7 @@ public class PolyhedronsSet extends AbstractRegion { final Plane oPlane = (Plane) original; final Plane tPlane = (Plane) transformed; - final Vector2D shift = tPlane.toSubSpace(apply(oPlane.getOrigin())); + final Vector2D shift = tPlane.toSubSpace((Point) apply(oPlane.getOrigin())); final AffineTransform at = AffineTransform.getTranslateInstance(shift.getX(), shift.getY()); diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java index 62a91d1a2..4d3879d67 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java @@ -20,6 +20,8 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.math3.exception.MathIllegalArgumentException; +import org.apache.commons.math3.geometry.Point; +import org.apache.commons.math3.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math3.geometry.euclidean.oned.Interval; import org.apache.commons.math3.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math3.geometry.euclidean.oned.Vector1D; @@ -84,8 +86,8 @@ public class SubLine { final List segments = new ArrayList(list.size()); for (final Interval interval : list) { - final Vector3D start = line.toSpace(new Vector1D(interval.getInf())); - final Vector3D end = line.toSpace(new Vector1D(interval.getSup())); + final Vector3D start = line.toSpace((Point) new Vector1D(interval.getInf())); + final Vector3D end = line.toSpace((Point) new Vector1D(interval.getSup())); segments.add(new Segment(start, end, line)); } @@ -116,10 +118,10 @@ public class SubLine { } // check location of point with respect to first sub-line - Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D)); + Location loc1 = remainingRegion.checkPoint((Point) line.toSubSpace((Point) v1D)); // check location of point with respect to second sub-line - Location loc2 = subLine.remainingRegion.checkPoint(subLine.line.toSubSpace(v1D)); + Location loc2 = subLine.remainingRegion.checkPoint((Point) subLine.line.toSubSpace((Point) v1D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null; @@ -138,8 +140,8 @@ public class SubLine { private static IntervalsSet buildIntervalSet(final Vector3D start, final Vector3D end) throws MathIllegalArgumentException { final Line line = new Line(start, end); - return new IntervalsSet(line.toSubSpace(start).getX(), - line.toSubSpace(end).getX()); + return new IntervalsSet(line.toSubSpace((Point) start).getX(), + line.toSubSpace((Point) end).getX()); } } diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubPlane.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubPlane.java index 51e7778c0..c815d736e 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubPlane.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubPlane.java @@ -16,6 +16,8 @@ */ package org.apache.commons.math3.geometry.euclidean.threed; +import org.apache.commons.math3.geometry.Point; +import org.apache.commons.math3.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math3.geometry.euclidean.oned.Vector1D; import org.apache.commons.math3.geometry.euclidean.twod.Euclidean2D; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; @@ -71,8 +73,8 @@ public class SubPlane extends AbstractSubHyperplane { // (i.e. the 3D half space on the plus side (resp. minus side) // of the instance contains the 2D half plane on the plus side // (resp. minus side) of the 2D line - Vector2D p = thisPlane.toSubSpace(inter.toSpace(Vector1D.ZERO)); - Vector2D q = thisPlane.toSubSpace(inter.toSpace(Vector1D.ONE)); + Vector2D p = thisPlane.toSubSpace((Point) inter.toSpace((Point) Vector1D.ZERO)); + Vector2D q = thisPlane.toSubSpace((Point) inter.toSpace((Point) Vector1D.ONE)); Vector3D crossP = Vector3D.crossProduct(inter.getDirection(), thisPlane.getNormal()); if (crossP.dotProduct(otherPlane.getNormal()) < 0) { final Vector2D tmp = p; @@ -109,8 +111,8 @@ public class SubPlane extends AbstractSubHyperplane { } // the hyperplanes do intersect - Vector2D p = thisPlane.toSubSpace(inter.toSpace(Vector1D.ZERO)); - Vector2D q = thisPlane.toSubSpace(inter.toSpace(Vector1D.ONE)); + Vector2D p = thisPlane.toSubSpace((Point) inter.toSpace((Point) Vector1D.ZERO)); + Vector2D q = thisPlane.toSubSpace((Point) inter.toSpace((Point) Vector1D.ONE)); Vector3D crossP = Vector3D.crossProduct(inter.getDirection(), thisPlane.getNormal()); if (crossP.dotProduct(otherPlane.getNormal()) < 0) { final Vector2D tmp = p; diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Vector3D.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Vector3D.java index 2809a59fb..a0f7765de 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Vector3D.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Vector3D.java @@ -23,11 +23,12 @@ import java.text.NumberFormat; import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.exception.util.LocalizedFormats; -import org.apache.commons.math3.geometry.Vector; +import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.geometry.Space; +import org.apache.commons.math3.geometry.Vector; import org.apache.commons.math3.util.FastMath; -import org.apache.commons.math3.util.MathUtils; import org.apache.commons.math3.util.MathArrays; +import org.apache.commons.math3.util.MathUtils; /** * This class implements vectors in a three-dimensional space. @@ -474,8 +475,16 @@ public class Vector3D implements Serializable, Vector { return dx + dy + dz; } - /** {@inheritDoc} */ + /** {@inheritDoc} + * @deprecated as of 3.3, replaced with {@link #distance(Point)} + */ + @Deprecated public double distance(Vector v) { + return distance((Point) v); + } + + /** {@inheritDoc} */ + public double distance(Point v) { final Vector3D v3 = (Vector3D) v; final double dx = v3.x - x; final double dy = v3.y - y; diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java index 1ef29f4a0..a13432bc1 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java @@ -21,6 +21,7 @@ import java.awt.geom.AffineTransform; import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.util.LocalizedFormats; import org.apache.commons.math3.geometry.Point; +import org.apache.commons.math3.geometry.Vector; import org.apache.commons.math3.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math3.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math3.geometry.euclidean.oned.OrientedPoint; @@ -176,6 +177,28 @@ public class Line implements Hyperplane, Embedding vector) { + return toSubSpace((Point) 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 + * @deprecated as of 3.3, replaced with {@link #toSpace(Point)} + */ + @Deprecated + public Vector2D toSpace(Vector vector) { + return toSpace((Point) vector); + } + /** {@inheritDoc} */ public Vector1D toSubSpace(final Point point) { Vector2D p2 = (Vector2D) point; @@ -231,6 +254,16 @@ public class Line implements Hyperplane, Embedding 0) ? -line.originOffset : line.originOffset); } + /** Get the offset (oriented distance) of a vector. + * @param vector vector to check + * @return offset of the vector + * @deprecated as of 3.3, replaced with {@link #getOffset(Point)} + */ + @Deprecated + public double getOffset(Vector vector) { + return getOffset((Point) vector); + } + /** {@inheritDoc} */ public double getOffset(final Point point) { Vector2D p2 = (Vector2D) point; diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/NestedLoops.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/NestedLoops.java index 5bf445c26..7bb4e7f90 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/NestedLoops.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/NestedLoops.java @@ -21,6 +21,7 @@ import java.util.Iterator; import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.util.LocalizedFormats; +import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math3.geometry.partitioning.Region; import org.apache.commons.math3.geometry.partitioning.RegionFactory; @@ -90,7 +91,8 @@ class NestedLoops { current = loop[i]; final Line line = new Line(previous, current); final IntervalsSet region = - new IntervalsSet(line.toSubSpace(previous).getX(), line.toSubSpace(current).getX()); + new IntervalsSet(line.toSubSpace((Point) previous).getX(), + line.toSubSpace((Point) current).getX()); edges.add(new SubLine(line, region)); } polygon = new PolygonsSet(edges); diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java index 5277e35e3..e7d0824b0 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.List; import org.apache.commons.math3.exception.MathInternalError; +import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math3.geometry.euclidean.oned.Interval; import org.apache.commons.math3.geometry.euclidean.oned.IntervalsSet; @@ -207,7 +208,7 @@ public class PolygonsSet extends AbstractRegion { // check if another vertex also happens to be on this line for (final Vertex vertex : vArray) { if (vertex != start && vertex != end && - FastMath.abs(line.getOffset(vertex.getLocation())) <= hyperplaneThickness) { + FastMath.abs(line.getOffset((Point) vertex.getLocation())) <= hyperplaneThickness) { vertex.bindWith(line); } } @@ -268,8 +269,8 @@ public class PolygonsSet extends AbstractRegion { final List minusList = new ArrayList(); for (final Edge edge : edges) { if (edge != inserted) { - final double startOffset = inserted.getLine().getOffset(edge.getStart().getLocation()); - final double endOffset = inserted.getLine().getOffset(edge.getEnd().getLocation()); + final double startOffset = inserted.getLine().getOffset((Point) edge.getStart().getLocation()); + final double endOffset = inserted.getLine().getOffset((Point) edge.getEnd().getLocation()); Side startSide = (FastMath.abs(startOffset) <= hyperplaneThickness) ? Side.HYPER : ((startOffset < 0) ? Side.MINUS : Side.PLUS); Side endSide = (FastMath.abs(endOffset) <= hyperplaneThickness) ? @@ -527,15 +528,15 @@ public class PolygonsSet extends AbstractRegion { if (tree.getCut() == null && (Boolean) tree.getAttribute()) { // the instance covers the whole space setSize(Double.POSITIVE_INFINITY); - setBarycenter(Vector2D.NaN); + setBarycenter((Point) Vector2D.NaN); } else { setSize(0); - setBarycenter(new Vector2D(0, 0)); + setBarycenter((Point) new Vector2D(0, 0)); } } else if (v[0][0] == null) { // there is at least one open-loop: the polygon is infinite setSize(Double.POSITIVE_INFINITY); - setBarycenter(Vector2D.NaN); + setBarycenter((Point) Vector2D.NaN); } else { // all loops are closed, we compute some integrals around the shape @@ -561,10 +562,10 @@ public class PolygonsSet extends AbstractRegion { if (sum < 0) { // the polygon as a finite outside surrounded by an infinite inside setSize(Double.POSITIVE_INFINITY); - setBarycenter(Vector2D.NaN); + setBarycenter((Point) Vector2D.NaN); } else { setSize(sum / 2); - setBarycenter(new Vector2D(sumX / (3 * sum), sumY / (3 * sum))); + setBarycenter((Point) new Vector2D(sumX / (3 * sum), sumY / (3 * sum))); } } @@ -626,8 +627,8 @@ public class PolygonsSet extends AbstractRegion { final Line line = loop.get(0).getLine(); vertices[i++] = new Vector2D[] { null, - line.toSpace(new Vector1D(-Float.MAX_VALUE)), - line.toSpace(new Vector1D(+Float.MAX_VALUE)) + line.toSpace((Point) new Vector1D(-Float.MAX_VALUE)), + line.toSpace((Point) new Vector1D(+Float.MAX_VALUE)) }; } else if (loop.get(0).getStart() == null) { // open loop with at least one real point @@ -637,10 +638,10 @@ public class PolygonsSet extends AbstractRegion { if (j == 0) { // null point and first dummy point - double x = segment.getLine().toSubSpace(segment.getEnd()).getX(); + double x = segment.getLine().toSubSpace((Point) segment.getEnd()).getX(); x -= FastMath.max(1.0, FastMath.abs(x / 2)); array[j++] = null; - array[j++] = segment.getLine().toSpace(new Vector1D(x)); + array[j++] = segment.getLine().toSpace((Point) new Vector1D(x)); } if (j < (array.length - 1)) { @@ -650,9 +651,9 @@ public class PolygonsSet extends AbstractRegion { if (j == (array.length - 1)) { // last dummy point - double x = segment.getLine().toSubSpace(segment.getStart()).getX(); + double x = segment.getLine().toSubSpace((Point) segment.getStart()).getX(); x += FastMath.max(1.0, FastMath.abs(x / 2)); - array[j++] = segment.getLine().toSpace(new Vector1D(x)); + array[j++] = segment.getLine().toSpace((Point) new Vector1D(x)); } } @@ -694,7 +695,7 @@ public class PolygonsSet extends AbstractRegion { // is this an open or a closed loop ? final boolean open = segment.getStart() == null; - while ((end != null) && (open || (globalStart.distance(end) > 1.0e-10))) { + while ((end != null) && (open || (globalStart.distance((Point) end) > 1.0e-10))) { // search the sub-hyperplane starting where the previous one ended AVLTree.Node selectedNode = null; @@ -706,7 +707,7 @@ public class PolygonsSet extends AbstractRegion { (n != null) && (n.getElement().compareTo(upperRight) <= 0); n = n.getNext()) { segment = n.getElement(); - final double distance = end.distance(segment.getStart()); + final double distance = end.distance((Point) segment.getStart()); if (distance < selectedDistance) { selectedNode = n; selectedSegment = segment; @@ -842,9 +843,9 @@ public class PolygonsSet extends AbstractRegion { final List intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList(); for (final Interval i : intervals) { final Vector2D start = Double.isInfinite(i.getInf()) ? - null : (Vector2D) line.toSpace(new Vector1D(i.getInf())); + null : (Vector2D) line.toSpace((Point) new Vector1D(i.getInf())); final Vector2D end = Double.isInfinite(i.getSup()) ? - null : (Vector2D) line.toSpace(new Vector1D(i.getSup())); + null : (Vector2D) line.toSpace((Point) new Vector1D(i.getSup())); if (reversed) { sorted.insert(new ComparableSegment(end, start, line.getReverse())); } else { diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Segment.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Segment.java index 121de1270..ad01437da 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Segment.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Segment.java @@ -16,6 +16,7 @@ */ package org.apache.commons.math3.geometry.euclidean.twod; +import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.util.FastMath; /** Simple container for a two-points segment. @@ -95,8 +96,8 @@ public class Segment { // if point isn't on the line segment, just return the shortest distance to the end points if (r < 0 || r > 1) { - final double dist1 = getStart().distance(p); - final double dist2 = getEnd().distance(p); + final double dist1 = getStart().distance((Point) p); + final double dist2 = getEnd().distance((Point) p); return FastMath.min(dist1, dist2); } @@ -106,7 +107,7 @@ public class Segment { final double py = start.getY() + r * deltaY; final Vector2D interPt = new Vector2D(px, py); - return interPt.distance(p); + return interPt.distance((Point) p); } } } diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java index b5d02a445..8967cd2d6 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java @@ -19,6 +19,7 @@ package org.apache.commons.math3.geometry.euclidean.twod; import java.util.ArrayList; import java.util.List; +import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math3.geometry.euclidean.oned.Interval; import org.apache.commons.math3.geometry.euclidean.oned.IntervalsSet; @@ -84,8 +85,8 @@ public class SubLine extends AbstractSubHyperplane { final List segments = new ArrayList(list.size()); for (final Interval interval : list) { - final Vector2D start = line.toSpace(new Vector1D(interval.getInf())); - final Vector2D end = line.toSpace(new Vector1D(interval.getSup())); + final Vector2D start = line.toSpace((Point) new Vector1D(interval.getInf())); + final Vector2D end = line.toSpace((Point) new Vector1D(interval.getSup())); segments.add(new Segment(start, end, line)); } @@ -120,10 +121,10 @@ public class SubLine extends AbstractSubHyperplane { } // check location of point with respect to first sub-line - Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D)); + Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace((Point) v2D)); // check location of point with respect to second sub-line - Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D)); + Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace((Point) v2D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null; @@ -140,8 +141,8 @@ public class SubLine extends AbstractSubHyperplane { */ private static IntervalsSet buildIntervalSet(final Vector2D start, final Vector2D end) { final Line line = new Line(start, end); - return new IntervalsSet(line.toSubSpace(start).getX(), - line.toSubSpace(end).getX()); + return new IntervalsSet(line.toSubSpace((Point) start).getX(), + line.toSubSpace((Point) end).getX()); } /** {@inheritDoc} */ @@ -167,7 +168,7 @@ public class SubLine extends AbstractSubHyperplane { // the lines do intersect final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0; - final Vector1D x = thisLine.toSubSpace(crossing); + final Vector1D x = thisLine.toSubSpace((Point) crossing); return getRemainingRegion().side(new OrientedPoint(x, direct)); } @@ -190,7 +191,7 @@ public class SubLine extends AbstractSubHyperplane { // the lines do intersect final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0; - final Vector1D x = thisLine.toSubSpace(crossing); + final Vector1D x = thisLine.toSubSpace((Point) crossing); final SubHyperplane subPlus = new OrientedPoint(x, !direct).wholeHyperplane(); final SubHyperplane subMinus = new OrientedPoint(x, direct).wholeHyperplane(); diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Vector2D.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Vector2D.java index 6043d8575..eaee92b97 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Vector2D.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Vector2D.java @@ -21,6 +21,7 @@ import java.text.NumberFormat; import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.MathArithmeticException; import org.apache.commons.math3.exception.util.LocalizedFormats; +import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.geometry.Space; import org.apache.commons.math3.geometry.Vector; import org.apache.commons.math3.util.FastMath; @@ -292,8 +293,16 @@ public class Vector2D implements Vector { return dx + dy; } - /** {@inheritDoc} */ + /** {@inheritDoc} + * @deprecated as of 3.3, replaced with {@link #distance(Point)} + */ + @Deprecated public double distance(Vector p) { + return distance((Point) p); + } + + /** {@inheritDoc} */ + public double distance(Point p) { Vector2D p3 = (Vector2D) p; final double dx = p3.x - x; final double dy = p3.y - y; diff --git a/src/main/java/org/apache/commons/math3/geometry/partitioning/AbstractRegion.java b/src/main/java/org/apache/commons/math3/geometry/partitioning/AbstractRegion.java index 41e820060..63c631d7f 100644 --- a/src/main/java/org/apache/commons/math3/geometry/partitioning/AbstractRegion.java +++ b/src/main/java/org/apache/commons/math3/geometry/partitioning/AbstractRegion.java @@ -26,6 +26,8 @@ import java.util.TreeSet; import org.apache.commons.math3.exception.MathInternalError; import org.apache.commons.math3.geometry.Space; import org.apache.commons.math3.geometry.Point; +import org.apache.commons.math3.geometry.Vector; +import org.apache.commons.math3.geometry.partitioning.Region.Location; /** Abstract class for all regions, independently of geometry type or dimension. @@ -249,11 +251,35 @@ public abstract class AbstractRegion implement return new RegionFactory().difference(region, this).isEmpty(); } + /** Check a point with respect to the region. + * @param point point to check + * @return a code representing the point status: either {@link + * Location#INSIDE}, {@link Location#OUTSIDE} or {@link Location#BOUNDARY} + * @deprecated as of 3.3, replaced with {@link #checkPoint(Point)} + */ + @Deprecated + public Location checkPoint(final Vector point) { + return checkPoint((Point) point); + } + /** {@inheritDoc} */ public Location checkPoint(final Point point) { return checkPoint(tree, point); } + /** Check a point with respect to the region starting at a given node. + * @param node root node of the region + * @param point point to check + * @return a code representing the point status: either {@link + * Region.Location#INSIDE INSIDE}, {@link Region.Location#OUTSIDE + * OUTSIDE} or {@link Region.Location#BOUNDARY BOUNDARY} + * @deprecated as of 3.3, replaced with {@link #checkPoint(BSPTree, Point)} + */ + @Deprecated + protected Location checkPoint(final BSPTree node, final Vector point) { + return checkPoint(node, (Point) point); + } + /** Check a point with respect to the region starting at a given node. * @param node root node of the region * @param point point to check @@ -430,6 +456,15 @@ public abstract class AbstractRegion implement return barycenter; } + /** Set the barycenter of the instance. + * @param barycenter barycenter of the instance + * @deprecated as of 3.3, replaced with {@link #setBarycenter(Point)} + */ + @Deprecated + protected void setBarycenter(final Vector barycenter) { + setBarycenter((Point) barycenter); + } + /** Set the barycenter of the instance. * @param barycenter barycenter of the instance */ diff --git a/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java b/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java index 784aa0b70..dd8096c7d 100644 --- a/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java +++ b/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.commons.math3.exception.MathInternalError; import org.apache.commons.math3.geometry.Point; import org.apache.commons.math3.geometry.Space; +import org.apache.commons.math3.geometry.Vector; import org.apache.commons.math3.util.FastMath; /** This class represent a Binary Space Partition tree. @@ -308,7 +309,20 @@ public class BSPTree { * interior of the node, if the cell is an internal node the points * belongs to the node cut sub-hyperplane.

* @param point point to check - * @return the tree cell to which the point belongs (can be + * @return the tree cell to which the point belongs + * @deprecated as of 3.3, replaced with {@link #getCell(Point)} + */ + @Deprecated + public BSPTree getCell(final Vector point) { + return getCell((Point) point); + } + + /** Get the cell to which a point belongs. + *

If the returned cell is a leaf node the points belongs to the + * interior of the node, if the cell is an internal node the points + * belongs to the node cut sub-hyperplane.

+ * @param point point to check + * @return the tree cell to which the point belongs */ public BSPTree getCell(final Point point) { diff --git a/src/main/java/org/apache/commons/math3/geometry/spherical/oned/ArcsSet.java b/src/main/java/org/apache/commons/math3/geometry/spherical/oned/ArcsSet.java index e26b3f37d..63020e290 100644 --- a/src/main/java/org/apache/commons/math3/geometry/spherical/oned/ArcsSet.java +++ b/src/main/java/org/apache/commons/math3/geometry/spherical/oned/ArcsSet.java @@ -90,7 +90,7 @@ public class ArcsSet extends AbstractRegion { * boundary does not really separate an inside open from an outside * open (open having here its topological meaning), then subsequent * calls to the {@link - * org.apache.commons.math3.geometry.partitioning.Region#checkPoint(org.apache.commons.math3.geometry.Vector) + * org.apache.commons.math3.geometry.partitioning.Region#checkPoint(org.apache.commons.math3.geometry.Point) * checkPoint} method will not be meaningful anymore.

*

If the boundary is empty, the region will represent the whole * space.

diff --git a/src/main/java/org/apache/commons/math3/geometry/spherical/oned/S1Point.java b/src/main/java/org/apache/commons/math3/geometry/spherical/oned/S1Point.java index 077476d6e..e7184d93d 100644 --- a/src/main/java/org/apache/commons/math3/geometry/spherical/oned/S1Point.java +++ b/src/main/java/org/apache/commons/math3/geometry/spherical/oned/S1Point.java @@ -86,6 +86,11 @@ public class S1Point implements Point { return Double.isNaN(alpha); } + /** {@inheritDoc} */ + public double distance(final Point point) { + return distance(this, (S1Point) point); + } + /** Compute the distance (angular separation) between two points. * @param p1 first vector * @param p2 second vector diff --git a/src/main/java/org/apache/commons/math3/geometry/spherical/oned/Sphere1D.java b/src/main/java/org/apache/commons/math3/geometry/spherical/oned/Sphere1D.java index 54bba045d..bd782de3b 100644 --- a/src/main/java/org/apache/commons/math3/geometry/spherical/oned/Sphere1D.java +++ b/src/main/java/org/apache/commons/math3/geometry/spherical/oned/Sphere1D.java @@ -22,7 +22,6 @@ import java.io.Serializable; import org.apache.commons.math3.exception.MathUnsupportedOperationException; import org.apache.commons.math3.exception.util.LocalizedFormats; import org.apache.commons.math3.geometry.Space; -import org.apache.commons.math3.geometry.spherical.oned.Sphere1D; /** * This class implements a one-dimensional sphere (i.e. a circle). diff --git a/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Circle.java b/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Circle.java index 57ac3cc05..184479aea 100644 --- a/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Circle.java +++ b/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Circle.java @@ -285,7 +285,7 @@ public class Circle implements Hyperplane, Embedding Point}, {@link Circle Line} or {@link + * Point Point}, {@link Circle Line} or {@link * org.apache.commons.math3.geometry.partitioning.SubHyperplane * SubHyperplane} instances */ diff --git a/src/main/java/org/apache/commons/math3/geometry/spherical/twod/S2Point.java b/src/main/java/org/apache/commons/math3/geometry/spherical/twod/S2Point.java index 54f3f8e90..d3de93068 100644 --- a/src/main/java/org/apache/commons/math3/geometry/spherical/twod/S2Point.java +++ b/src/main/java/org/apache/commons/math3/geometry/spherical/twod/S2Point.java @@ -169,6 +169,11 @@ public class S2Point implements Point { return new S2Point(-theta, FastMath.PI - phi, vector.negate()); } + /** {@inheritDoc} */ + public double distance(final Point point) { + return distance(this, (S2Point) point); + } + /** Compute the distance (angular separation) between two points. * @param p1 first vector * @param p2 second vector diff --git a/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java b/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java index ca5fdcdf5..a305ecc0e 100644 --- a/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java +++ b/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java @@ -104,8 +104,8 @@ public class SphericalPolygonsSet extends AbstractRegion { *

This constructor does not handle polygons with a boundary * forming several disconnected paths (such as polygons with holes).

*

For cases where this simple constructor applies, it is expected to - * be numerically more robust than the {@link #PolygonsSet(Collection) general - * constructor} using {@link SubHyperplane subhyperplanes}.

+ * be numerically more robust than the {@link #SphericalPolygonsSet(Collection, + * double) general constructor} using {@link SubHyperplane subhyperplanes}.

*

If the list is empty, the region will represent the whole * space.

*

@@ -804,10 +804,9 @@ public class SphericalPolygonsSet extends AbstractRegion { // find the edge associated with the selected node for (final Edge edge : edges) { - if (edge.getNode() == selected) { - if (Vector3D.angle(point.getVector(), edge.getStart().getLocation().getVector()) <= tolerance) { - return edge; - } + if (edge.getNode() == selected && + Vector3D.angle(point.getVector(), edge.getStart().getLocation().getVector()) <= tolerance) { + return edge; } }