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

Improve OffsetCurve to support mitre joins for polygons #1109

Merged
merged 1 commit into from
Jan 7, 2025
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 @@ -208,27 +208,37 @@ public Geometry getCurve() {
public Geometry map(Geometry geom) {
if (geom instanceof Point) return null;
if (geom instanceof Polygon ) {
return toLineString(geom.buffer(distance).getBoundary());
return computePolygonCurve((Polygon) geom, distance);
}
return computeCurve((LineString) geom, distance);
}

/**
* Force LinearRings to be LineStrings.
*
* @param geom a geometry which may be a LinearRing
* @return a geometry which will be a LineString or MultiLineString
*/
private Geometry toLineString(Geometry geom) {
if (geom instanceof LinearRing) {
LinearRing ring = (LinearRing) geom;
return geom.getFactory().createLineString(ring.getCoordinateSequence());
}
return geom;
}
});
}

private Geometry computePolygonCurve(Polygon poly, double distance) {
Geometry buffer;
if (bufferParams == null)
buffer = BufferOp.bufferOp(poly, distance);
else {
buffer = BufferOp.bufferOp(poly, distance, bufferParams);
}
return toLineString(buffer.getBoundary());
}

/**
* Force LinearRings to be LineStrings.
*
* @param geom a linear geometry which may be a LinearRing
* @return a geometry which if linear is a LineString or MultiLineString
*/
private static Geometry toLineString(Geometry geom) {
if (geom instanceof LinearRing) {
LinearRing ring = (LinearRing) geom;
return geom.getFactory().createLineString(ring.getCoordinateSequence());
}
return geom;
}

/**
* Gets the raw offset curve for a line at a given distance.
* The quadrant segments, join style and mitre limit can be specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ public void testMitreJoinNegDistance() {
);
}

public void testPolygonMitreJoin() {
checkOffsetCurve(
"POLYGON ((1 1, 1 7, 5 4, 8 8, 8 1, 1 1))",
1, 0, BufferParameters.JOIN_MITRE, 5,
"LINESTRING (0 0, 0 9, 4.8 5.4, 9 11, 9 0, 0 0)",
0.0001
);
checkOffsetCurve(
"POLYGON ((1 1, 1 7, 5 4, 8 8, 8 1, 1 1))",
-1, 0, BufferParameters.JOIN_MITRE, 5,
"LINESTRING (2 2, 2 5, 5.2 2.6, 7 5, 7 2, 2 2)",
0.0001
);

}
//=======================================

private static final double EQUALS_TOL = 0.05;
Expand Down
Loading