Replies: 1 comment 2 replies
-
This is somewhat complicated so I hope my explanation below makes some sense ... Clipping must be done using integer coordinates to maintain numerical robustness. So the ClipperD class is really just a wrapper around Clipper64, and scales float values in input path coordinates to integer values (and later descales the solution). But there must be a limit to the available precision because integers must fit comfortably inside Int64 (and perform Int64 addition and subtraction without overflow). So in theory at least these scaled integer values could be +/-1 x 1019. However the function in the library that calculates intersections degrades (ie becomes less accurate) when integer values are much greater than +/-1 x 1012. (I could make this function more accurate but doing so significantly slows performance.) So the compromise is to limit the amount of scaling (ie when converting floats to integers) to try and keep integers inside this +/-1 x 1012 range. And there's an undocumented assumption that by limiting the decimal precision to 8 (ie scaling 100,000,000), it's unlikely that integer values will significantly exceed a range where (intersection point calculation) precision becomes significantly compromised. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to understand best practices with Clipper2. My original point data is floating point data. I would like to maximize the precision in my results from Clipper. I generally understand how the precision parameter works with ClipperD -- the default value is 2, the maximum is 8.
Precision = 8 seems to be a limit that is based on some assumption of the magnitude of your double values. However, the scale factor is set before Clipper has received any path data (and therefore can not have checked a bounding box to determine the magnitude of the numbers).
Part of me is tempted to scale my doubles before feeding them into PathsD, but that really seems counter to the way things are supposed to work. If I'm going to scale my numbers, I might as well scale them to +=1e12 and use Clipper64 (right?).
As a user, I expected Clipper to defer scaling my D input until after I was done AddSubject()'ing it (and it could therefore use a bounding box to come up with an appropriate shift and scale). Or allow me to specify the magnitude of numbers I plan on using.
What is the best practice way to obtain maximum precision when dealing with Boolean operations on floating point data?
Thanks again for an outstanding library.
Beta Was this translation helpful? Give feedback.
All reactions