Skip to content

Commit

Permalink
Merge e299a59 into 60bcdd4
Browse files Browse the repository at this point in the history
  • Loading branch information
darkma773r committed Feb 2, 2018
2 parents 60bcdd4 + e299a59 commit e52335b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,15 @@ 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) {
// Go through the list and compare each segment with the next
// one in line. We can remove the shared vertex if the segments
// are not infinite and they lie on the same line.
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 &&
previous.getStart() != null && next.getEnd() != 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.geometry.euclidean.oned.Interval;
import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet;
import org.apache.commons.math4.geometry.GeometryTestUtils;
import org.apache.commons.math4.geometry.euclidean.oned.Cartesian1D;
import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D;
import org.apache.commons.math4.geometry.euclidean.twod.Line;
Expand All @@ -37,11 +38,53 @@
import org.apache.commons.math4.geometry.partitioning.SubHyperplane;
import org.apache.commons.math4.geometry.partitioning.Region.Location;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.numbers.core.Precision;
import org.junit.Assert;
import org.junit.Test;

public class PolygonsSetTest {

@Test
public void testInfiniteLines_twoIntersecting() {
// arrange
Line line1 = new Line(new Cartesian2D(0, 0), new Cartesian2D(1, 1), 1e-10);
Line line2 = new Line(new Cartesian2D(1, -1), new Cartesian2D(0, 0), 1e-10);

List<SubHyperplane<Euclidean2D>> boundaries = new ArrayList<SubHyperplane<Euclidean2D>>();
boundaries.add(line1.wholeHyperplane());
boundaries.add(line2.wholeHyperplane());

// act
PolygonsSet poly = new PolygonsSet(boundaries, 1e-10);

// assert
Assert.assertEquals(1e-10, poly.getTolerance(), Precision.EPSILON);
Assert.assertEquals(Double.POSITIVE_INFINITY, poly.getSize(), 1e-10);
Assert.assertEquals(Double.POSITIVE_INFINITY, poly.getBoundarySize(), 1e-10);
Assert.assertEquals(false, poly.isEmpty());
Assert.assertEquals(false, poly.isFull());
GeometryTestUtils.assertVectorEquals(Cartesian2D.NaN, (Cartesian2D) poly.getBarycenter(), 1e-10);

Cartesian2D[][] vertices = poly.getVertices();
Assert.assertEquals(1, vertices.length);

Cartesian2D[] loop = vertices[0];
Assert.assertEquals(3, loop.length);
Assert.assertEquals(null, loop[0]);
GeometryTestUtils.assertVectorEquals(line2.toSpace(new Cartesian1D(-Float.MAX_VALUE)), loop[1], 1e-10);
GeometryTestUtils.assertVectorEquals(line2.toSpace(new Cartesian1D(Float.MAX_VALUE)), loop[2], 1e-10);

checkPoints(Region.Location.INSIDE, poly, new Cartesian2D[] {
new Cartesian2D(-1, 0),
new Cartesian2D(-Float.MAX_VALUE, Float.MAX_VALUE / 2.0)
});
checkPoints(Region.Location.OUTSIDE, poly, new Cartesian2D[] {
new Cartesian2D(1, 0),
new Cartesian2D(Float.MAX_VALUE, Float.MAX_VALUE / 2.0)
});
checkPoints(Region.Location.BOUNDARY, poly, new Cartesian2D[] { Cartesian2D.ZERO });
}

@Test
public void testSimplyConnected() {
Cartesian2D[][] vertices = new Cartesian2D[][] {
Expand Down

0 comments on commit e52335b

Please sign in to comment.