Skip to content

Commit

Permalink
Fix OffsetCurve EndCap parameter handling (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts authored May 8, 2023
1 parent 711b540 commit afbcf67
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ extern "C" {
{
return execute(extHandle, [&]() {
BufferParameters bp;
bp.setEndCapStyle(BufferParameters::CAP_FLAT);
//-- use default cap style ROUND
bp.setQuadrantSegments(quadsegs);

if(joinStyle > BufferParameters::JOIN_BEVEL) {
Expand Down
5 changes: 4 additions & 1 deletion include/geos/operation/buffer/OffsetCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,16 @@ class GEOS_DLL OffsetCurve {
OffsetCurve(const Geometry& geom, double dist, BufferParameters& bp)
: inputGeom(geom)
, distance(dist)
, bufferParams(bp)
, matchDistance(std::abs(dist)/MATCH_DISTANCE_FACTOR)
, geomFactory(geom.getFactory())
{
if (!std::isfinite(dist)) {
throw util::IllegalArgumentException("OffsetCurve distance must be a finite value");
}
//-- set buffer params, leaving cap style as the default CAP_ROUND
bufferParams.setQuadrantSegments( bp.getQuadrantSegments());
bufferParams.setJoinStyle( bp.getJoinStyle());
bufferParams.setMitreLimit( bp.getMitreLimit());
};

/**
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/capi/GEOSOffsetCurveTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void object::test<5>()
"LINESTRING(33282908 6005055,33282900 6005050,33282892 6005042,33282876 6005007,33282863 6004982,33282866 6004971,33282876 6004975,33282967 6005018,33282999 6005031)",
// Old algorithm
// "LINESTRING EMPTY",
"LINESTRING (33282915.823395286 6005042.482567544, 33282948.754269265 6005058.043310193, 33282949.87329309 6005058.534544426, 33282982.439409934 6005071.764529393)",
"LINESTRING (33282939.63869393 6005053.735950421, 33282948.754269257 6005058.043310191, 33282949.873293087 6005058.534544423, 33282982.439409934 6005071.764529393)",
44, 1, GEOSBUF_JOIN_MITRE, 1,
0.000001
);
Expand Down Expand Up @@ -246,5 +246,19 @@ void object::test<11>()
);
}

// Test negative offset
// See https://github.com/libgeos/geos/issues/897
template<>
template<>
void object::test<12>()
{
checkOffset(
"LINESTRING (292671.05 7336734.42, 292624.85 7336739.72, 292623.53 7336739.92, 292622.36 7336740.2, 292621.35 7336740.57, 292620.94 7336740.78, 292620.61 7336740.97, 292620.33 7336741.14, 292620.13 7336741.29, 292619.79 7336741.57, 292619.48 7336741.86, 292619.34 7336742.01, 292619.21 7336742.17, 292619.09 7336742.34, 292618.98 7336742.51, 292618.8 7336742.88, 292618.63 7336743.25, 292618.57 7336743.43, 292618.52 7336743.58, 292618.48 7336743.71, 292618.46 7336743.8, 292618.44 7336743.98, 292618.42 7336744.15, 292618.41 7336744.33, 292618.4 7336744.51, 292618.39 7336744.69, 292618.38 7336744.88, 292618.38 7336744.91, 292618.38 7336744.95, 292618.38 7336744.99, 292618.38 7336745.02, 292618.38 7336745.06, 292618.38 7336745.1, 292618.38 7336745.13, 292618.38 7336745.17, 292618.38 7336745.21, 292618.38 7336745.25, 292618.38 7336745.43, 292618.41 7336746.92)",
"LINESTRING (292672.7595667329 7336749.322260955, 292631.53009245027 7336754.052049131)",
-15, 8, GEOSBUF_JOIN_ROUND, 0,
0.000001
);
}

} // namespace tut

0 comments on commit afbcf67

Please sign in to comment.