-
Notifications
You must be signed in to change notification settings - Fork 391
Description
Problem
When USINGZ is enabled, GetLineIntersectPt in clipper.core.h sets ip.z = 0 for true intersection points (where the intersection falls strictly between the segment endpoints).
This is fine for the main Clipper engine which calls ZCallback immediately after to let users fill in Z. But several code paths call GetLineIntersectPt without a subsequent ZCallback:
- RectClip64 / RectClipLines64
- DoSquare in offset operations
In these cases, the Z data stored by the user on the input points is permanently lost with no way to recover it.
Impact
Any user relying on Z to carry metadata (point indices, source IDs, custom data) through RectClip or offset operations will silently get z = 0 on every intersection point. The only workaround today is to manually match output points back to source edges by X/Y coordinates after the operation, which is fragile and expensive.
Proposed Fix
Instead of ip.z = 0, pick the nearer endpoint's Z value based on the parameter t along the segment:
ip.z = (t <= 0.5) ? ln1a.z : ln1b.z;
Hopefully this is a reasonable default :D
The intersection point inherits Z from whichever endpoint it's closer to. For the main Clipper engine this value is immediately overwritten by ZCallback anyway, so there's no behavioral change for existing users. But for RectClip and other paths without a callback, it provides a usable approximation instead of data loss.
PR: #1064