No tabs.
This commit is contained in:
parent
5ec8070228
commit
29c067466e
|
@ -644,10 +644,10 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
|
|||
for (ConnectableSegment s = getUnprocessed(segments); s != null; s = getUnprocessed(segments)) {
|
||||
final List<Segment> loop = followLoop(s);
|
||||
if (loop != null) {
|
||||
// an open loop is one that has fewer than two segments or has a null
|
||||
// start point; the case where we have two segments in a closed loop
|
||||
// (ie, an infinitely thin, degenerate loop) will result in null being
|
||||
// returned from the followLoops method
|
||||
// an open loop is one that has fewer than two segments or has a null
|
||||
// start point; the case where we have two segments in a closed loop
|
||||
// (ie, an infinitely thin, degenerate loop) will result in null being
|
||||
// returned from the followLoops method
|
||||
if (loop.size() < 2 || loop.get(0).getStart() == null) {
|
||||
// this is an open loop, we put it on the front
|
||||
loops.add(0, loop);
|
||||
|
@ -867,22 +867,22 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
|
|||
* @param loop segments loop to filter (will be modified in-place)
|
||||
*/
|
||||
private void filterSpuriousVertices(final List<Segment> loop) {
|
||||
// we need at least 2 segments in order for one of the contained vertices
|
||||
// to be unnecessary
|
||||
if (loop.size() > 1) {
|
||||
for (int i = 0; i < loop.size(); ++i) {
|
||||
final Segment previous = loop.get(i);
|
||||
int j = (i + 1) % loop.size();
|
||||
final Segment next = loop.get(j);
|
||||
if (next != null &&
|
||||
Precision.equals(previous.getLine().getAngle(), next.getLine().getAngle(), Precision.EPSILON)) {
|
||||
// the vertex between the two edges is a spurious one
|
||||
// replace the two segments by a single one
|
||||
loop.set(j, new Segment(previous.getStart(), next.getEnd(), previous.getLine()));
|
||||
loop.remove(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
// we need at least 2 segments in order for one of the contained vertices
|
||||
// to be unnecessary
|
||||
if (loop.size() > 1) {
|
||||
for (int i = 0; i < loop.size(); ++i) {
|
||||
final Segment previous = loop.get(i);
|
||||
int j = (i + 1) % loop.size();
|
||||
final Segment next = loop.get(j);
|
||||
if (next != null &&
|
||||
Precision.equals(previous.getLine().getAngle(), next.getLine().getAngle(), Precision.EPSILON)) {
|
||||
// the vertex between the two edges is a spurious one
|
||||
// replace the two segments by a single one
|
||||
loop.set(j, new Segment(previous.getStart(), next.getEnd(), previous.getLine()));
|
||||
loop.remove(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Private extension of Segment allowing connection. */
|
||||
|
@ -1078,23 +1078,23 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
|
|||
* @return node closest to point, or null if point is null or no node is closer than tolerance
|
||||
*/
|
||||
private BSPTree<Euclidean2D> selectClosest(final Cartesian2D point, final Iterable<BSPTree<Euclidean2D>> candidates) {
|
||||
if (point != null) {
|
||||
BSPTree<Euclidean2D> selected = null;
|
||||
double min = Double.POSITIVE_INFINITY;
|
||||
if (point != null) {
|
||||
BSPTree<Euclidean2D> selected = null;
|
||||
double min = Double.POSITIVE_INFINITY;
|
||||
|
||||
for (final BSPTree<Euclidean2D> node : candidates) {
|
||||
final double distance = FastMath.abs(node.getCut().getHyperplane().getOffset(point));
|
||||
if (distance < min) {
|
||||
selected = node;
|
||||
min = distance;
|
||||
}
|
||||
}
|
||||
for (final BSPTree<Euclidean2D> node : candidates) {
|
||||
final double distance = FastMath.abs(node.getCut().getHyperplane().getOffset(point));
|
||||
if (distance < min) {
|
||||
selected = node;
|
||||
min = distance;
|
||||
}
|
||||
}
|
||||
|
||||
if (min <= tolerance) {
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if (min <= tolerance) {
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Get the segments.
|
||||
|
|
|
@ -29,7 +29,7 @@ public class SubOrientedPointTest {
|
|||
|
||||
@Test
|
||||
public void testGetSize() {
|
||||
// arrange
|
||||
// arrange
|
||||
OrientedPoint hyperplane = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
SubOrientedPoint pt = (SubOrientedPoint) hyperplane.wholeHyperplane();
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class SubOrientedPointTest {
|
|||
|
||||
@Test
|
||||
public void testIsEmpty() {
|
||||
// arrange
|
||||
// arrange
|
||||
OrientedPoint hyperplane = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
SubOrientedPoint pt = (SubOrientedPoint) hyperplane.wholeHyperplane();
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class SubOrientedPointTest {
|
|||
|
||||
@Test
|
||||
public void testBuildNew() {
|
||||
// arrange
|
||||
// arrange
|
||||
OrientedPoint originalHyperplane = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
SubOrientedPoint pt = (SubOrientedPoint) originalHyperplane.wholeHyperplane();
|
||||
|
||||
|
@ -67,84 +67,84 @@ public class SubOrientedPointTest {
|
|||
|
||||
@Test
|
||||
public void testSplit_resultOnMinusSide() {
|
||||
// arrange
|
||||
OrientedPoint hyperplane = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
IntervalsSet interval = new IntervalsSet(4, 5, TEST_TOLERANCE);
|
||||
SubOrientedPoint pt = new SubOrientedPoint(hyperplane, interval);
|
||||
// arrange
|
||||
OrientedPoint hyperplane = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
IntervalsSet interval = new IntervalsSet(4, 5, TEST_TOLERANCE);
|
||||
SubOrientedPoint pt = new SubOrientedPoint(hyperplane, interval);
|
||||
|
||||
OrientedPoint splitter = new OrientedPoint(new Cartesian1D(2), true, TEST_TOLERANCE);
|
||||
OrientedPoint splitter = new OrientedPoint(new Cartesian1D(2), true, TEST_TOLERANCE);
|
||||
|
||||
// act
|
||||
SplitSubHyperplane<Euclidean1D> split = pt.split(splitter);
|
||||
// act
|
||||
SplitSubHyperplane<Euclidean1D> split = pt.split(splitter);
|
||||
|
||||
// assert
|
||||
Assert.assertEquals(Side.MINUS, split.getSide());
|
||||
// assert
|
||||
Assert.assertEquals(Side.MINUS, split.getSide());
|
||||
|
||||
SubOrientedPoint minusSub = ((SubOrientedPoint) split.getMinus());
|
||||
Assert.assertNotNull(minusSub);
|
||||
SubOrientedPoint minusSub = ((SubOrientedPoint) split.getMinus());
|
||||
Assert.assertNotNull(minusSub);
|
||||
|
||||
OrientedPoint minusHyper = (OrientedPoint) minusSub.getHyperplane();
|
||||
Assert.assertEquals(1, minusHyper.getLocation().getX(), TEST_TOLERANCE);
|
||||
OrientedPoint minusHyper = (OrientedPoint) minusSub.getHyperplane();
|
||||
Assert.assertEquals(1, minusHyper.getLocation().getX(), TEST_TOLERANCE);
|
||||
|
||||
List<Interval> minusIntervals = ((IntervalsSet) minusSub.getRemainingRegion()).asList();
|
||||
Assert.assertEquals(1, minusIntervals.size());
|
||||
Assert.assertEquals(4, minusIntervals.get(0).getInf(), TEST_TOLERANCE);
|
||||
Assert.assertEquals(5, minusIntervals.get(0).getSup(), TEST_TOLERANCE);
|
||||
List<Interval> minusIntervals = ((IntervalsSet) minusSub.getRemainingRegion()).asList();
|
||||
Assert.assertEquals(1, minusIntervals.size());
|
||||
Assert.assertEquals(4, minusIntervals.get(0).getInf(), TEST_TOLERANCE);
|
||||
Assert.assertEquals(5, minusIntervals.get(0).getSup(), TEST_TOLERANCE);
|
||||
|
||||
Assert.assertNull(split.getPlus());
|
||||
Assert.assertNull(split.getPlus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplit_resultOnPlusSide() {
|
||||
// arrange
|
||||
OrientedPoint hyperplane = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
IntervalsSet interval = new IntervalsSet(4, 5, TEST_TOLERANCE);
|
||||
SubOrientedPoint pt = new SubOrientedPoint(hyperplane, interval);
|
||||
// arrange
|
||||
OrientedPoint hyperplane = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
IntervalsSet interval = new IntervalsSet(4, 5, TEST_TOLERANCE);
|
||||
SubOrientedPoint pt = new SubOrientedPoint(hyperplane, interval);
|
||||
|
||||
OrientedPoint splitter = new OrientedPoint(new Cartesian1D(0), true, TEST_TOLERANCE);
|
||||
OrientedPoint splitter = new OrientedPoint(new Cartesian1D(0), true, TEST_TOLERANCE);
|
||||
|
||||
// act
|
||||
SplitSubHyperplane<Euclidean1D> split = pt.split(splitter);
|
||||
// act
|
||||
SplitSubHyperplane<Euclidean1D> split = pt.split(splitter);
|
||||
|
||||
// assert
|
||||
Assert.assertEquals(Side.PLUS, split.getSide());
|
||||
// assert
|
||||
Assert.assertEquals(Side.PLUS, split.getSide());
|
||||
|
||||
Assert.assertNull(split.getMinus());
|
||||
Assert.assertNull(split.getMinus());
|
||||
|
||||
SubOrientedPoint plusSub = ((SubOrientedPoint) split.getPlus());
|
||||
Assert.assertNotNull(plusSub);
|
||||
SubOrientedPoint plusSub = ((SubOrientedPoint) split.getPlus());
|
||||
Assert.assertNotNull(plusSub);
|
||||
|
||||
OrientedPoint plusHyper = (OrientedPoint) plusSub.getHyperplane();
|
||||
Assert.assertEquals(1, plusHyper.getLocation().getX(), TEST_TOLERANCE);
|
||||
OrientedPoint plusHyper = (OrientedPoint) plusSub.getHyperplane();
|
||||
Assert.assertEquals(1, plusHyper.getLocation().getX(), TEST_TOLERANCE);
|
||||
|
||||
List<Interval> plusIntervals = ((IntervalsSet) plusSub.getRemainingRegion()).asList();
|
||||
Assert.assertEquals(1, plusIntervals.size());
|
||||
Assert.assertEquals(4, plusIntervals.get(0).getInf(), TEST_TOLERANCE);
|
||||
Assert.assertEquals(5, plusIntervals.get(0).getSup(), TEST_TOLERANCE);
|
||||
List<Interval> plusIntervals = ((IntervalsSet) plusSub.getRemainingRegion()).asList();
|
||||
Assert.assertEquals(1, plusIntervals.size());
|
||||
Assert.assertEquals(4, plusIntervals.get(0).getInf(), TEST_TOLERANCE);
|
||||
Assert.assertEquals(5, plusIntervals.get(0).getSup(), TEST_TOLERANCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplit_equivalentHyperplanes() {
|
||||
// arrange
|
||||
OrientedPoint hyperplane = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
IntervalsSet interval = new IntervalsSet(4, 5, TEST_TOLERANCE);
|
||||
SubOrientedPoint pt = new SubOrientedPoint(hyperplane, interval);
|
||||
// arrange
|
||||
OrientedPoint hyperplane = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
IntervalsSet interval = new IntervalsSet(4, 5, TEST_TOLERANCE);
|
||||
SubOrientedPoint pt = new SubOrientedPoint(hyperplane, interval);
|
||||
|
||||
OrientedPoint splitter = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
OrientedPoint splitter = new OrientedPoint(new Cartesian1D(1), true, TEST_TOLERANCE);
|
||||
|
||||
// act
|
||||
SplitSubHyperplane<Euclidean1D> split = pt.split(splitter);
|
||||
// act
|
||||
SplitSubHyperplane<Euclidean1D> split = pt.split(splitter);
|
||||
|
||||
// assert
|
||||
Assert.assertEquals(Side.HYPER, split.getSide());
|
||||
// assert
|
||||
Assert.assertEquals(Side.HYPER, split.getSide());
|
||||
|
||||
Assert.assertNull(split.getMinus());
|
||||
Assert.assertNull(split.getPlus());
|
||||
Assert.assertNull(split.getMinus());
|
||||
Assert.assertNull(split.getPlus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplit_usesToleranceFromParentHyperplane() {
|
||||
// arrange
|
||||
// arrange
|
||||
OrientedPoint hyperplane = new OrientedPoint(new Cartesian1D(1), true, 0.1);
|
||||
SubOrientedPoint pt = (SubOrientedPoint) hyperplane.wholeHyperplane();
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ public class PolygonsSetTest {
|
|||
|
||||
@Test
|
||||
public void testSingleInfiniteLine() {
|
||||
// arrange
|
||||
// arrange
|
||||
double tolerance = 1e-10;
|
||||
Line line = new Line(new Cartesian2D(0, 0), new Cartesian2D(1, 1), tolerance);
|
||||
|
||||
|
@ -123,7 +123,7 @@ public class PolygonsSetTest {
|
|||
|
||||
@Test
|
||||
public void testMixOfFiniteAndInfiniteBoundaries() {
|
||||
// arrange
|
||||
// arrange
|
||||
double tolerance = 1e-10;
|
||||
|
||||
Line line = new Line(new Cartesian2D(1, 0), new Cartesian2D(1, 1), tolerance);
|
||||
|
|
Loading…
Reference in New Issue