Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vertex-vertex intersection in OverlayArea #1040

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,27 @@ private static double areaForIntersection(Coordinate a0, Coordinate a1, Coordina
* For accuracy the full edge is used to provide the direction vector.
*/
Coordinate intPt = li.getIntersection(0);

boolean isAenteringB = Orientation.COUNTERCLOCKWISE == Orientation.index(a0, a1, b1);

if ( isAenteringB ) {

if ( Orientation.CLOCKWISE == Orientation.index(a0, a1, b0) ) {
if (intPt.equals2D(a1)) {
// Intersection at vertex and A0 -> A1 is outside of the intersection area
// Area will be computed by the segment A1 -> A2
return 0.0;
}
return EdgeVector.area2Term(intPt, a0, a1, true)
+ EdgeVector.area2Term(intPt, b1, b0, false);
}
else {
else if ( Orientation.CLOCKWISE == Orientation.index(a0, a1, b1) ) {
if (intPt.equals2D(a0)) {
// Intersection at vertex and A0 -> A1 is outside of the intersection area
// Area will be computed by the segment A(-1) -> A0
return 0.0;
}
return EdgeVector.area2Term(intPt, a1, a0, false)
+ EdgeVector.area2Term(intPt, b0, b1, true);
}

return 0.0;
}

private double areaForInteriorVertices(LinearRing ring) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,22 @@ private double areaForIntersections(CoordinateSequence ringA, boolean isCCWA, Co
* Use full edge to compute direction, for accuracy.
*/
Coordinate intPt = li.getIntersection(0);

boolean isAenteringB = Orientation.COUNTERCLOCKWISE == Orientation.index(a0, a1, b1);

if ( isAenteringB ) {

if ( Orientation.CLOCKWISE == Orientation.index(a0, a1, b0) ) {
if (intPt.equals2D(a1)) {
// Intersection at vertex and A0 -> A1 is outside of the intersection area
// Area will be computed by the segment A1 -> A2
continue;
}
area += EdgeVector.area2Term(intPt, a0, a1, true);
area += EdgeVector.area2Term(intPt, b1, b0, false);
}
else {
else if ( Orientation.CLOCKWISE == Orientation.index(a0, a1, b1) ) {
if (intPt.equals2D(a0)) {
// Intersection at vertex and A0 -> A1 is outside of the intersection area
// Area will be computed by the segment A(-1) -> A0
continue;
}
area += EdgeVector.area2Term(intPt, a1, a0, false);
area += EdgeVector.area2Term(intPt, b0, b1, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ public void testDisjoint() {
"POLYGON ((10 90, 40 90, 40 60, 10 60, 10 90))",
"POLYGON ((90 10, 50 10, 50 50, 90 50, 90 10))");
}

//TODO: fix this bug
public void xtestTouching() {

public void testTouchingTwoCollinear() {
checkIntersectionArea(
"POLYGON ((10 90, 50 90, 50 50, 10 50, 10 90))",
"POLYGON ((90 10, 50 10, 50 50, 90 50, 90 10))");
}

public void testTouchingOneCollinear() {
checkIntersectionArea(
"POLYGON ((10 90, 50 90, 50 50, 10 50, 10 90))",
"POLYGON ((90 10, 49 10, 50 50, 90 50, 90 10))");
}

public void testTouchingNoneCollinear() {
checkIntersectionArea(
"POLYGON ((10 90, 50 90, 50 50, 10 52, 10 90))",
"POLYGON ((90 10, 49 10, 50 50, 90 50, 90 10))");
}

public void testRectangleAContainsB() {
checkIntersectionArea(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,24 @@ public void testDisjoint() {
"POLYGON ((90 10, 50 10, 50 50, 90 50, 90 10))");
}

//TODO: fix this bug
public void xtestTouching() {
public void testTouchingTwoCollinear() {
checkIntersectionArea(
"POLYGON ((10 90, 50 90, 50 50, 10 50, 10 90))",
"POLYGON ((90 10, 50 10, 50 50, 90 50, 90 10))");
}

public void testTouchingOneCollinear() {
checkIntersectionArea(
"POLYGON ((10 90, 50 90, 50 50, 10 50, 10 90))",
"POLYGON ((90 10, 49 10, 50 50, 90 50, 90 10))");
}

public void testTouchingNoneCollinear() {
checkIntersectionArea(
"POLYGON ((10 90, 50 90, 50 50, 10 52, 10 90))",
"POLYGON ((90 10, 49 10, 50 50, 90 50, 90 10))");
}

public void testRectangleAContainsB() {
checkIntersectionArea(
"POLYGON ((100 300, 300 300, 300 100, 100 100, 100 300))",
Expand Down
Loading