AngusJohnson / Clipper2

Polygon Clipping and Offsetting - C++, C# and Delphi
Boost Software License 1.0
1.46k stars 267 forks source link

Inconsistent truncation between offseting and clipping for pathsD #389

Closed ccoustet closed 1 year ago

ccoustet commented 1 year ago

Hi everyone, My software needs the coordinates to remain consistent between operations.* I tried to apply truncation at the very beginning of my polygon creation (using the same scale/inv_scale process used in InflatePaths).

  const double scale = std::pow(10, precision);

This way offset operations retain full precision (critical with offset=0). The problem is that I just discovered that the clipping process in ClipperD::ClipperD, the one involved in clipping operations, is different: I no longer have a way to early truncate polygons to ensure NULL ops let them unchanged.

  // to optimize scaling / descaling precision
  // set the scale to a power of double's radix (2) (#25)
  scale_ = std::pow(std::numeric_limits<double>::radix, std::ilogb(std::pow(10, precision)) + 1);

I have no problem with either of the two ways to truncate, but I would need the same to be used consistently in any truncation operation in the library.

AngusJohnson commented 1 year ago

Hi again Christophe. Could you please explain what you mean by truncation?

ccoustet commented 1 year ago

Hi Angus,I call truncation the loss of precision resulting of the scaling-unscaling process I apply when creating the polygons.The exact position of the vertices is not so important to me (and cannot be fully preserved anyway). What is important is that, once created, the vertices does not change if they should not, or holes will appear in the final geometry. Dr Christophe Coustet

AngusJohnson commented 1 year ago

OK. Obviously when the offset delta is 0, then the input paths should be returned unchanged. And this already happens if you use ClipperOffset directly. However the InflatePaths function(s) which call ClipperOffset internally aren't doing this, and this is particularly problematic for the float point version since is scaling and descaling etc without otherwise doing anything. Will fix.

AngusJohnson commented 1 year ago

Hopefully fixed now 🤞🙏.