Clipper2 scale, what is the right value to use? #419
Replies: 3 comments
|
Hi Petras.
Could you please explain what you mean by failures. Anhow, the following seems to work as expected: |
|
The problem was that I was trying adding points to Clipper64 and Path64 that rounds up to integer. In that case ScalePaths functions does not have affect since points have already been added with rounded values. I changed to the code PathsD and ClipperD: Clipper2Lib::PathsD clipper_plate_outlines;
clipper_plate_outlines.emplace_back(std::vector<Clipper2Lib::PointD>());
clipper_plate_outlines.back().reserve(plate_outline.size() - 1);
for (int i = 0; i < plate_outline.size() - 1; i++)
clipper_plate_outlines.back().emplace_back((plate_outline[i].x()), (plate_outline[i].y()));
When using ClipperD, should I scale paths or Clipper is handling the scaling internally? |
|
Hi again Petras. I'm afraid It's not clear to me what you're asking. |

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I have a question related to the tolerance when converting double values to Clipper integer values.
I can maximally scale points 1e8 times and sometimes get failures with this tolerance, so I use 1e6 or 1e7.
The points coordinates are not large they are between -1000 and 1000 units.
Is the code what I am doing wrote is correct regarding the logic of scaling?
I have a feeling that in Clipper1 the tolerance of scale was bigger:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Here the scale factor is taken by measuring the maximum coordinate value ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// double max_coordinate = 0; for (int i = 0; i < joint_outline.size() - 1; i++) // plate { // translation_vector += joint_outline[i]; if (max_coordinate < std::abs(joint_outline[i].hx())) max_coordinate = std::abs(joint_outline[i].hx()); if (max_coordinate < std::abs(joint_outline[i].hy())) max_coordinate = std::abs(joint_outline[i].hy()); } for (int i = 0; i < plate_outline.size() - 1; i++) // joint { // translation_vector += plate_outline[i]; if (max_coordinate < std::abs(plate_outline[i].hx())) max_coordinate = std::abs(plate_outline[i].hx()); if (max_coordinate < std::abs(plate_outline[i].hy())) max_coordinate = std::abs(plate_outline[i].hy()); } double scale = std::pow(10, 8 - cgal_math_util::count_digits(std::ceil(max_coordinate))); ///////////////////////////////////////////////////////////////////////////////////// // Convert to Clipper ///////////////////////////////////////////////////////////////////////////////////// Clipper2Lib::Paths64 clipper_plate_outlines; clipper_plate_outlines.emplace_back(std::vector<Clipper2Lib::Point64>()); clipper_plate_outlines.back().reserve(plate_outline.size() - 1); Clipper2Lib::Paths64 clipper_joint_outlines; clipper_joint_outlines.emplace_back(std::vector<Clipper2Lib::Point64>()); clipper_joint_outlines.back().reserve(joint_outline.size()); for (int i = 0; i < plate_outline.size() - 1; i++) // this outline has no duplicate end point because it is "closed path" clipper_plate_outlines.back().emplace_back((int)(plate_outline[i].x() * scale), (int)(plate_outline[i].y() * scale)); for (int i = 0; i < joint_outline.size(); i++) // this outline has duplicate end points because it is "open path" clipper_joint_outlines.back().emplace_back((int)(joint_outline[i].x() * scale), (int)(joint_outline[i].y() * scale)); // https://github.com/AngusJohnson/Clipper2/blob/main/CPP/Clipper2Lib/include/clipper2/clipper.h Clipper2Lib::Paths64 clipper_result_closed; Clipper2Lib::Paths64 clipper_result_open; Clipper2Lib::Clipper64 clipper; clipper.AddOpenSubject(clipper_joint_outlines); clipper.AddClip(clipper_plate_outlines); clipper.Execute(Clipper2Lib::ClipType::Intersection, Clipper2Lib::FillRule::NonZero, clipper_result_closed, clipper_result_open);All reactions