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 buffer optimization for inverted rings #878

Merged
merged 1 commit into from
May 31, 2022
Merged
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 @@ -307,6 +307,7 @@ private void addRingSide(Coordinate[] coord, double offsetDistance, int side, in
}

private static final int MAX_INVERTED_RING_SIZE = 9;
private static final int INVERTED_CURVE_VERTEX_FACTOR = 4;
private static final double NEARNESS_FACTOR = 0.99;

/**
Expand Down Expand Up @@ -344,10 +345,11 @@ private static boolean isRingCurveInverted(Coordinate[] inputPts, double distanc
if (inputPts.length >= MAX_INVERTED_RING_SIZE) return false;

/**
* An inverted curve has no more points than the input ring.
* This also eliminates concave inputs (which will produce fillet arcs)
* Don't check curves which are much larger than the input.
* This improves performance by avoiding checking some concave inputs
* (which can produce fillet arcs with many more vertices)
*/
if (curvePts.length > inputPts.length) return false;
if (curvePts.length > INVERTED_CURVE_VERTEX_FACTOR * inputPts.length) return false;

/**
* Check if the curve vertices are all closer to the input ring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,17 @@ public void testMultiPolygonElementRemoved() {
checkBufferNumGeometries(wkt, -18, 1);
}

/**
* Checks a bug in the inverted-ring-removal heuristic.
* See https://github.com/locationtech/jts/issues/876
*/
public void testLineClosedNoHole() {
String wkt = "LINESTRING (-20 0, 0 20, 20 0, 0 -20, -20 0)";
checkBufferHasHole(wkt, 70, false);
}

//===================================================

private void checkBufferEmpty(String wkt, double dist, boolean isEmptyExpected) {
Geometry a = read(wkt);
Geometry result = a.buffer(dist);
Expand Down