Using Clipper Offset with PathsD #442
-
Hi, I'm wanting to use clipper offset with double coordinates but I'm not getting the results I'm expecting (jagged) and I think it might possibly be due to truncation of values when they are converted from PathsD to Paths64. Its a bit hard for me to show the results or my code for this but its basically: Clipper2Lib::PathsD paths;
for (const auto &poly : polys)
{
Clipper2Lib::PathD path;
for (const auto &point : poly)
{
path.push_back({point.x, point.y});
}
paths.push_back(path);
}
Clipper2Lib::ClipperOffset co;
co.AddPaths(paths, Clipper2Lib::JoinType::Round, Clipper2Lib::EndType::Polygon);
const auto result = co.Execute(offset);
std::vector< std::vector< InternalVector2dD > > output;
for (const auto &path : result)
{
std::vector< InternalVector2dD > newPoints;
for (const auto &point : path)
{
newPoints.push_back(InternalVector2dD (point.x, point.y));
}
output.push_back(newPoints);
} When I look at the function Hopefully this is enough information for some assistance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Duncan. Yes, you're correct that And looking at this again now, I'm very much inclined toward removing this overloaded method and allowing only So in doing this, |
Beta Was this translation helpful? Give feedback.
Hi Duncan.
Yes, you're correct that
ClipperOffset::AddPaths(const PathsD &p, ...)
doesn't do any scaling and simply truncates to integer values.And looking at this again now, I'm very much inclined toward removing this overloaded method and allowing only
ClipperOffset::AddPaths(const Paths64 &p, ...)
, especially since the result ofClipperOffset::Execute
will always be aPaths64
object. And this would avoid any scaling confusion such as you're experiencing now. Nor should this cause inconvenience, because theClipper::Inflate()
function would still acceptPathsD
objects, and it scales too (defaulting to 2 decimal places). And of course it also de-scales the result.So in doing this,
Clip…