*/
- private static class LineTransform implements Transform {
+ private static class LineTransform implements Transform {
// CHECKSTYLE: stop JavadocVariable check
private double cXX;
@@ -478,16 +398,16 @@ public class Line implements Hyperplane {
}
/** {@inheritDoc} */
- public Point apply(final Point point) {
- final Point2D p2D = (Point2D) point;
+ public Vector2D apply(final Vector point) {
+ final Vector2D p2D = (Vector2D) point;
final double x = p2D.getX();
final double y = p2D.getY();
- return new Point2D(cXX * x + cXY * y + cX1,
+ return new Vector2D(cXX * x + cXY * y + cX1,
cYX * x + cYY * y + cY1);
}
/** {@inheritDoc} */
- public Hyperplane apply(final Hyperplane hyperplane) {
+ public Line apply(final Hyperplane hyperplane) {
final Line line = (Line) hyperplane;
final double rOffset = c1X * line.cos + c1Y * line.sin + c11 * line.originOffset;
final double rCos = cXX * line.cos + cXY * line.sin;
@@ -499,12 +419,15 @@ public class Line implements Hyperplane {
}
/** {@inheritDoc} */
- public SubHyperplane apply(final SubHyperplane sub,
- final Hyperplane original, final Hyperplane transformed) {
- final OrientedPoint op = (OrientedPoint) sub.getHyperplane();
- final Point1D newLoc =
- (Point1D) transformed.toSubSpace(apply(original.toSpace(op.getLocation())));
- return new SubHyperplane(new OrientedPoint(newLoc, op.isDirect()));
+ public SubHyperplane apply(final SubHyperplane sub,
+ final Hyperplane original,
+ final Hyperplane transformed) {
+ final OrientedPoint op = (OrientedPoint) sub.getHyperplane();
+ final Line originalLine = (Line) original;
+ final Line transformedLine = (Line) transformed;
+ final Vector1D newLoc =
+ transformedLine.toSubSpace(apply(originalLine.toSpace(op.getLocation())));
+ return new OrientedPoint(newLoc, op.isDirect()).wholeHyperplane();
}
}
diff --git a/src/main/java/org/apache/commons/math/geometry/euclidean/twod/NestedLoops.java b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/NestedLoops.java
index 687a7da96..3c4169d33 100644
--- a/src/main/java/org/apache/commons/math/geometry/euclidean/twod/NestedLoops.java
+++ b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/NestedLoops.java
@@ -17,44 +17,43 @@
package org.apache.commons.math.geometry.euclidean.twod;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.util.LocalizedFormats;
-import org.apache.commons.math.geometry.euclidean.oned.OrientedPoint;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
-import org.apache.commons.math.geometry.partitioning.Hyperplane;
+import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.RegionFactory;
import org.apache.commons.math.geometry.partitioning.SubHyperplane;
/** This class represent a tree of nested 2D boundary loops.
- * This class is used during Piece instances construction.
- * Beams are built using the outline edges as
- * representative of facets, the orientation of these facets are
+ *
This class is used for piecewise polygons construction.
+ * Polygons are built using the outline edges as
+ * representative of boundaries, the orientation of these lines are
* meaningful. However, we want to allow the user to specify its
* outline loops without having to take care of this orientation. This
* class is devoted to correct mis-oriented loops.
- *
Orientation is computed assuming the piece is finite, i.e. the
- * outermost loops have their exterior side facing points at infinity,
- * and hence are oriented counter-clockwise. The orientation of
+ *
Orientation is computed assuming the piecewise polygon is finite,
+ * i.e. the outermost loops have their exterior side facing points at
+ * infinity, and hence are oriented counter-clockwise. The orientation of
* internal loops is computed as the reverse of the orientation of
* their immediate surrounding loop.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
*/
class NestedLoops {
/** Boundary loop. */
- private Point2D[] loop;
+ private Vector2D[] loop;
/** Surrounded loops. */
private ArrayList surrounded;
/** Polygon enclosing a finite region. */
- private Region polygon;
+ private Region polygon;
/** Indicator for original loop orientation. */
private boolean originalIsClockwise;
@@ -74,7 +73,7 @@ class NestedLoops {
* @param loop boundary loop (will be reversed in place if needed)
* @exception MathIllegalArgumentException if an outline has an open boundary loop
*/
- private NestedLoops(final Point2D[] loop) throws MathIllegalArgumentException {
+ private NestedLoops(final Vector2D[] loop) throws MathIllegalArgumentException {
if (loop[0] == null) {
throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
@@ -84,23 +83,21 @@ class NestedLoops {
surrounded = new ArrayList();
// build the polygon defined by the loop
- final ArrayList edges = new ArrayList();
- Point2D current = loop[loop.length - 1];
+ final ArrayList> edges = new ArrayList>();
+ Vector2D current = loop[loop.length - 1];
for (int i = 0; i < loop.length; ++i) {
- final Point2D previous = current;
+ final Vector2D previous = current;
current = loop[i];
final Line line = new Line(previous, current);
- final Region region = Region.buildConvex(Arrays.asList(new Hyperplane[] {
- new OrientedPoint((Point1D) line.toSubSpace(previous), false),
- new OrientedPoint((Point1D) line.toSubSpace(current), true)
- }));
- edges.add(new SubHyperplane(line, region));
+ final IntervalsSet region =
+ new IntervalsSet(line.toSubSpace(previous).getX(), line.toSubSpace(current).getX());
+ edges.add(new SubLine(line, region));
}
polygon = new PolygonsSet(edges);
// ensure the polygon encloses a finite region of the plane
if (Double.isInfinite(polygon.getSize())) {
- polygon = polygon.getComplement();
+ polygon = new RegionFactory().getComplement(polygon);
originalIsClockwise = false;
} else {
originalIsClockwise = true;
@@ -113,7 +110,7 @@ class NestedLoops {
* @exception MathIllegalArgumentException if an outline has crossing
* boundary loops or open boundary loops
*/
- public void add(final Point2D[] bLoop) throws MathIllegalArgumentException {
+ public void add(final Vector2D[] bLoop) throws MathIllegalArgumentException {
add(new NestedLoops(bLoop));
}
@@ -142,8 +139,9 @@ class NestedLoops {
}
// we should be separate from the remaining children
+ RegionFactory factory = new RegionFactory();
for (final NestedLoops child : surrounded) {
- if (!Region.intersection(node.polygon, child.polygon).isEmpty()) {
+ if (!factory.intersection(node.polygon, child.polygon).isEmpty()) {
throw new MathIllegalArgumentException(LocalizedFormats.CROSSING_BOUNDARY_LOOPS);
}
}
@@ -154,7 +152,7 @@ class NestedLoops {
/** Correct the orientation of the loops contained in the tree.
* This is this method that really inverts the loops that where
- * provided through the {@link #add(Point2D[]) add} method if
+ * provided through the {@link #add(Vector2D[]) add} method if
* they are mis-oriented
*/
public void correctOrientation() {
@@ -174,7 +172,7 @@ class NestedLoops {
int min = -1;
int max = loop.length;
while (++min < --max) {
- final Point2D tmp = loop[min];
+ final Vector2D tmp = loop[min];
loop[min] = loop[max];
loop[max] = tmp;
}
diff --git a/src/main/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSet.java b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSet.java
index c8fdee73c..a84c5b068 100644
--- a/src/main/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSet.java
+++ b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSet.java
@@ -17,25 +17,27 @@
package org.apache.commons.math.geometry.euclidean.twod;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
+import org.apache.commons.math.exception.MathInternalError;
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
import org.apache.commons.math.geometry.partitioning.BSPTree;
-import org.apache.commons.math.geometry.partitioning.Hyperplane;
import org.apache.commons.math.geometry.partitioning.Region;
import org.apache.commons.math.geometry.partitioning.SubHyperplane;
+import org.apache.commons.math.geometry.partitioning.AbstractRegion;
import org.apache.commons.math.geometry.partitioning.utilities.AVLTree;
import org.apache.commons.math.util.FastMath;
/** This class represents a 2D region: a set of polygons.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
*/
-public class PolygonsSet extends Region {
+public class PolygonsSet extends AbstractRegion {
/** Vertices organized as boundary loops. */
- private Point2D[][] vertices;
+ private Vector2D[][] vertices;
/** Build a polygons set representing the whole real line.
*/
@@ -52,7 +54,7 @@ public class PolygonsSet extends Region {
* {@code Boolean.TRUE} and {@code Boolean.FALSE}
* @param tree inside/outside BSP tree representing the region
*/
- public PolygonsSet(final BSPTree tree) {
+ public PolygonsSet(final BSPTree tree) {
super(tree);
}
@@ -63,7 +65,7 @@ public class PolygonsSet extends Region {
* its plus side.
* The boundary elements can be in any order, and can form
* several non-connected sets (like for example polygons with holes
- * or a set of disjoints polyhedrons considered as a whole). In
+ * or a set of disjoint polyhedrons considered as a whole). In
* fact, the elements do not even need to be connected together
* (their topological connections are not used here). However, if the
* boundary does not really separate an inside open from an outside
@@ -76,7 +78,7 @@ public class PolygonsSet extends Region {
* @param boundary collection of boundary elements, as a
* collection of {@link SubHyperplane SubHyperplane} objects
*/
- public PolygonsSet(final Collection boundary) {
+ public PolygonsSet(final Collection> boundary) {
super(boundary);
}
@@ -88,7 +90,7 @@ public class PolygonsSet extends Region {
*/
public PolygonsSet(final double xMin, final double xMax,
final double yMin, final double yMax) {
- this(buildConvex(boxBoundary(xMin, xMax, yMin, yMax)).getTree(false));
+ super(boxBoundary(xMin, xMax, yMin, yMax));
}
/** Create a list of hyperplanes representing the boundary of a box.
@@ -98,42 +100,42 @@ public class PolygonsSet extends Region {
* @param yMax high bound along the y direction
* @return boundary of the box
*/
- private static List boxBoundary(final double xMin, final double xMax,
- final double yMin, final double yMax) {
- final Point2D minMin = new Point2D(xMin, yMin);
- final Point2D minMax = new Point2D(xMin, yMax);
- final Point2D maxMin = new Point2D(xMax, yMin);
- final Point2D maxMax = new Point2D(xMax, yMax);
- return Arrays.asList(new Hyperplane[] {
+ private static Line[] boxBoundary(final double xMin, final double xMax,
+ final double yMin, final double yMax) {
+ 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);
+ return new Line[] {
new Line(minMin, maxMin),
new Line(maxMin, maxMax),
new Line(maxMax, minMax),
new Line(minMax, minMin)
- });
+ };
}
/** {@inheritDoc} */
- public Region buildNew(final BSPTree tree) {
+ public PolygonsSet buildNew(final BSPTree tree) {
return new PolygonsSet(tree);
}
/** {@inheritDoc} */
protected void computeGeometricalProperties() {
- final Point2D[][] v = getVertices();
+ final Vector2D[][] v = getVertices();
if (v.length == 0) {
if ((Boolean) getTree(false).getAttribute()) {
setSize(Double.POSITIVE_INFINITY);
- setBarycenter(Point2D.UNDEFINED);
+ setBarycenter(Vector2D.NaN);
} else {
setSize(0);
- setBarycenter(new Point2D(0, 0));
+ setBarycenter(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(Point2D.UNDEFINED);
+ setBarycenter(Vector2D.NaN);
} else {
// all loops are closed, we compute some integrals around the shape
@@ -141,14 +143,14 @@ public class PolygonsSet extends Region {
double sumX = 0;
double sumY = 0;
- for (Point2D[] loop : v) {
- double x1 = loop[loop.length - 1].x;
- double y1 = loop[loop.length - 1].y;
- for (final Point2D point : loop) {
+ for (Vector2D[] loop : v) {
+ double x1 = loop[loop.length - 1].getX();
+ double y1 = loop[loop.length - 1].getY();
+ for (final Vector2D point : loop) {
final double x0 = x1;
final double y0 = y1;
- x1 = point.x;
- y1 = point.y;
+ x1 = point.getX();
+ y1 = point.getY();
final double factor = x0 * y1 - y0 * x1;
sum += factor;
sumX += factor * (x0 + x1);
@@ -159,10 +161,10 @@ public class PolygonsSet extends Region {
if (sum < 0) {
// the polygon as a finite outside surrounded by an infinite inside
setSize(Double.POSITIVE_INFINITY);
- setBarycenter(Point2D.UNDEFINED);
+ setBarycenter(Vector2D.NaN);
} else {
setSize(sum / 2);
- setBarycenter(new Point2D(sumX / (3 * sum), sumY / (3 * sum)));
+ setBarycenter(new Vector2D(sumX / (3 * sum), sumY / (3 * sum)));
}
}
@@ -192,19 +194,19 @@ public class PolygonsSet extends Region {
* loops with the open loops first (the returned value is guaranteed
* to be non-null)
*/
- public Point2D[][] getVertices() {
+ public Vector2D[][] getVertices() {
if (vertices == null) {
if (getTree(false).getCut() == null) {
- vertices = new Point2D[0][];
+ vertices = new Vector2D[0][];
} else {
- // sort the segmfinal ents according to their start point
+ // sort the segments according to their start point
final SegmentsBuilder visitor = new SegmentsBuilder();
getTree(true).visit(visitor);
final AVLTree sorted = visitor.getSorted();
// identify the loops, starting from the open ones
- // (their start segments final are naturally at the sorted set beginning)
+ // (their start segments are naturally at the sorted set beginning)
final ArrayList> loops = new ArrayList>();
while (!sorted.isEmpty()) {
final AVLTree.Node node = sorted.getSmallest();
@@ -215,31 +217,30 @@ public class PolygonsSet extends Region {
}
// tranform the loops in an array of arrays of points
- vertices = new Point2D[loops.size()][];
+ vertices = new Vector2D[loops.size()][];
int i = 0;
for (final List loop : loops) {
if (loop.size() < 2) {
- // sifinal ngle infinite line
- final Line line = ((Segment) loop.get(0)).getLine();
- vertices[i++] = new Point2D[] {
+ // single infinite line
+ final Line line = loop.get(0).getLine();
+ vertices[i++] = new Vector2D[] {
null,
- (Point2D) line.toSpace(new Point1D(-Float.MAX_VALUE)),
- (Point2D) line.toSpace(new Point1D(+Float.MAX_VALUE))
+ line.toSpace(new Vector1D(-Float.MAX_VALUE)),
+ line.toSpace(new Vector1D(+Float.MAX_VALUE))
};
- } else if (((Segment) loop.get(0)).getStart() == null) {
- // open lofinal op with at least one real point
- final Point2D[] array = new Point2D[loop.size() + 2];
+ } else if (loop.get(0).getStart() == null) {
+ // open loop with at least one real point
+ final Vector2D[] array = new Vector2D[loop.size() + 2];
int j = 0;
for (Segment segment : loop) {
if (j == 0) {
// null point and first dummy point
- double x =
- ((Point1D) segment.getLine().toSubSpace(segment.getEnd())).getAbscissa();
+ double x = segment.getLine().toSubSpace(segment.getEnd()).getX();
x -= FastMath.max(1.0, FastMath.abs(x / 2));
array[j++] = null;
- array[j++] = (Point2D) segment.getLine().toSpace(new Point1D(x));
+ array[j++] = segment.getLine().toSpace(new Vector1D(x));
}
if (j < (array.length - 1)) {
@@ -249,16 +250,15 @@ public class PolygonsSet extends Region {
if (j == (array.length - 1)) {
// last dummy point
- double x =
- ((Point1D) segment.getLine().toSubSpace(segment.getStart())).getAbscissa();
+ double x = segment.getLine().toSubSpace(segment.getStart()).getX();
x += FastMath.max(1.0, FastMath.abs(x / 2));
- array[j++] = (Point2D) segment.getLine().toSpace(new Point1D(x));
+ array[j++] = segment.getLine().toSpace(new Vector1D(x));
}
}
vertices[i++] = array;
} else {
- final Point2D[] array = new Point2D[loop.size()];
+ final Vector2D[] array = new Vector2D[loop.size()];
int j = 0;
for (Segment segment : loop) {
array[j++] = segment.getStart();
@@ -285,10 +285,10 @@ public class PolygonsSet extends Region {
final AVLTree sorted) {
final ArrayList loop = new ArrayList();
- Segment segment = (Segment) node.getElement();
+ Segment segment = node.getElement();
loop.add(segment);
- final Point2D globalStart = segment.getStart();
- Point2D end = segment.getEnd();
+ final Vector2D globalStart = segment.getStart();
+ Vector2D end = segment.getEnd();
node.delete();
// is this an open or a closed loop ?
@@ -333,7 +333,7 @@ public class PolygonsSet extends Region {
}
if ((end == null) && !open) {
- throw new RuntimeException("internal error");
+ throw new MathInternalError();
}
return loop;
diff --git a/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Segment.java b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Segment.java
index a631a2be2..eceb980cd 100644
--- a/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Segment.java
+++ b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Segment.java
@@ -19,15 +19,16 @@ package org.apache.commons.math.geometry.euclidean.twod;
import org.apache.commons.math.geometry.partitioning.utilities.OrderedTuple;
/** This class holds segments information before they are connected.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
*/
class Segment implements Comparable {
/** Start point of the segment. */
- private final Point2D start;
+ private final Vector2D start;
/** End point of the segments. */
- private final Point2D end;
+ private final Vector2D end;
/** Line containing the segment. */
private final Line line;
@@ -40,13 +41,13 @@ class Segment implements Comparable {
* @param end end point of the segment
* @param line line containing the segment
*/
- public Segment(final Point2D start, final Point2D end, final Line line) {
+ public Segment(final Vector2D start, final Vector2D end, final Line line) {
this.start = start;
this.end = end;
this.line = line;
sortingKey = (start == null) ?
new OrderedTuple(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY) :
- new OrderedTuple(start.x, start.y);
+ new OrderedTuple(start.getX(), start.getY());
}
/** Build a dummy segment.
@@ -58,24 +59,24 @@ class Segment implements Comparable {
* @param dx abscissa offset from the start point
* @param dy ordinate offset from the start point
*/
- public Segment(final Point2D start, final double dx, final double dy) {
+ public Segment(final Vector2D start, final double dx, final double dy) {
this.start = null;
this.end = null;
this.line = null;
- sortingKey = new OrderedTuple(start.x + dx, start.y + dy);
+ sortingKey = new OrderedTuple(start.getX() + dx, start.getY() + dy);
}
/** Get the start point of the segment.
* @return start point of the segment
*/
- public Point2D getStart() {
+ public Vector2D getStart() {
return start;
}
/** Get the end point of the segment.
* @return end point of the segment
*/
- public Point2D getEnd() {
+ public Vector2D getEnd() {
return end;
}
diff --git a/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SegmentBuilder.java b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SegmentBuilder.java
index 622b3f881..6f68f4478 100644
--- a/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SegmentBuilder.java
+++ b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SegmentBuilder.java
@@ -18,19 +18,22 @@ package org.apache.commons.math.geometry.euclidean.twod;
import java.util.List;
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
import org.apache.commons.math.geometry.euclidean.oned.Interval;
import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
+import org.apache.commons.math.geometry.partitioning.AbstractSubHyperplane;
import org.apache.commons.math.geometry.partitioning.BSPTree;
import org.apache.commons.math.geometry.partitioning.BSPTreeVisitor;
-import org.apache.commons.math.geometry.partitioning.Region.BoundaryAttribute;
+import org.apache.commons.math.geometry.partitioning.BoundaryAttribute;
import org.apache.commons.math.geometry.partitioning.SubHyperplane;
import org.apache.commons.math.geometry.partitioning.utilities.AVLTree;
/** Visitor building segments.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
*/
-class SegmentsBuilder implements BSPTreeVisitor {
+class SegmentsBuilder implements BSPTreeVisitor {
/** Sorted segments. */
private AVLTree sorted;
@@ -41,13 +44,14 @@ class SegmentsBuilder implements BSPTreeVisitor {
}
/** {@inheritDoc} */
- public Order visitOrder(final BSPTree node) {
+ public Order visitOrder(final BSPTree node) {
return Order.MINUS_SUB_PLUS;
}
/** {@inheritDoc} */
- public void visitInternalNode(final BSPTree node) {
- final BoundaryAttribute attribute = (BoundaryAttribute) node.getAttribute();
+ public void visitInternalNode(final BSPTree node) {
+ @SuppressWarnings("unchecked")
+ final BoundaryAttribute attribute = (BoundaryAttribute) node.getAttribute();
if (attribute.getPlusOutside() != null) {
addContribution(attribute.getPlusOutside(), false);
}
@@ -57,21 +61,24 @@ class SegmentsBuilder implements BSPTreeVisitor {
}
/** {@inheritDoc} */
- public void visitLeafNode(final BSPTree node) {
+ public void visitLeafNode(final BSPTree node) {
}
/** Add he contribution of a boundary facet.
* @param sub boundary facet
* @param reversed if true, the facet has the inside on its plus side
*/
- private void addContribution(final SubHyperplane sub, final boolean reversed) {
+ private void addContribution(final SubHyperplane sub, final boolean reversed) {
+ @SuppressWarnings("unchecked")
+ final AbstractSubHyperplane absSub =
+ (AbstractSubHyperplane) sub;
final Line line = (Line) sub.getHyperplane();
- final List intervals = ((IntervalsSet) sub.getRemainingRegion()).asList();
+ final List intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
for (final Interval i : intervals) {
- final Point2D start = Double.isInfinite(i.getLower()) ?
- null : (Point2D) line.toSpace(new Point1D(i.getLower()));
- final Point2D end = Double.isInfinite(i.getUpper()) ?
- null : (Point2D) line.toSpace(new Point1D(i.getUpper()));
+ final Vector2D start = Double.isInfinite(i.getLower()) ?
+ null : (Vector2D) line.toSpace(new Vector1D(i.getLower()));
+ final Vector2D end = Double.isInfinite(i.getUpper()) ?
+ null : (Vector2D) line.toSpace(new Vector1D(i.getUpper()));
if (reversed) {
sorted.insert(new Segment(end, start, line.getReverse()));
} else {
diff --git a/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SubLine.java b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SubLine.java
new file mode 100644
index 000000000..c0965aac9
--- /dev/null
+++ b/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SubLine.java
@@ -0,0 +1,108 @@
+/*
+ * 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.math.geometry.euclidean.twod;
+
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
+import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
+import org.apache.commons.math.geometry.euclidean.oned.OrientedPoint;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
+import org.apache.commons.math.geometry.partitioning.AbstractSubHyperplane;
+import org.apache.commons.math.geometry.partitioning.BSPTree;
+import org.apache.commons.math.geometry.partitioning.Hyperplane;
+import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.Side;
+import org.apache.commons.math.geometry.partitioning.SubHyperplane;
+import org.apache.commons.math.util.FastMath;
+
+/** This class represents a sub-hyperplane for {@link Line}.
+ * @version $Id:$
+ * @since 3.0
+ */
+public class SubLine extends AbstractSubHyperplane {
+
+ /** Simple constructor.
+ * @param hyperplane underlying hyperplane
+ * @param remainingRegion remaining region of the hyperplane
+ */
+ public SubLine(final Hyperplane hyperplane,
+ final Region remainingRegion) {
+ super(hyperplane, remainingRegion);
+ }
+
+ /** {@inheritDoc} */
+ protected AbstractSubHyperplane buildNew(final Hyperplane hyperplane,
+ final Region remainingRegion) {
+ return new SubLine(hyperplane, remainingRegion);
+ }
+
+ /** {@inheritDoc} */
+ public Side side(final Hyperplane hyperplane) {
+
+ final Line thisLine = (Line) getHyperplane();
+ final Line otherLine = (Line) hyperplane;
+ final Vector2D crossing = thisLine.intersection(otherLine);
+
+ if (crossing == null) {
+ // the lines are parallel,
+ final double global = otherLine.getOffset(thisLine);
+ return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
+ }
+
+ // the lines do intersect
+ final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0;
+ final Vector1D x = (Vector1D) thisLine.toSubSpace(crossing);
+ return getRemainingRegion().side(new OrientedPoint(x, direct));
+
+ }
+
+ /** {@inheritDoc} */
+ public SplitSubHyperplane split(final Hyperplane hyperplane) {
+
+ final Line thisLine = (Line) getHyperplane();
+ final Line otherLine = (Line) hyperplane;
+ final Vector2D crossing = thisLine.intersection(otherLine);
+
+ if (crossing == null) {
+ // the lines are parallel
+ final double global = otherLine.getOffset(thisLine);
+ return (global < -1.0e-10) ?
+ new SplitSubHyperplane(null, this) :
+ new SplitSubHyperplane(this, null);
+ }
+
+ // the lines do intersect
+ final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0;
+ final Vector1D x = (Vector1D) thisLine.toSubSpace(crossing);
+ final SubHyperplane subPlus = new OrientedPoint(x, !direct).wholeHyperplane();
+ final SubHyperplane subMinus = new OrientedPoint(x, direct).wholeHyperplane();
+
+ final BSPTree splitTree = getRemainingRegion().getTree(false).split(subMinus);
+ final BSPTree plusTree = getRemainingRegion().isEmpty(splitTree.getPlus()) ?
+ new BSPTree(Boolean.FALSE) :
+ new BSPTree(subPlus, new BSPTree(Boolean.FALSE),
+ splitTree.getPlus(), null);
+ final BSPTree minusTree = getRemainingRegion().isEmpty(splitTree.getMinus()) ?
+ new BSPTree(Boolean.FALSE) :
+ new BSPTree(subMinus, new BSPTree(Boolean.FALSE),
+ splitTree.getMinus(), null);
+
+ return new SplitSubHyperplane(new SubLine(thisLine.copySelf(), new IntervalsSet(plusTree)),
+ new SubLine(thisLine.copySelf(), new IntervalsSet(minusTree)));
+
+ }
+
+}
diff --git a/src/test/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSetTest.java b/src/test/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSetTest.java
index 1d8c63032..b7c4640a4 100644
--- a/src/test/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSetTest.java
+++ b/src/test/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSetTest.java
@@ -20,8 +20,9 @@ import java.util.List;
import org.apache.commons.math.geometry.euclidean.oned.Interval;
import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.RegionFactory;
import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
@@ -32,12 +33,12 @@ public class IntervalsSetTest {
public void testInterval() {
IntervalsSet set = new IntervalsSet(2.3, 5.7);
Assert.assertEquals(3.4, set.getSize(), 1.0e-10);
- Assert.assertEquals(4.0, ((Point1D) set.getBarycenter()).getAbscissa(), 1.0e-10);
- Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(2.3)));
- Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(5.7)));
- Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Point1D(1.2)));
- Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Point1D(8.7)));
- Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Point1D(3.0)));
+ Assert.assertEquals(4.0, ((Vector1D) set.getBarycenter()).getX(), 1.0e-10);
+ Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(2.3)));
+ Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(5.7)));
+ Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector1D(1.2)));
+ Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector1D(8.7)));
+ Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Vector1D(3.0)));
Assert.assertEquals(2.3, set.getInf(), 1.0e-10);
Assert.assertEquals(5.7, set.getSup(), 1.0e-10);
}
@@ -45,17 +46,17 @@ public class IntervalsSetTest {
@Test
public void testInfinite() {
IntervalsSet set = new IntervalsSet(9.0, Double.POSITIVE_INFINITY);
- Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(9.0)));
- Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Point1D(8.4)));
+ Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(9.0)));
+ Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector1D(8.4)));
for (double e = 1.0; e <= 6.0; e += 1.0) {
Assert.assertEquals(Region.Location.INSIDE,
- set.checkPoint(new Point1D(FastMath.pow(10.0, e))));
+ set.checkPoint(new Vector1D(FastMath.pow(10.0, e))));
}
Assert.assertTrue(Double.isInfinite(set.getSize()));
Assert.assertEquals(9.0, set.getInf(), 1.0e-10);
Assert.assertTrue(Double.isInfinite(set.getSup()));
- set = (IntervalsSet) set.getComplement();
+ set = (IntervalsSet) new RegionFactory().getComplement(set);
Assert.assertEquals(9.0, set.getSup(), 1.0e-10);
Assert.assertTrue(Double.isInfinite(set.getInf()));
@@ -63,22 +64,23 @@ public class IntervalsSetTest {
@Test
public void testMultiple() {
+ RegionFactory factory = new RegionFactory();
IntervalsSet set = (IntervalsSet)
- Region.intersection(Region.union(Region.difference(new IntervalsSet(1.0, 6.0),
- new IntervalsSet(3.0, 5.0)),
- new IntervalsSet(9.0, Double.POSITIVE_INFINITY)),
- new IntervalsSet(Double.NEGATIVE_INFINITY, 11.0));
+ factory.intersection(factory.union(factory.difference(new IntervalsSet(1.0, 6.0),
+ new IntervalsSet(3.0, 5.0)),
+ new IntervalsSet(9.0, Double.POSITIVE_INFINITY)),
+ new IntervalsSet(Double.NEGATIVE_INFINITY, 11.0));
Assert.assertEquals(5.0, set.getSize(), 1.0e-10);
- Assert.assertEquals(5.9, ((Point1D) set.getBarycenter()).getAbscissa(), 1.0e-10);
- Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Point1D(0.0)));
- Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Point1D(4.0)));
- Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Point1D(8.0)));
- Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Point1D(12.0)));
- Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Point1D(1.2)));
- Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Point1D(5.9)));
- Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Point1D(9.01)));
- Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(5.0)));
- Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(11.0)));
+ Assert.assertEquals(5.9, ((Vector1D) set.getBarycenter()).getX(), 1.0e-10);
+ Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector1D(0.0)));
+ Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector1D(4.0)));
+ Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector1D(8.0)));
+ Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector1D(12.0)));
+ Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Vector1D(1.2)));
+ Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Vector1D(5.9)));
+ Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Vector1D(9.01)));
+ Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(5.0)));
+ Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(11.0)));
Assert.assertEquals( 1.0, set.getInf(), 1.0e-10);
Assert.assertEquals(11.0, set.getSup(), 1.0e-10);
diff --git a/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PlaneTest.java b/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PlaneTest.java
index 3b4d35d06..e1ff38710 100644
--- a/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PlaneTest.java
+++ b/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PlaneTest.java
@@ -18,7 +18,6 @@ package org.apache.commons.math.geometry.euclidean.threed;
import org.apache.commons.math.geometry.euclidean.threed.Line;
import org.apache.commons.math.geometry.euclidean.threed.Plane;
-import org.apache.commons.math.geometry.euclidean.threed.Point3D;
import org.apache.commons.math.geometry.euclidean.threed.Rotation;
import org.apache.commons.math.geometry.euclidean.threed.Vector3D;
import org.junit.Assert;
@@ -29,22 +28,22 @@ public class PlaneTest {
@Test
public void testContains() {
Plane p = new Plane(new Vector3D(0, 0, 1), new Vector3D(0, 0, 1));
- Assert.assertTrue(p.contains(new Point3D(0, 0, 1)));
- Assert.assertTrue(p.contains(new Point3D(17, -32, 1)));
- Assert.assertTrue(! p.contains(new Point3D(17, -32, 1.001)));
+ Assert.assertTrue(p.contains(new Vector3D(0, 0, 1)));
+ Assert.assertTrue(p.contains(new Vector3D(17, -32, 1)));
+ Assert.assertTrue(! p.contains(new Vector3D(17, -32, 1.001)));
}
@Test
public void testOffset() {
Vector3D p1 = new Vector3D(1, 1, 1);
Plane p = new Plane(p1, new Vector3D(0.2, 0, 0));
- Assert.assertEquals(-5.0, p.getOffset(new Point3D(-4, 0, 0)), 1.0e-10);
- Assert.assertEquals(+5.0, p.getOffset(new Point3D(6, 10, -12)), 1.0e-10);
+ Assert.assertEquals(-5.0, p.getOffset(new Vector3D(-4, 0, 0)), 1.0e-10);
+ Assert.assertEquals(+5.0, p.getOffset(new Vector3D(6, 10, -12)), 1.0e-10);
Assert.assertEquals(0.3,
- p.getOffset(new Point3D(1.0, p1, 0.3, p.getNormal())),
+ p.getOffset(new Vector3D(1.0, p1, 0.3, p.getNormal())),
1.0e-10);
Assert.assertEquals(-0.3,
- p.getOffset(new Point3D(1.0, p1, -0.3, p.getNormal())),
+ p.getOffset(new Vector3D(1.0, p1, -0.3, p.getNormal())),
1.0e-10);
}
@@ -56,9 +55,9 @@ public class PlaneTest {
@Test
public void testThreePoints() {
- Point3D p1 = new Point3D(1.2, 3.4, -5.8);
- Point3D p2 = new Point3D(3.4, -5.8, 1.2);
- Point3D p3 = new Point3D(-2.0, 4.3, 0.7);
+ Vector3D p1 = new Vector3D(1.2, 3.4, -5.8);
+ Vector3D p2 = new Vector3D(3.4, -5.8, 1.2);
+ Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7);
Plane p = new Plane(p1, p2, p3);
Assert.assertTrue(p.contains(p1));
Assert.assertTrue(p.contains(p2));
@@ -67,9 +66,9 @@ public class PlaneTest {
@Test
public void testRotate() {
- Point3D p1 = new Point3D(1.2, 3.4, -5.8);
- Point3D p2 = new Point3D(3.4, -5.8, 1.2);
- Point3D p3 = new Point3D(-2.0, 4.3, 0.7);
+ Vector3D p1 = new Vector3D(1.2, 3.4, -5.8);
+ Vector3D p2 = new Vector3D(3.4, -5.8, 1.2);
+ Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7);
Plane p = new Plane(p1, p2, p3);
Vector3D oldNormal = p.getNormal();
@@ -92,9 +91,9 @@ public class PlaneTest {
@Test
public void testTranslate() {
- Point3D p1 = new Point3D(1.2, 3.4, -5.8);
- Point3D p2 = new Point3D(3.4, -5.8, 1.2);
- Point3D p3 = new Point3D(-2.0, 4.3, 0.7);
+ Vector3D p1 = new Vector3D(1.2, 3.4, -5.8);
+ Vector3D p2 = new Vector3D(3.4, -5.8, 1.2);
+ Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7);
Plane p = new Plane(p1, p2, p3);
p = p.translate(new Vector3D(2.0, p.getU(), -1.5, p.getV()));
@@ -118,7 +117,7 @@ public class PlaneTest {
public void testIntersection() {
Plane p = new Plane(new Vector3D(1, 2, 3), new Vector3D(-4, 1, -5));
Line l = new Line(new Vector3D(0.2, -3.5, 0.7), new Vector3D(1, 1, -1));
- Point3D point = p.intersection(l);
+ Vector3D point = p.intersection(l);
Assert.assertTrue(p.contains(point));
Assert.assertTrue(l.contains(point));
Assert.assertNull(p.intersection(new Line(new Vector3D(10, 10, 10),
diff --git a/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSetTest.java b/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSetTest.java
index 1197b7d90..fec1b602b 100644
--- a/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSetTest.java
+++ b/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSetTest.java
@@ -16,20 +16,13 @@
*/
package org.apache.commons.math.geometry.euclidean.threed;
-import java.util.Arrays;
-
-import org.apache.commons.math.geometry.euclidean.threed.Plane;
-import org.apache.commons.math.geometry.euclidean.threed.Point3D;
-import org.apache.commons.math.geometry.euclidean.threed.PolyhedronsSet;
-import org.apache.commons.math.geometry.euclidean.threed.Rotation;
-import org.apache.commons.math.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.math.geometry.euclidean.twod.Point2D;
import org.apache.commons.math.geometry.euclidean.twod.PolygonsSet;
+import org.apache.commons.math.geometry.euclidean.twod.Vector2D;
import org.apache.commons.math.geometry.partitioning.BSPTree;
import org.apache.commons.math.geometry.partitioning.BSPTreeVisitor;
-import org.apache.commons.math.geometry.partitioning.Hyperplane;
+import org.apache.commons.math.geometry.partitioning.BoundaryAttribute;
import org.apache.commons.math.geometry.partitioning.Region;
-import org.apache.commons.math.geometry.partitioning.SubHyperplane;
+import org.apache.commons.math.geometry.partitioning.RegionFactory;
import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
@@ -53,41 +46,41 @@ public class PolyhedronsSetTest {
boolean zOK = (z >= 0.0) && (z <= 1.0);
Region.Location expected =
(xOK && yOK && zOK) ? Region.Location.INSIDE : Region.Location.OUTSIDE;
- Assert.assertEquals(expected, tree.checkPoint(new Point3D(x, y, z)));
+ Assert.assertEquals(expected, tree.checkPoint(new Vector3D(x, y, z)));
}
}
}
- checkPoints(Region.Location.BOUNDARY, tree, new Point3D[] {
- new Point3D(0.0, 0.5, 0.5),
- new Point3D(1.0, 0.5, 0.5),
- new Point3D(0.5, 0.0, 0.5),
- new Point3D(0.5, 1.0, 0.5),
- new Point3D(0.5, 0.5, 0.0),
- new Point3D(0.5, 0.5, 1.0)
+ checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] {
+ new Vector3D(0.0, 0.5, 0.5),
+ new Vector3D(1.0, 0.5, 0.5),
+ new Vector3D(0.5, 0.0, 0.5),
+ new Vector3D(0.5, 1.0, 0.5),
+ new Vector3D(0.5, 0.5, 0.0),
+ new Vector3D(0.5, 0.5, 1.0)
});
- checkPoints(Region.Location.OUTSIDE, tree, new Point3D[] {
- new Point3D(0.0, 1.2, 1.2),
- new Point3D(1.0, 1.2, 1.2),
- new Point3D(1.2, 0.0, 1.2),
- new Point3D(1.2, 1.0, 1.2),
- new Point3D(1.2, 1.2, 0.0),
- new Point3D(1.2, 1.2, 1.0)
+ checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] {
+ new Vector3D(0.0, 1.2, 1.2),
+ new Vector3D(1.0, 1.2, 1.2),
+ new Vector3D(1.2, 0.0, 1.2),
+ new Vector3D(1.2, 1.0, 1.2),
+ new Vector3D(1.2, 1.2, 0.0),
+ new Vector3D(1.2, 1.2, 1.0)
});
}
@Test
public void testTetrahedron() {
- Point3D vertex1 = new Point3D(1, 2, 3);
- Point3D vertex2 = new Point3D(2, 2, 4);
- Point3D vertex3 = new Point3D(2, 3, 3);
- Point3D vertex4 = new Point3D(1, 3, 4);
+ Vector3D vertex1 = new Vector3D(1, 2, 3);
+ Vector3D vertex2 = new Vector3D(2, 2, 4);
+ Vector3D vertex3 = new Vector3D(2, 3, 3);
+ Vector3D vertex4 = new Vector3D(1, 3, 4);
+ @SuppressWarnings("unchecked")
PolyhedronsSet tree =
- (PolyhedronsSet) Region.buildConvex(Arrays.asList(new Hyperplane[] {
+ (PolyhedronsSet) new RegionFactory().buildConvex(
new Plane(vertex3, vertex2, vertex1),
new Plane(vertex2, vertex3, vertex4),
new Plane(vertex4, vertex3, vertex1),
- new Plane(vertex1, vertex2, vertex4)
- }));
+ new Plane(vertex1, vertex2, vertex4));
Assert.assertEquals(1.0 / 3.0, tree.getSize(), 1.0e-10);
Assert.assertEquals(2.0 * FastMath.sqrt(3.0), tree.getBoundarySize(), 1.0e-10);
Vector3D barycenter = (Vector3D) tree.getBarycenter();
@@ -95,18 +88,18 @@ public class PolyhedronsSetTest {
Assert.assertEquals(2.5, barycenter.getY(), 1.0e-10);
Assert.assertEquals(3.5, barycenter.getZ(), 1.0e-10);
double third = 1.0 / 3.0;
- checkPoints(Region.Location.BOUNDARY, tree, new Point3D[] {
+ checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] {
vertex1, vertex2, vertex3, vertex4,
- new Point3D(third, vertex1, third, vertex2, third, vertex3),
- new Point3D(third, vertex2, third, vertex3, third, vertex4),
- new Point3D(third, vertex3, third, vertex4, third, vertex1),
- new Point3D(third, vertex4, third, vertex1, third, vertex2)
+ new Vector3D(third, vertex1, third, vertex2, third, vertex3),
+ new Vector3D(third, vertex2, third, vertex3, third, vertex4),
+ new Vector3D(third, vertex3, third, vertex4, third, vertex1),
+ new Vector3D(third, vertex4, third, vertex1, third, vertex2)
});
- checkPoints(Region.Location.OUTSIDE, tree, new Point3D[] {
- new Point3D(1, 2, 4),
- new Point3D(2, 2, 3),
- new Point3D(2, 3, 4),
- new Point3D(1, 3, 3)
+ checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] {
+ new Vector3D(1, 2, 4),
+ new Vector3D(2, 2, 3),
+ new Vector3D(2, 3, 4),
+ new Vector3D(1, 3, 3)
});
}
@@ -116,13 +109,13 @@ public class PolyhedronsSetTest {
Vector3D vertex2 = new Vector3D(2.0, 2.4, 4.2);
Vector3D vertex3 = new Vector3D(2.8, 3.3, 3.7);
Vector3D vertex4 = new Vector3D(1.0, 3.6, 4.5);
+ @SuppressWarnings("unchecked")
PolyhedronsSet tree =
- (PolyhedronsSet) Region.buildConvex(Arrays.asList(new Hyperplane[] {
+ (PolyhedronsSet) new RegionFactory().buildConvex(
new Plane(vertex3, vertex2, vertex1),
new Plane(vertex2, vertex3, vertex4),
new Plane(vertex4, vertex3, vertex1),
- new Plane(vertex1, vertex2, vertex4)
- }));
+ new Plane(vertex1, vertex2, vertex4));
Vector3D barycenter = (Vector3D) tree.getBarycenter();
Vector3D s = new Vector3D(10.2, 4.3, -6.7);
Vector3D c = new Vector3D(-0.2, 2.1, -3.2);
@@ -152,29 +145,30 @@ public class PolyhedronsSetTest {
1.0, c,
1.0, r.applyTo(vertex4.subtract(c)))
};
- tree.getTree(true).visit(new BSPTreeVisitor() {
+ tree.getTree(true).visit(new BSPTreeVisitor() {
- public Order visitOrder(BSPTree node) {
+ public Order visitOrder(BSPTree node) {
return Order.MINUS_SUB_PLUS;
}
- public void visitInternalNode(BSPTree node) {
- Region.BoundaryAttribute attribute =
- (Region.BoundaryAttribute) node.getAttribute();
+ public void visitInternalNode(BSPTree node) {
+ @SuppressWarnings("unchecked")
+ BoundaryAttribute attribute =
+ (BoundaryAttribute) node.getAttribute();
if (attribute.getPlusOutside() != null) {
- checkFacet(attribute.getPlusOutside());
+ checkFacet((SubPlane) attribute.getPlusOutside());
}
if (attribute.getPlusInside() != null) {
- checkFacet(attribute.getPlusInside());
+ checkFacet((SubPlane) attribute.getPlusInside());
}
}
- public void visitLeafNode(BSPTree node) {
+ public void visitLeafNode(BSPTree node) {
}
- private void checkFacet(SubHyperplane facet) {
+ private void checkFacet(SubPlane facet) {
Plane plane = (Plane) facet.getHyperplane();
- Point2D[][] vertices =
+ Vector2D[][] vertices =
((PolygonsSet) facet.getRemainingRegion()).getVertices();
Assert.assertEquals(1, vertices.length);
for (int i = 0; i < vertices[0].length; ++i) {
@@ -222,8 +216,8 @@ public class PolyhedronsSetTest {
new PolyhedronsSet(x - w, x + w, y - l, y + l, z - w, z + w);
PolyhedronsSet zBeam =
new PolyhedronsSet(x - w, x + w, y - w, y + w, z - l, z + l);
- PolyhedronsSet tree =
- (PolyhedronsSet) Region.union(xBeam, Region.union(yBeam, zBeam));
+ RegionFactory factory = new RegionFactory();
+ PolyhedronsSet tree = (PolyhedronsSet) factory.union(xBeam, factory.union(yBeam, zBeam));
Vector3D barycenter = (Vector3D) tree.getBarycenter();
Assert.assertEquals(x, barycenter.getX(), 1.0e-10);
@@ -234,7 +228,7 @@ public class PolyhedronsSetTest {
}
- private void checkPoints(Region.Location expected, PolyhedronsSet tree, Point3D[] points) {
+ private void checkPoints(Region.Location expected, PolyhedronsSet tree, Vector3D[] points) {
for (int i = 0; i < points.length; ++i) {
Assert.assertEquals(expected, tree.checkPoint(points[i]));
}
diff --git a/src/test/java/org/apache/commons/math/geometry/euclidean/twod/LineTest.java b/src/test/java/org/apache/commons/math/geometry/euclidean/twod/LineTest.java
index 62cfe97b9..894a2ac4b 100644
--- a/src/test/java/org/apache/commons/math/geometry/euclidean/twod/LineTest.java
+++ b/src/test/java/org/apache/commons/math/geometry/euclidean/twod/LineTest.java
@@ -16,9 +16,10 @@
*/
package org.apache.commons.math.geometry.euclidean.twod;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
import org.apache.commons.math.geometry.euclidean.twod.Line;
-import org.apache.commons.math.geometry.euclidean.twod.Point2D;
+import org.apache.commons.math.geometry.euclidean.twod.Vector2D;
import org.apache.commons.math.geometry.partitioning.Transform;
import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
@@ -30,48 +31,48 @@ public class LineTest {
@Test
public void testContains() {
- Line l = new Line(new Point2D(0, 1), new Point2D(1, 2));
- Assert.assertTrue(l.contains(new Point2D(0, 1)));
- Assert.assertTrue(l.contains(new Point2D(1, 2)));
- Assert.assertTrue(l.contains(new Point2D(7, 8)));
- Assert.assertTrue(! l.contains(new Point2D(8, 7)));
+ Line l = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
+ Assert.assertTrue(l.contains(new Vector2D(0, 1)));
+ Assert.assertTrue(l.contains(new Vector2D(1, 2)));
+ Assert.assertTrue(l.contains(new Vector2D(7, 8)));
+ Assert.assertTrue(! l.contains(new Vector2D(8, 7)));
}
@Test
public void testAbscissa() {
- Line l = new Line(new Point2D(2, 1), new Point2D(-2, -2));
+ Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
Assert.assertEquals(0.0,
- ((Point1D) l.toSubSpace(new Point2D(-3, 4))).getAbscissa(),
+ ((Vector1D) l.toSubSpace(new Vector2D(-3, 4))).getX(),
1.0e-10);
Assert.assertEquals(0.0,
- ((Point1D) l.toSubSpace(new Point2D( 3, -4))).getAbscissa(),
+ ((Vector1D) l.toSubSpace(new Vector2D( 3, -4))).getX(),
1.0e-10);
Assert.assertEquals(-5.0,
- ((Point1D) l.toSubSpace(new Point2D( 7, -1))).getAbscissa(),
+ ((Vector1D) l.toSubSpace(new Vector2D( 7, -1))).getX(),
1.0e-10);
Assert.assertEquals( 5.0,
- ((Point1D) l.toSubSpace(new Point2D(-1, -7))).getAbscissa(),
+ ((Vector1D) l.toSubSpace(new Vector2D(-1, -7))).getX(),
1.0e-10);
}
@Test
public void testOffset() {
- Line l = new Line(new Point2D(2, 1), new Point2D(-2, -2));
- Assert.assertEquals(-5.0, l.getOffset(new Point2D(5, -3)), 1.0e-10);
- Assert.assertEquals(+5.0, l.getOffset(new Point2D(-5, 2)), 1.0e-10);
+ Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
+ Assert.assertEquals(-5.0, l.getOffset(new Vector2D(5, -3)), 1.0e-10);
+ Assert.assertEquals(+5.0, l.getOffset(new Vector2D(-5, 2)), 1.0e-10);
}
@Test
public void testPointAt() {
- Line l = new Line(new Point2D(2, 1), new Point2D(-2, -2));
+ Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
for (double a = -2.0; a < 2.0; a += 0.2) {
- Point1D pA = new Point1D(a);
- Point2D point = (Point2D) l.toSpace(pA);
- Assert.assertEquals(a, ((Point1D) l.toSubSpace(point)).getAbscissa(), 1.0e-10);
+ Vector1D pA = new Vector1D(a);
+ Vector2D point = (Vector2D) l.toSpace(pA);
+ Assert.assertEquals(a, ((Vector1D) l.toSubSpace(point)).getX(), 1.0e-10);
Assert.assertEquals(0.0, l.getOffset(point), 1.0e-10);
for (double o = -2.0; o < 2.0; o += 0.2) {
point = l.getPointAt(pA, o);
- Assert.assertEquals(a, ((Point1D) l.toSubSpace(point)).getAbscissa(), 1.0e-10);
+ Assert.assertEquals(a, ((Vector1D) l.toSubSpace(point)).getX(), 1.0e-10);
Assert.assertEquals(o, l.getOffset(point), 1.0e-10);
}
}
@@ -79,38 +80,36 @@ public class LineTest {
@Test
public void testOriginOffset() {
- Line l1 = new Line(new Point2D(0, 1), new Point2D(1, 2));
+ Line l1 = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
Assert.assertEquals(FastMath.sqrt(0.5), l1.getOriginOffset(), 1.0e-10);
- Line l2 = new Line(new Point2D(1, 2), new Point2D(0, 1));
+ Line l2 = new Line(new Vector2D(1, 2), new Vector2D(0, 1));
Assert.assertEquals(-FastMath.sqrt(0.5), l2.getOriginOffset(), 1.0e-10);
}
@Test
public void testParallel() {
- Line l1 = new Line(new Point2D(0, 1), new Point2D(1, 2));
- Line l2 = new Line(new Point2D(2, 2), new Point2D(3, 3));
+ Line l1 = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
+ Line l2 = new Line(new Vector2D(2, 2), new Vector2D(3, 3));
Assert.assertTrue(l1.isParallelTo(l2));
- Line l3 = new Line(new Point2D(1, 0), new Point2D(0.5, -0.5));
+ Line l3 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.5));
Assert.assertTrue(l1.isParallelTo(l3));
- Line l4 = new Line(new Point2D(1, 0), new Point2D(0.5, -0.51));
+ Line l4 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.51));
Assert.assertTrue(! l1.isParallelTo(l4));
}
@Test
public void testTransform() {
- Line l1 = new Line(new Point2D(1.0 ,1.0), new Point2D(4.0 ,1.0));
- Transform t1 = Line.getTransform(new AffineTransform(0.0, 0.5,
- -1.0, 0.0,
- 1.0, 1.5));
+ Line l1 = new Line(new Vector2D(1.0 ,1.0), new Vector2D(4.0 ,1.0));
+ Transform t1 =
+ Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
Assert.assertEquals(0.5 * FastMath.PI,
((Line) t1.apply(l1)).getAngle(),
1.0e-10);
- Line l2 = new Line(new Point2D(0.0, 0.0), new Point2D(1.0, 1.0));
- Transform t2 = Line.getTransform(new AffineTransform(0.0, 0.5,
- -1.0, 0.0,
- 1.0, 1.5));
+ Line l2 = new Line(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0));
+ Transform t2 =
+ Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
Assert.assertEquals(FastMath.atan2(1.0, -2.0),
((Line) t2.apply(l2)).getAngle(),
1.0e-10);
@@ -119,11 +118,11 @@ public class LineTest {
@Test
public void testIntersection() {
- Line l1 = new Line(new Point2D( 0, 1), new Point2D(1, 2));
- Line l2 = new Line(new Point2D(-1, 2), new Point2D(2, 1));
- Point2D p = (Point2D) l1.intersection(l2);
- Assert.assertEquals(0.5, p.x, 1.0e-10);
- Assert.assertEquals(1.5, p.y, 1.0e-10);
+ Line l1 = new Line(new Vector2D( 0, 1), new Vector2D(1, 2));
+ Line l2 = new Line(new Vector2D(-1, 2), new Vector2D(2, 1));
+ Vector2D p = (Vector2D) l1.intersection(l2);
+ Assert.assertEquals(0.5, p.getX(), 1.0e-10);
+ Assert.assertEquals(1.5, p.getY(), 1.0e-10);
}
}
diff --git a/src/test/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSetTest.java b/src/test/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSetTest.java
index df2c704da..8bae8944d 100644
--- a/src/test/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSetTest.java
+++ b/src/test/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSetTest.java
@@ -21,12 +21,13 @@ import java.util.List;
import org.apache.commons.math.geometry.euclidean.oned.Interval;
import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
import org.apache.commons.math.geometry.euclidean.twod.Line;
-import org.apache.commons.math.geometry.euclidean.twod.Point2D;
+import org.apache.commons.math.geometry.euclidean.twod.Vector2D;
import org.apache.commons.math.geometry.euclidean.twod.PolygonsSet;
import org.apache.commons.math.geometry.partitioning.BSPTree;
import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.RegionFactory;
import org.apache.commons.math.geometry.partitioning.SubHyperplane;
import org.apache.commons.math.util.FastMath;
import org.junit.Assert;
@@ -36,59 +37,59 @@ public class PolygonsSetTest {
@Test
public void testSimplyConnected() {
- Point2D[][] vertices = new Point2D[][] {
- new Point2D[] {
- new Point2D(36.0, 22.0),
- new Point2D(39.0, 32.0),
- new Point2D(19.0, 32.0),
- new Point2D( 6.0, 16.0),
- new Point2D(31.0, 10.0),
- new Point2D(42.0, 16.0),
- new Point2D(34.0, 20.0),
- new Point2D(29.0, 19.0),
- new Point2D(23.0, 22.0),
- new Point2D(33.0, 25.0)
+ Vector2D[][] vertices = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D(36.0, 22.0),
+ new Vector2D(39.0, 32.0),
+ new Vector2D(19.0, 32.0),
+ new Vector2D( 6.0, 16.0),
+ new Vector2D(31.0, 10.0),
+ new Vector2D(42.0, 16.0),
+ new Vector2D(34.0, 20.0),
+ new Vector2D(29.0, 19.0),
+ new Vector2D(23.0, 22.0),
+ new Vector2D(33.0, 25.0)
}
};
PolygonsSet set = buildSet(vertices);
- Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Point2D(50.0, 30.0)));
- checkPoints(Region.Location.INSIDE, set, new Point2D[] {
- new Point2D(30.0, 15.0),
- new Point2D(15.0, 20.0),
- new Point2D(24.0, 25.0),
- new Point2D(35.0, 30.0),
- new Point2D(19.0, 17.0)
+ Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector2D(50.0, 30.0)));
+ checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
+ new Vector2D(30.0, 15.0),
+ new Vector2D(15.0, 20.0),
+ new Vector2D(24.0, 25.0),
+ new Vector2D(35.0, 30.0),
+ new Vector2D(19.0, 17.0)
});
- checkPoints(Region.Location.OUTSIDE, set, new Point2D[] {
- new Point2D(50.0, 30.0),
- new Point2D(30.0, 35.0),
- new Point2D(10.0, 25.0),
- new Point2D(10.0, 10.0),
- new Point2D(40.0, 10.0),
- new Point2D(50.0, 15.0),
- new Point2D(30.0, 22.0)
+ checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
+ new Vector2D(50.0, 30.0),
+ new Vector2D(30.0, 35.0),
+ new Vector2D(10.0, 25.0),
+ new Vector2D(10.0, 10.0),
+ new Vector2D(40.0, 10.0),
+ new Vector2D(50.0, 15.0),
+ new Vector2D(30.0, 22.0)
});
- checkPoints(Region.Location.BOUNDARY, set, new Point2D[] {
- new Point2D(30.0, 32.0),
- new Point2D(34.0, 20.0)
+ checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
+ new Vector2D(30.0, 32.0),
+ new Vector2D(34.0, 20.0)
});
checkVertices(set.getVertices(), vertices);
}
@Test
public void testStair() {
- Point2D[][] vertices = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 0.0, 2.0),
- new Point2D(-0.1, 2.0),
- new Point2D(-0.1, 1.0),
- new Point2D(-0.3, 1.0),
- new Point2D(-0.3, 1.5),
- new Point2D(-1.3, 1.5),
- new Point2D(-1.3, 2.0),
- new Point2D(-1.8, 2.0),
- new Point2D(-1.8 - 1.0 / FastMath.sqrt(2.0),
+ Vector2D[][] vertices = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 0.0, 2.0),
+ new Vector2D(-0.1, 2.0),
+ new Vector2D(-0.1, 1.0),
+ new Vector2D(-0.3, 1.0),
+ new Vector2D(-0.3, 1.5),
+ new Vector2D(-1.3, 1.5),
+ new Vector2D(-1.3, 2.0),
+ new Vector2D(-1.8, 2.0),
+ new Vector2D(-1.8 - 1.0 / FastMath.sqrt(2.0),
2.0 - 1.0 / FastMath.sqrt(2.0))
}
};
@@ -102,91 +103,91 @@ public class PolygonsSetTest {
@Test
public void testHole() {
- Point2D[][] vertices = new Point2D[][] {
- new Point2D[] {
- new Point2D(0.0, 0.0),
- new Point2D(3.0, 0.0),
- new Point2D(3.0, 3.0),
- new Point2D(0.0, 3.0)
- }, new Point2D[] {
- new Point2D(1.0, 2.0),
- new Point2D(2.0, 2.0),
- new Point2D(2.0, 1.0),
- new Point2D(1.0, 1.0)
+ Vector2D[][] vertices = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D(0.0, 0.0),
+ new Vector2D(3.0, 0.0),
+ new Vector2D(3.0, 3.0),
+ new Vector2D(0.0, 3.0)
+ }, new Vector2D[] {
+ new Vector2D(1.0, 2.0),
+ new Vector2D(2.0, 2.0),
+ new Vector2D(2.0, 1.0),
+ new Vector2D(1.0, 1.0)
}
};
PolygonsSet set = buildSet(vertices);
- checkPoints(Region.Location.INSIDE, set, new Point2D[] {
- new Point2D(0.5, 0.5),
- new Point2D(1.5, 0.5),
- new Point2D(2.5, 0.5),
- new Point2D(0.5, 1.5),
- new Point2D(2.5, 1.5),
- new Point2D(0.5, 2.5),
- new Point2D(1.5, 2.5),
- new Point2D(2.5, 2.5),
- new Point2D(0.5, 1.0)
+ checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
+ new Vector2D(0.5, 0.5),
+ new Vector2D(1.5, 0.5),
+ new Vector2D(2.5, 0.5),
+ new Vector2D(0.5, 1.5),
+ new Vector2D(2.5, 1.5),
+ new Vector2D(0.5, 2.5),
+ new Vector2D(1.5, 2.5),
+ new Vector2D(2.5, 2.5),
+ new Vector2D(0.5, 1.0)
});
- checkPoints(Region.Location.OUTSIDE, set, new Point2D[] {
- new Point2D(1.5, 1.5),
- new Point2D(3.5, 1.0),
- new Point2D(4.0, 1.5),
- new Point2D(6.0, 6.0)
+ checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
+ new Vector2D(1.5, 1.5),
+ new Vector2D(3.5, 1.0),
+ new Vector2D(4.0, 1.5),
+ new Vector2D(6.0, 6.0)
});
- checkPoints(Region.Location.BOUNDARY, set, new Point2D[] {
- new Point2D(1.0, 1.0),
- new Point2D(1.5, 0.0),
- new Point2D(1.5, 1.0),
- new Point2D(1.5, 2.0),
- new Point2D(1.5, 3.0),
- new Point2D(3.0, 3.0)
+ checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
+ new Vector2D(1.0, 1.0),
+ new Vector2D(1.5, 0.0),
+ new Vector2D(1.5, 1.0),
+ new Vector2D(1.5, 2.0),
+ new Vector2D(1.5, 3.0),
+ new Vector2D(3.0, 3.0)
});
checkVertices(set.getVertices(), vertices);
}
@Test
public void testDisjointPolygons() {
- Point2D[][] vertices = new Point2D[][] {
- new Point2D[] {
- new Point2D(0.0, 1.0),
- new Point2D(2.0, 1.0),
- new Point2D(1.0, 2.0)
- }, new Point2D[] {
- new Point2D(4.0, 0.0),
- new Point2D(5.0, 1.0),
- new Point2D(3.0, 1.0)
+ Vector2D[][] vertices = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D(0.0, 1.0),
+ new Vector2D(2.0, 1.0),
+ new Vector2D(1.0, 2.0)
+ }, new Vector2D[] {
+ new Vector2D(4.0, 0.0),
+ new Vector2D(5.0, 1.0),
+ new Vector2D(3.0, 1.0)
}
};
PolygonsSet set = buildSet(vertices);
- Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Point2D(1.0, 1.5)));
- checkPoints(Region.Location.INSIDE, set, new Point2D[] {
- new Point2D(1.0, 1.5),
- new Point2D(4.5, 0.8)
+ Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new Vector2D(1.0, 1.5)));
+ checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
+ new Vector2D(1.0, 1.5),
+ new Vector2D(4.5, 0.8)
});
- checkPoints(Region.Location.OUTSIDE, set, new Point2D[] {
- new Point2D(1.0, 0.0),
- new Point2D(3.5, 1.2),
- new Point2D(2.5, 1.0),
- new Point2D(3.0, 4.0)
+ checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
+ new Vector2D(1.0, 0.0),
+ new Vector2D(3.5, 1.2),
+ new Vector2D(2.5, 1.0),
+ new Vector2D(3.0, 4.0)
});
- checkPoints(Region.Location.BOUNDARY, set, new Point2D[] {
- new Point2D(1.0, 1.0),
- new Point2D(3.5, 0.5),
- new Point2D(0.0, 1.0)
+ checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
+ new Vector2D(1.0, 1.0),
+ new Vector2D(3.5, 0.5),
+ new Vector2D(0.0, 1.0)
});
checkVertices(set.getVertices(), vertices);
}
@Test
public void testOppositeHyperplanes() {
- Point2D[][] vertices = new Point2D[][] {
- new Point2D[] {
- new Point2D(1.0, 0.0),
- new Point2D(2.0, 1.0),
- new Point2D(3.0, 1.0),
- new Point2D(2.0, 2.0),
- new Point2D(1.0, 1.0),
- new Point2D(0.0, 1.0)
+ Vector2D[][] vertices = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D(1.0, 0.0),
+ new Vector2D(2.0, 1.0),
+ new Vector2D(3.0, 1.0),
+ new Vector2D(2.0, 2.0),
+ new Vector2D(1.0, 1.0),
+ new Vector2D(0.0, 1.0)
}
};
PolygonsSet set = buildSet(vertices);
@@ -195,16 +196,16 @@ public class PolygonsSetTest {
@Test
public void testSingularPoint() {
- Point2D[][] vertices = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 1.0, 0.0),
- new Point2D( 1.0, 1.0),
- new Point2D( 0.0, 1.0),
- new Point2D( 0.0, 0.0),
- new Point2D(-1.0, 0.0),
- new Point2D(-1.0, -1.0),
- new Point2D( 0.0, -1.0)
+ Vector2D[][] vertices = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 1.0, 0.0),
+ new Vector2D( 1.0, 1.0),
+ new Vector2D( 0.0, 1.0),
+ new Vector2D( 0.0, 0.0),
+ new Vector2D(-1.0, 0.0),
+ new Vector2D(-1.0, -1.0),
+ new Vector2D( 0.0, -1.0)
}
};
PolygonsSet set = buildSet(vertices);
@@ -213,48 +214,48 @@ public class PolygonsSetTest {
@Test
public void testLineIntersection() {
- Point2D[][] vertices = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 2.0, 0.0),
- new Point2D( 2.0, 1.0),
- new Point2D( 3.0, 1.0),
- new Point2D( 3.0, 3.0),
- new Point2D( 1.0, 3.0),
- new Point2D( 1.0, 2.0),
- new Point2D( 0.0, 2.0)
+ Vector2D[][] vertices = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 2.0, 0.0),
+ new Vector2D( 2.0, 1.0),
+ new Vector2D( 3.0, 1.0),
+ new Vector2D( 3.0, 3.0),
+ new Vector2D( 1.0, 3.0),
+ new Vector2D( 1.0, 2.0),
+ new Vector2D( 0.0, 2.0)
}
};
PolygonsSet set = buildSet(vertices);
- Line l1 = new Line(new Point2D(-1.5, 0.0), FastMath.PI / 4);
- SubHyperplane s1 = set.intersection(new SubHyperplane(l1));
+ Line l1 = new Line(new Vector2D(-1.5, 0.0), FastMath.PI / 4);
+ SubLine s1 = (SubLine) set.intersection(l1.wholeHyperplane());
List i1 = ((IntervalsSet) s1.getRemainingRegion()).asList();
Assert.assertEquals(2, i1.size());
Interval v10 = (Interval) i1.get(0);
- Point2D p10Lower = (Point2D) l1.toSpace(new Point1D(v10.getLower()));
+ Vector2D p10Lower = (Vector2D) l1.toSpace(new Vector1D(v10.getLower()));
Assert.assertEquals(0.0, p10Lower.getX(), 1.0e-10);
Assert.assertEquals(1.5, p10Lower.getY(), 1.0e-10);
- Point2D p10Upper = (Point2D) l1.toSpace(new Point1D(v10.getUpper()));
+ Vector2D p10Upper = (Vector2D) l1.toSpace(new Vector1D(v10.getUpper()));
Assert.assertEquals(0.5, p10Upper.getX(), 1.0e-10);
Assert.assertEquals(2.0, p10Upper.getY(), 1.0e-10);
Interval v11 = (Interval) i1.get(1);
- Point2D p11Lower = (Point2D) l1.toSpace(new Point1D(v11.getLower()));
+ Vector2D p11Lower = (Vector2D) l1.toSpace(new Vector1D(v11.getLower()));
Assert.assertEquals(1.0, p11Lower.getX(), 1.0e-10);
Assert.assertEquals(2.5, p11Lower.getY(), 1.0e-10);
- Point2D p11Upper = (Point2D) l1.toSpace(new Point1D(v11.getUpper()));
+ Vector2D p11Upper = (Vector2D) l1.toSpace(new Vector1D(v11.getUpper()));
Assert.assertEquals(1.5, p11Upper.getX(), 1.0e-10);
Assert.assertEquals(3.0, p11Upper.getY(), 1.0e-10);
- Line l2 = new Line(new Point2D(-1.0, 2.0), 0);
- SubHyperplane s2 = set.intersection(new SubHyperplane(l2));
+ Line l2 = new Line(new Vector2D(-1.0, 2.0), 0);
+ SubLine s2 = (SubLine) set.intersection(l2.wholeHyperplane());
List i2 = ((IntervalsSet) s2.getRemainingRegion()).asList();
Assert.assertEquals(1, i2.size());
Interval v20 = (Interval) i2.get(0);
- Point2D p20Lower = (Point2D) l2.toSpace(new Point1D(v20.getLower()));
+ Vector2D p20Lower = (Vector2D) l2.toSpace(new Vector1D(v20.getLower()));
Assert.assertEquals(1.0, p20Lower.getX(), 1.0e-10);
Assert.assertEquals(2.0, p20Lower.getY(), 1.0e-10);
- Point2D p20Upper = (Point2D) l2.toSpace(new Point1D(v20.getUpper()));
+ Vector2D p20Upper = (Vector2D) l2.toSpace(new Vector1D(v20.getUpper()));
Assert.assertEquals(3.0, p20Upper.getX(), 1.0e-10);
Assert.assertEquals(2.0, p20Upper.getY(), 1.0e-10);
@@ -262,37 +263,38 @@ public class PolygonsSetTest {
@Test
public void testUnlimitedSubHyperplane() {
- Point2D[][] vertices1 = new Point2D[][] {
- new Point2D[] {
- new Point2D(0.0, 0.0),
- new Point2D(4.0, 0.0),
- new Point2D(1.4, 1.5),
- new Point2D(0.0, 3.5)
+ Vector2D[][] vertices1 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D(0.0, 0.0),
+ new Vector2D(4.0, 0.0),
+ new Vector2D(1.4, 1.5),
+ new Vector2D(0.0, 3.5)
}
};
PolygonsSet set1 = buildSet(vertices1);
- Point2D[][] vertices2 = new Point2D[][] {
- new Point2D[] {
- new Point2D(1.4, 0.2),
- new Point2D(2.8, -1.2),
- new Point2D(2.5, 0.6)
+ Vector2D[][] vertices2 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D(1.4, 0.2),
+ new Vector2D(2.8, -1.2),
+ new Vector2D(2.5, 0.6)
}
};
PolygonsSet set2 = buildSet(vertices2);
- PolygonsSet set = (PolygonsSet) Region.union(set1.copySelf(),
- set2.copySelf());
+ PolygonsSet set =
+ (PolygonsSet) new RegionFactory().union(set1.copySelf(),
+ set2.copySelf());
checkVertices(set1.getVertices(), vertices1);
checkVertices(set2.getVertices(), vertices2);
- checkVertices(set.getVertices(), new Point2D[][] {
- new Point2D[] {
- new Point2D(0.0, 0.0),
- new Point2D(1.6, 0.0),
- new Point2D(2.8, -1.2),
- new Point2D(2.6, 0.0),
- new Point2D(4.0, 0.0),
- new Point2D(1.4, 1.5),
- new Point2D(0.0, 3.5)
+ checkVertices(set.getVertices(), new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D(0.0, 0.0),
+ new Vector2D(1.6, 0.0),
+ new Vector2D(2.8, -1.2),
+ new Vector2D(2.6, 0.0),
+ new Vector2D(4.0, 0.0),
+ new Vector2D(1.4, 1.5),
+ new Vector2D(0.0, 3.5)
}
});
@@ -300,306 +302,306 @@ public class PolygonsSetTest {
@Test
public void testUnion() {
- Point2D[][] vertices1 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 2.0, 0.0),
- new Point2D( 2.0, 2.0),
- new Point2D( 0.0, 2.0)
+ Vector2D[][] vertices1 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 2.0, 0.0),
+ new Vector2D( 2.0, 2.0),
+ new Vector2D( 0.0, 2.0)
}
};
PolygonsSet set1 = buildSet(vertices1);
- Point2D[][] vertices2 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 1.0, 1.0),
- new Point2D( 3.0, 1.0),
- new Point2D( 3.0, 3.0),
- new Point2D( 1.0, 3.0)
+ Vector2D[][] vertices2 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 1.0, 1.0),
+ new Vector2D( 3.0, 1.0),
+ new Vector2D( 3.0, 3.0),
+ new Vector2D( 1.0, 3.0)
}
};
PolygonsSet set2 = buildSet(vertices2);
- PolygonsSet set = (PolygonsSet) Region.union(set1.copySelf(),
- set2.copySelf());
+ PolygonsSet set = (PolygonsSet) new RegionFactory().union(set1.copySelf(),
+ set2.copySelf());
checkVertices(set1.getVertices(), vertices1);
checkVertices(set2.getVertices(), vertices2);
- checkVertices(set.getVertices(), new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 2.0, 0.0),
- new Point2D( 2.0, 1.0),
- new Point2D( 3.0, 1.0),
- new Point2D( 3.0, 3.0),
- new Point2D( 1.0, 3.0),
- new Point2D( 1.0, 2.0),
- new Point2D( 0.0, 2.0)
+ checkVertices(set.getVertices(), new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 2.0, 0.0),
+ new Vector2D( 2.0, 1.0),
+ new Vector2D( 3.0, 1.0),
+ new Vector2D( 3.0, 3.0),
+ new Vector2D( 1.0, 3.0),
+ new Vector2D( 1.0, 2.0),
+ new Vector2D( 0.0, 2.0)
}
});
- checkPoints(Region.Location.INSIDE, set, new Point2D[] {
- new Point2D(1.0, 1.0),
- new Point2D(0.5, 0.5),
- new Point2D(2.0, 2.0),
- new Point2D(2.5, 2.5),
- new Point2D(0.5, 1.5),
- new Point2D(1.5, 1.5),
- new Point2D(1.5, 0.5),
- new Point2D(1.5, 2.5),
- new Point2D(2.5, 1.5),
- new Point2D(2.5, 2.5)
+ checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
+ new Vector2D(1.0, 1.0),
+ new Vector2D(0.5, 0.5),
+ new Vector2D(2.0, 2.0),
+ new Vector2D(2.5, 2.5),
+ new Vector2D(0.5, 1.5),
+ new Vector2D(1.5, 1.5),
+ new Vector2D(1.5, 0.5),
+ new Vector2D(1.5, 2.5),
+ new Vector2D(2.5, 1.5),
+ new Vector2D(2.5, 2.5)
});
- checkPoints(Region.Location.OUTSIDE, set, new Point2D[] {
- new Point2D(-0.5, 0.5),
- new Point2D( 0.5, 2.5),
- new Point2D( 2.5, 0.5),
- new Point2D( 3.5, 2.5)
+ checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
+ new Vector2D(-0.5, 0.5),
+ new Vector2D( 0.5, 2.5),
+ new Vector2D( 2.5, 0.5),
+ new Vector2D( 3.5, 2.5)
});
- checkPoints(Region.Location.BOUNDARY, set, new Point2D[] {
- new Point2D(0.0, 0.0),
- new Point2D(0.5, 2.0),
- new Point2D(2.0, 0.5),
- new Point2D(2.5, 1.0),
- new Point2D(3.0, 2.5)
+ checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
+ new Vector2D(0.0, 0.0),
+ new Vector2D(0.5, 2.0),
+ new Vector2D(2.0, 0.5),
+ new Vector2D(2.5, 1.0),
+ new Vector2D(3.0, 2.5)
});
}
@Test
public void testIntersection() {
- Point2D[][] vertices1 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 2.0, 0.0),
- new Point2D( 2.0, 2.0),
- new Point2D( 0.0, 2.0)
+ Vector2D[][] vertices1 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 2.0, 0.0),
+ new Vector2D( 2.0, 2.0),
+ new Vector2D( 0.0, 2.0)
}
};
PolygonsSet set1 = buildSet(vertices1);
- Point2D[][] vertices2 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 1.0, 1.0),
- new Point2D( 3.0, 1.0),
- new Point2D( 3.0, 3.0),
- new Point2D( 1.0, 3.0)
+ Vector2D[][] vertices2 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 1.0, 1.0),
+ new Vector2D( 3.0, 1.0),
+ new Vector2D( 3.0, 3.0),
+ new Vector2D( 1.0, 3.0)
}
};
PolygonsSet set2 = buildSet(vertices2);
- PolygonsSet set = (PolygonsSet) Region.intersection(set1.copySelf(),
- set2.copySelf());
+ PolygonsSet set = (PolygonsSet) new RegionFactory().intersection(set1.copySelf(),
+ set2.copySelf());
checkVertices(set1.getVertices(), vertices1);
checkVertices(set2.getVertices(), vertices2);
- checkVertices(set.getVertices(), new Point2D[][] {
- new Point2D[] {
- new Point2D( 1.0, 1.0),
- new Point2D( 2.0, 1.0),
- new Point2D( 2.0, 2.0),
- new Point2D( 1.0, 2.0)
+ checkVertices(set.getVertices(), new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 1.0, 1.0),
+ new Vector2D( 2.0, 1.0),
+ new Vector2D( 2.0, 2.0),
+ new Vector2D( 1.0, 2.0)
}
});
- checkPoints(Region.Location.INSIDE, set, new Point2D[] {
- new Point2D(1.5, 1.5)
+ checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
+ new Vector2D(1.5, 1.5)
});
- checkPoints(Region.Location.OUTSIDE, set, new Point2D[] {
- new Point2D(0.5, 1.5),
- new Point2D(2.5, 1.5),
- new Point2D(1.5, 0.5),
- new Point2D(0.5, 0.5)
+ checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
+ new Vector2D(0.5, 1.5),
+ new Vector2D(2.5, 1.5),
+ new Vector2D(1.5, 0.5),
+ new Vector2D(0.5, 0.5)
});
- checkPoints(Region.Location.BOUNDARY, set, new Point2D[] {
- new Point2D(1.0, 1.0),
- new Point2D(2.0, 2.0),
- new Point2D(1.0, 1.5),
- new Point2D(1.5, 2.0)
+ checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
+ new Vector2D(1.0, 1.0),
+ new Vector2D(2.0, 2.0),
+ new Vector2D(1.0, 1.5),
+ new Vector2D(1.5, 2.0)
});
}
@Test
public void testXor() {
- Point2D[][] vertices1 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 2.0, 0.0),
- new Point2D( 2.0, 2.0),
- new Point2D( 0.0, 2.0)
+ Vector2D[][] vertices1 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 2.0, 0.0),
+ new Vector2D( 2.0, 2.0),
+ new Vector2D( 0.0, 2.0)
}
};
PolygonsSet set1 = buildSet(vertices1);
- Point2D[][] vertices2 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 1.0, 1.0),
- new Point2D( 3.0, 1.0),
- new Point2D( 3.0, 3.0),
- new Point2D( 1.0, 3.0)
+ Vector2D[][] vertices2 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 1.0, 1.0),
+ new Vector2D( 3.0, 1.0),
+ new Vector2D( 3.0, 3.0),
+ new Vector2D( 1.0, 3.0)
}
};
PolygonsSet set2 = buildSet(vertices2);
- PolygonsSet set = (PolygonsSet) Region.xor(set1.copySelf(),
- set2.copySelf());
+ PolygonsSet set = (PolygonsSet) new RegionFactory().xor(set1.copySelf(),
+ set2.copySelf());
checkVertices(set1.getVertices(), vertices1);
checkVertices(set2.getVertices(), vertices2);
- checkVertices(set.getVertices(), new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 2.0, 0.0),
- new Point2D( 2.0, 1.0),
- new Point2D( 3.0, 1.0),
- new Point2D( 3.0, 3.0),
- new Point2D( 1.0, 3.0),
- new Point2D( 1.0, 2.0),
- new Point2D( 0.0, 2.0)
+ checkVertices(set.getVertices(), new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 2.0, 0.0),
+ new Vector2D( 2.0, 1.0),
+ new Vector2D( 3.0, 1.0),
+ new Vector2D( 3.0, 3.0),
+ new Vector2D( 1.0, 3.0),
+ new Vector2D( 1.0, 2.0),
+ new Vector2D( 0.0, 2.0)
},
- new Point2D[] {
- new Point2D( 1.0, 1.0),
- new Point2D( 1.0, 2.0),
- new Point2D( 2.0, 2.0),
- new Point2D( 2.0, 1.0)
+ new Vector2D[] {
+ new Vector2D( 1.0, 1.0),
+ new Vector2D( 1.0, 2.0),
+ new Vector2D( 2.0, 2.0),
+ new Vector2D( 2.0, 1.0)
}
});
- checkPoints(Region.Location.INSIDE, set, new Point2D[] {
- new Point2D(0.5, 0.5),
- new Point2D(2.5, 2.5),
- new Point2D(0.5, 1.5),
- new Point2D(1.5, 0.5),
- new Point2D(1.5, 2.5),
- new Point2D(2.5, 1.5),
- new Point2D(2.5, 2.5)
+ checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
+ new Vector2D(0.5, 0.5),
+ new Vector2D(2.5, 2.5),
+ new Vector2D(0.5, 1.5),
+ new Vector2D(1.5, 0.5),
+ new Vector2D(1.5, 2.5),
+ new Vector2D(2.5, 1.5),
+ new Vector2D(2.5, 2.5)
});
- checkPoints(Region.Location.OUTSIDE, set, new Point2D[] {
- new Point2D(-0.5, 0.5),
- new Point2D( 0.5, 2.5),
- new Point2D( 2.5, 0.5),
- new Point2D( 1.5, 1.5),
- new Point2D( 3.5, 2.5)
+ checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
+ new Vector2D(-0.5, 0.5),
+ new Vector2D( 0.5, 2.5),
+ new Vector2D( 2.5, 0.5),
+ new Vector2D( 1.5, 1.5),
+ new Vector2D( 3.5, 2.5)
});
- checkPoints(Region.Location.BOUNDARY, set, new Point2D[] {
- new Point2D(1.0, 1.0),
- new Point2D(2.0, 2.0),
- new Point2D(1.5, 1.0),
- new Point2D(2.0, 1.5),
- new Point2D(0.0, 0.0),
- new Point2D(0.5, 2.0),
- new Point2D(2.0, 0.5),
- new Point2D(2.5, 1.0),
- new Point2D(3.0, 2.5)
+ checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
+ new Vector2D(1.0, 1.0),
+ new Vector2D(2.0, 2.0),
+ new Vector2D(1.5, 1.0),
+ new Vector2D(2.0, 1.5),
+ new Vector2D(0.0, 0.0),
+ new Vector2D(0.5, 2.0),
+ new Vector2D(2.0, 0.5),
+ new Vector2D(2.5, 1.0),
+ new Vector2D(3.0, 2.5)
});
}
@Test
public void testDifference() {
- Point2D[][] vertices1 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 2.0, 0.0),
- new Point2D( 2.0, 2.0),
- new Point2D( 0.0, 2.0)
+ Vector2D[][] vertices1 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 2.0, 0.0),
+ new Vector2D( 2.0, 2.0),
+ new Vector2D( 0.0, 2.0)
}
};
PolygonsSet set1 = buildSet(vertices1);
- Point2D[][] vertices2 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 1.0, 1.0),
- new Point2D( 3.0, 1.0),
- new Point2D( 3.0, 3.0),
- new Point2D( 1.0, 3.0)
+ Vector2D[][] vertices2 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 1.0, 1.0),
+ new Vector2D( 3.0, 1.0),
+ new Vector2D( 3.0, 3.0),
+ new Vector2D( 1.0, 3.0)
}
};
PolygonsSet set2 = buildSet(vertices2);
- PolygonsSet set = (PolygonsSet) Region.difference(set1.copySelf(),
- set2.copySelf());
+ PolygonsSet set = (PolygonsSet) new RegionFactory().difference(set1.copySelf(),
+ set2.copySelf());
checkVertices(set1.getVertices(), vertices1);
checkVertices(set2.getVertices(), vertices2);
- checkVertices(set.getVertices(), new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.0, 0.0),
- new Point2D( 2.0, 0.0),
- new Point2D( 2.0, 1.0),
- new Point2D( 1.0, 1.0),
- new Point2D( 1.0, 2.0),
- new Point2D( 0.0, 2.0)
+ checkVertices(set.getVertices(), new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.0, 0.0),
+ new Vector2D( 2.0, 0.0),
+ new Vector2D( 2.0, 1.0),
+ new Vector2D( 1.0, 1.0),
+ new Vector2D( 1.0, 2.0),
+ new Vector2D( 0.0, 2.0)
}
});
- checkPoints(Region.Location.INSIDE, set, new Point2D[] {
- new Point2D(0.5, 0.5),
- new Point2D(0.5, 1.5),
- new Point2D(1.5, 0.5)
+ checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
+ new Vector2D(0.5, 0.5),
+ new Vector2D(0.5, 1.5),
+ new Vector2D(1.5, 0.5)
});
- checkPoints(Region.Location.OUTSIDE, set, new Point2D[] {
- new Point2D( 2.5, 2.5),
- new Point2D(-0.5, 0.5),
- new Point2D( 0.5, 2.5),
- new Point2D( 2.5, 0.5),
- new Point2D( 1.5, 1.5),
- new Point2D( 3.5, 2.5),
- new Point2D( 1.5, 2.5),
- new Point2D( 2.5, 1.5),
- new Point2D( 2.0, 1.5),
- new Point2D( 2.0, 2.0),
- new Point2D( 2.5, 1.0),
- new Point2D( 2.5, 2.5),
- new Point2D( 3.0, 2.5)
+ checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
+ new Vector2D( 2.5, 2.5),
+ new Vector2D(-0.5, 0.5),
+ new Vector2D( 0.5, 2.5),
+ new Vector2D( 2.5, 0.5),
+ new Vector2D( 1.5, 1.5),
+ new Vector2D( 3.5, 2.5),
+ new Vector2D( 1.5, 2.5),
+ new Vector2D( 2.5, 1.5),
+ new Vector2D( 2.0, 1.5),
+ new Vector2D( 2.0, 2.0),
+ new Vector2D( 2.5, 1.0),
+ new Vector2D( 2.5, 2.5),
+ new Vector2D( 3.0, 2.5)
});
- checkPoints(Region.Location.BOUNDARY, set, new Point2D[] {
- new Point2D(1.0, 1.0),
- new Point2D(1.5, 1.0),
- new Point2D(0.0, 0.0),
- new Point2D(0.5, 2.0),
- new Point2D(2.0, 0.5)
+ checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
+ new Vector2D(1.0, 1.0),
+ new Vector2D(1.5, 1.0),
+ new Vector2D(0.0, 0.0),
+ new Vector2D(0.5, 2.0),
+ new Vector2D(2.0, 0.5)
});
}
@Test
public void testEmptyDifference() {
- Point2D[][] vertices1 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.5, 3.5),
- new Point2D( 0.5, 4.5),
- new Point2D(-0.5, 4.5),
- new Point2D(-0.5, 3.5)
+ Vector2D[][] vertices1 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.5, 3.5),
+ new Vector2D( 0.5, 4.5),
+ new Vector2D(-0.5, 4.5),
+ new Vector2D(-0.5, 3.5)
}
};
PolygonsSet set1 = buildSet(vertices1);
- Point2D[][] vertices2 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 1.0, 2.0),
- new Point2D( 1.0, 8.0),
- new Point2D(-1.0, 8.0),
- new Point2D(-1.0, 2.0)
+ Vector2D[][] vertices2 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 1.0, 2.0),
+ new Vector2D( 1.0, 8.0),
+ new Vector2D(-1.0, 8.0),
+ new Vector2D(-1.0, 2.0)
}
};
PolygonsSet set2 = buildSet(vertices2);
- Assert.assertTrue(Region.difference(set1.copySelf(), set2.copySelf()).isEmpty());
+ Assert.assertTrue(new RegionFactory().difference(set1.copySelf(), set2.copySelf()).isEmpty());
}
@Test
public void testChoppedHexagon() {
double pi6 = FastMath.PI / 6.0;
double sqrt3 = FastMath.sqrt(3.0);
- SubHyperplane[] hyp = {
- new SubHyperplane(new Line(new Point2D( 0.0, 1.0), 5 * pi6)),
- new SubHyperplane(new Line(new Point2D(-sqrt3, 1.0), 7 * pi6)),
- new SubHyperplane(new Line(new Point2D(-sqrt3, 1.0), 9 * pi6)),
- new SubHyperplane(new Line(new Point2D(-sqrt3, 0.0), 11 * pi6)),
- new SubHyperplane(new Line(new Point2D( 0.0, 0.0), 13 * pi6)),
- new SubHyperplane(new Line(new Point2D( 0.0, 1.0), 3 * pi6)),
- new SubHyperplane(new Line(new Point2D(-5.0 * sqrt3 / 6.0, 0.0), 9 * pi6))
+ SubLine[] hyp = {
+ new Line(new Vector2D( 0.0, 1.0), 5 * pi6).wholeHyperplane(),
+ new Line(new Vector2D(-sqrt3, 1.0), 7 * pi6).wholeHyperplane(),
+ new Line(new Vector2D(-sqrt3, 1.0), 9 * pi6).wholeHyperplane(),
+ new Line(new Vector2D(-sqrt3, 0.0), 11 * pi6).wholeHyperplane(),
+ new Line(new Vector2D( 0.0, 0.0), 13 * pi6).wholeHyperplane(),
+ new Line(new Vector2D( 0.0, 1.0), 3 * pi6).wholeHyperplane(),
+ new Line(new Vector2D(-5.0 * sqrt3 / 6.0, 0.0), 9 * pi6).wholeHyperplane()
};
- hyp[1] = hyp[0].getHyperplane().split(hyp[1]).getMinus();
- hyp[2] = hyp[1].getHyperplane().split(hyp[2]).getMinus();
- hyp[3] = hyp[2].getHyperplane().split(hyp[3]).getMinus();
- hyp[4] = hyp[0].getHyperplane().split(hyp[3].getHyperplane().split(hyp[4]).getMinus()).getMinus();
- hyp[5] = hyp[0].getHyperplane().split(hyp[4].getHyperplane().split(hyp[5]).getMinus()).getMinus();
- hyp[6] = hyp[1].getHyperplane().split(hyp[3].getHyperplane().split(hyp[6]).getMinus()).getMinus();
- BSPTree tree = new BSPTree(Boolean.TRUE);
+ hyp[1] = (SubLine) hyp[1].split(hyp[0].getHyperplane()).getMinus();
+ hyp[2] = (SubLine) hyp[2].split(hyp[1].getHyperplane()).getMinus();
+ hyp[3] = (SubLine) hyp[3].split(hyp[2].getHyperplane()).getMinus();
+ hyp[4] = (SubLine) hyp[4].split(hyp[3].getHyperplane()).getMinus().split(hyp[0].getHyperplane()).getMinus();
+ hyp[5] = (SubLine) hyp[5].split(hyp[4].getHyperplane()).getMinus().split(hyp[0].getHyperplane()).getMinus();
+ hyp[6] = (SubLine) hyp[6].split(hyp[3].getHyperplane()).getMinus().split(hyp[1].getHyperplane()).getMinus();
+ BSPTree tree = new BSPTree(Boolean.TRUE);
for (int i = hyp.length - 1; i >= 0; --i) {
- tree = new BSPTree(hyp[i], new BSPTree(Boolean.FALSE), tree, null);
+ tree = new BSPTree(hyp[i], new BSPTree(Boolean.FALSE), tree, null);
}
PolygonsSet set = new PolygonsSet(tree);
- SubHyperplane splitter =
- new SubHyperplane(new Line(new Point2D(-2.0 * sqrt3 / 3.0, 0.0), 9 * pi6));
+ SubLine splitter =
+ new Line(new Vector2D(-2.0 * sqrt3 / 3.0, 0.0), 9 * pi6).wholeHyperplane();
PolygonsSet slice =
- new PolygonsSet(new BSPTree(splitter,
- set.getTree(false).split(splitter).getPlus(),
- new BSPTree(Boolean.FALSE), null));
+ new PolygonsSet(new BSPTree(splitter,
+ set.getTree(false).split(splitter).getPlus(),
+ new BSPTree(Boolean.FALSE), null));
Assert.assertEquals(Region.Location.OUTSIDE,
- slice.checkPoint(new Point2D(0.1, 0.5)));
+ slice.checkPoint(new Vector2D(0.1, 0.5)));
Assert.assertEquals(11.0 / 3.0, slice.getBoundarySize(), 1.0e-10);
}
@@ -607,27 +609,27 @@ public class PolygonsSetTest {
@Test
public void testConcentric() {
double h = FastMath.sqrt(3.0) / 2.0;
- Point2D[][] vertices1 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.00, 0.1 * h),
- new Point2D( 0.05, 0.1 * h),
- new Point2D( 0.10, 0.2 * h),
- new Point2D( 0.05, 0.3 * h),
- new Point2D(-0.05, 0.3 * h),
- new Point2D(-0.10, 0.2 * h),
- new Point2D(-0.05, 0.1 * h)
+ Vector2D[][] vertices1 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.00, 0.1 * h),
+ new Vector2D( 0.05, 0.1 * h),
+ new Vector2D( 0.10, 0.2 * h),
+ new Vector2D( 0.05, 0.3 * h),
+ new Vector2D(-0.05, 0.3 * h),
+ new Vector2D(-0.10, 0.2 * h),
+ new Vector2D(-0.05, 0.1 * h)
}
};
PolygonsSet set1 = buildSet(vertices1);
- Point2D[][] vertices2 = new Point2D[][] {
- new Point2D[] {
- new Point2D( 0.00, 0.0 * h),
- new Point2D( 0.10, 0.0 * h),
- new Point2D( 0.20, 0.2 * h),
- new Point2D( 0.10, 0.4 * h),
- new Point2D(-0.10, 0.4 * h),
- new Point2D(-0.20, 0.2 * h),
- new Point2D(-0.10, 0.0 * h)
+ Vector2D[][] vertices2 = new Vector2D[][] {
+ new Vector2D[] {
+ new Vector2D( 0.00, 0.0 * h),
+ new Vector2D( 0.10, 0.0 * h),
+ new Vector2D( 0.20, 0.2 * h),
+ new Vector2D( 0.10, 0.4 * h),
+ new Vector2D(-0.10, 0.4 * h),
+ new Vector2D(-0.20, 0.2 * h),
+ new Vector2D(-0.10, 0.0 * h)
}
};
PolygonsSet set2 = buildSet(vertices2);
@@ -636,109 +638,127 @@ public class PolygonsSetTest {
@Test
public void testBug20040520() {
- BSPTree a0 = new BSPTree(buildSegment(new Point2D(0.85, -0.05),
- new Point2D(0.90, -0.10)),
- new BSPTree(Boolean.FALSE),
- new BSPTree(Boolean.TRUE),
- null);
- BSPTree a1 = new BSPTree(buildSegment(new Point2D(0.85, -0.10),
- new Point2D(0.90, -0.10)),
- new BSPTree(Boolean.FALSE), a0, null);
- BSPTree a2 = new BSPTree(buildSegment(new Point2D(0.90, -0.05),
- new Point2D(0.85, -0.05)),
- new BSPTree(Boolean.FALSE), a1, null);
- BSPTree a3 = new BSPTree(buildSegment(new Point2D(0.82, -0.05),
- new Point2D(0.82, -0.08)),
- new BSPTree(Boolean.FALSE),
- new BSPTree(Boolean.TRUE),
- null);
- BSPTree a4 = new BSPTree(buildHalfLine(new Point2D(0.85, -0.05),
- new Point2D(0.80, -0.05),
- false),
- new BSPTree(Boolean.FALSE), a3, null);
- BSPTree a5 = new BSPTree(buildSegment(new Point2D(0.82, -0.08),
- new Point2D(0.82, -0.18)),
- new BSPTree(Boolean.FALSE),
- new BSPTree(Boolean.TRUE),
- null);
- BSPTree a6 = new BSPTree(buildHalfLine(new Point2D(0.82, -0.18),
- new Point2D(0.85, -0.15),
- true),
- new BSPTree(Boolean.FALSE), a5, null);
- BSPTree a7 = new BSPTree(buildHalfLine(new Point2D(0.85, -0.05),
- new Point2D(0.82, -0.08),
- false),
- a4, a6, null);
- BSPTree a8 = new BSPTree(buildLine(new Point2D(0.85, -0.25),
- new Point2D(0.85, 0.05)),
- a2, a7, null);
- BSPTree a9 = new BSPTree(buildLine(new Point2D(0.90, 0.05),
- new Point2D(0.90, -0.50)),
- a8, new BSPTree(Boolean.FALSE), null);
+ BSPTree a0 =
+ new BSPTree(buildSegment(new Vector2D(0.85, -0.05),
+ new Vector2D(0.90, -0.10)),
+ new BSPTree(Boolean.FALSE),
+ new BSPTree(Boolean.TRUE),
+ null);
+ BSPTree a1 =
+ new BSPTree(buildSegment(new Vector2D(0.85, -0.10),
+ new Vector2D(0.90, -0.10)),
+ new BSPTree(Boolean.FALSE), a0, null);
+ BSPTree a2 =
+ new BSPTree(buildSegment(new Vector2D(0.90, -0.05),
+ new Vector2D(0.85, -0.05)),
+ new BSPTree(Boolean.FALSE), a1, null);
+ BSPTree a3 =
+ new BSPTree(buildSegment(new Vector2D(0.82, -0.05),
+ new Vector2D(0.82, -0.08)),
+ new BSPTree(Boolean.FALSE),
+ new BSPTree(Boolean.TRUE),
+ null);
+ BSPTree a4 =
+ new BSPTree(buildHalfLine(new Vector2D(0.85, -0.05),
+ new Vector2D(0.80, -0.05),
+ false),
+ new BSPTree(Boolean.FALSE), a3, null);
+ BSPTree a5 =
+ new BSPTree(buildSegment(new Vector2D(0.82, -0.08),
+ new Vector2D(0.82, -0.18)),
+ new BSPTree(Boolean.FALSE),
+ new BSPTree(Boolean.TRUE),
+ null);
+ BSPTree a6 =
+ new BSPTree(buildHalfLine(new Vector2D(0.82, -0.18),
+ new Vector2D(0.85, -0.15),
+ true),
+ new BSPTree(Boolean.FALSE), a5, null);
+ BSPTree a7 =
+ new BSPTree(buildHalfLine(new Vector2D(0.85, -0.05),
+ new Vector2D(0.82, -0.08),
+ false),
+ a4, a6, null);
+ BSPTree a8 =
+ new BSPTree(buildLine(new Vector2D(0.85, -0.25),
+ new Vector2D(0.85, 0.05)),
+ a2, a7, null);
+ BSPTree a9 =
+ new BSPTree(buildLine(new Vector2D(0.90, 0.05),
+ new Vector2D(0.90, -0.50)),
+ a8, new BSPTree(Boolean.FALSE), null);
- BSPTree b0 = new BSPTree(buildSegment(new Point2D(0.92, -0.12),
- new Point2D(0.92, -0.08)),
- new BSPTree(Boolean.FALSE), new BSPTree(Boolean.TRUE),
- null);
- BSPTree b1 = new BSPTree(buildHalfLine(new Point2D(0.92, -0.08),
- new Point2D(0.90, -0.10),
- true),
- new BSPTree(Boolean.FALSE), b0, null);
- BSPTree b2 = new BSPTree(buildSegment(new Point2D(0.92, -0.18),
- new Point2D(0.92, -0.12)),
- new BSPTree(Boolean.FALSE), new BSPTree(Boolean.TRUE),
- null);
- BSPTree b3 = new BSPTree(buildSegment(new Point2D(0.85, -0.15),
- new Point2D(0.90, -0.20)),
- new BSPTree(Boolean.FALSE), b2, null);
- BSPTree b4 = new BSPTree(buildSegment(new Point2D(0.95, -0.15),
- new Point2D(0.85, -0.05)),
- b1, b3, null);
- BSPTree b5 = new BSPTree(buildHalfLine(new Point2D(0.85, -0.05),
- new Point2D(0.85, -0.25),
- true),
- new BSPTree(Boolean.FALSE), b4, null);
- BSPTree b6 = new BSPTree(buildLine(new Point2D(0.0, -1.10),
- new Point2D(1.0, -0.10)),
- new BSPTree(Boolean.FALSE), b5, null);
+ BSPTree