Offset with holes #300
Answered
by
sethhillbrand
sethhillbrand
asked this question in
Q&A
|
Hi Angus and others tldr; the ClipperOffset appears to behave differently in Clipper2 vs Clipper1. Is this intentional and is there a way to simulate the Clipper1 behavior? In Clipper1, if we called ClipperOffset with a negative value, the outline got smaller while the holes got larger In Clipper2, calling ClipperOffset with a negative value, both the outline AND the holes get smaller The code in Clipper1 is ClipperOffset c;
PolyTree solution;
for( const POLYGON& poly : m_polys )
{
for( size_t i = 0; i < poly.size(); i++ )
{
c.AddPath( poly[i].convertToClipper( i == 0, zValues, arcBuffer ),
jtSquare, etClosedPolygon );
}
}
double coeff = 1.0 - cos( M_PI / aCircleSegCount );
c.ArcTolerance = std::abs( aAmount ) * coeff;
c.MiterLimit = 2.0;
c.MiterFallback = miterFallback;
c.Execute( solution, aAmount );In Clipper2, the code is: ClipperOffset c;
for( const POLYGON& poly : m_polys )
{
for( size_t i = 0; i < poly.size(); i++ )
{
c.AddPath( poly[i].convertToClipper2( i == 0, zValues, arcBuffer ),
JoinType::Square, EndType::Polygon );
}
}
double coeff = 1.0 - cos( M_PI / aCircleSegCount );
c.ArcTolerance = std::abs( aAmount ) * coeff;
c.MiterLimit = 2.0;
c.MiterFallback = miterFallback;
Paths64 solution = c.Execute( aAmount ); |
Answered by
sethhillbrand
Oct 28, 2022
Replies: 2 comments
|
I'm going to answer my own question here. Just took some searching. In Clipper2, we can't be as loose with adding holes. They need to be grouped with a specific path. So, changing the Clipper2 code to the following seems to work. for( const POLYGON& poly : m_polys )
{
Paths64 paths;
for( size_t i = 0; i < poly.size(); i++ )
paths.push_back( poly[i].convertToClipper2( i == 0, zValues, arcBuffer ) );
c.AddPaths( paths, joinType, EndType::Polygon );
} |
0 replies
Answer selected by
sethhillbrand
|
Yes, run ok in C# too. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


I'm going to answer my own question here. Just took some searching.
In Clipper2, we can't be as loose with adding holes. They need to be grouped with a specific path. So, changing the Clipper2 code to the following seems to work.