8000 Fix OffsetCurve to use a minimum QuadrantSegs value by dr-jts · Pull Request #981 · locationtech/jts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix OffsetCurve to use a minimum QuadrantSegs value #981

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

Merged
merged 2 commits into from
May 26, 2023
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
8000
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public class OffsetCurve {
* The nearness tolerance for matching the the raw offset linework and the buffer curve.
*/
private static final int MATCH_DISTANCE_FACTOR = 10000;

/**
* A QuadSegs minimum value that will prevent generating
* unwanted offset curve artifacts near end caps.
*/
private static final int MIN_QUADRANT_SEGMENTS = 8;

/**
* Computes the offset curve of a geometry at a given distance.
Expand Down Expand Up @@ -164,7 +170,15 @@ public OffsetCurve(Geometry geom, double distance, BufferParameters bufParams) {
//-- make new buffer params since the end cap style must be the default
this.bufferParams = new BufferParameters();
if (bufParams != null) {
bufferParams.setQuadrantSegments(bufParams.getQuadrantSegments());
/**
* Prevent using a very small QuadSegs value, to avoid
* offset curve artifacts near the end caps.
*/
int quadSegs = bufParams.getQuadrantSegments();
if (quadSegs < MIN_QUADRANT_SEGMENTS) {
quadSegs = MIN_QUADRANT_SEGMENTS;
}
bufferParams.setQuadrantSegments(quadSegs);
bufferParams.setJoinStyle(bufParams.getJoinStyle());
bufferParams.setMitreLimit(bufParams.getMitreLimit());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ public void testInfiniteLoop() {
public void testQuadSegs() {
checkOffsetCurve(
"LINESTRING (20 20, 50 50, 80 20)",
10, 2, -1, -1,
"LINESTRING (12.93 27.07, 42.93 57.07, 50 60, 57.07 57.07, 87.07 27.07)"
10, 10, -1, -1,
"LINESTRING (12.93 27.07, 42.93 57.07, 44.12 58.09, 45.46 58.91, 46.91 59.51, 48.44 59.88, 50 60, 51.56 59.88, 53.09 59.51, 54.54 58.91, 55.88 58.09, 57.07 57.07, 87.07 27.07)"
);
}

Expand All @@ -319,6 +319,24 @@ public void testJoinMitre() {
);
}

// See https://github.com/qgis/QGIS/issues/53165
public void testMinQuadrantSegments() {
checkOffsetCurve(
"LINESTRING (553772.0645892698 177770.05079236583, 553780.9235869241 177768.99614978794, 553781.8325485934 177768.41771963477)",
-11, 0, BufferParameters.JOIN_MITRE, -1,
"LINESTRING (553770.76 177759.13, 553777.54 177758.32)"
);
}

// See https://github.com/qgis/QGIS/issues/53165#issuecomment-1563214857
public void testMinQuadrantSegments_QGIS() {
checkOffsetCurve(
"LINESTRING (421 622, 446 625, 449 627)",
133, 0, BufferParameters.JOIN_MITRE, -1,
"LINESTRING (405.15 754.05, 416.3 755.39)"
);
}

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

private static final double EQUALS_TOL = 0.05;
Expand Down
0