Skip to content

GetLineIntersectPt zeroes Z for intersection points, breaking USINGZ without ZCallback #1065

@Nebukam

Description

@Nebukam

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions