Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions CPP/Clipper2Lib/include/clipper2/clipper.core.h
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,23 @@ namespace Clipper2Lib
ip.y = originy + static_cast<T>(hity);
}
#ifdef USINGZ
ip.z = 0;
// Interpolate Z from ln1 endpoints based on proximity along segment
{
double seg_dx = static_cast<double>(ln1b.x - ln1a.x);
double seg_dy = static_cast<double>(ln1b.y - ln1a.y);
double seg_len_sq = seg_dx * seg_dx + seg_dy * seg_dy;
if (seg_len_sq > 0.0)
{
double pt_dx = static_cast<double>(ip.x - ln1a.x);
double pt_dy = static_cast<double>(ip.y - ln1a.y);
double t_z = (pt_dx * seg_dx + pt_dy * seg_dy) / seg_len_sq;
ip.z = (t_z <= 0.5) ? ln1a.z : ln1b.z;
}
else
{
ip.z = ln1a.z;
}
}
#endif
return true;
}
Expand All @@ -967,7 +983,7 @@ namespace Clipper2Lib
ip.x = static_cast<T>(ln1a.x + t * dx1);
ip.y = static_cast<T>(ln1a.y + t * dy1);
#ifdef USINGZ
ip.z = 0;
ip.z = (t <= 0.5) ? ln1a.z : ln1b.z;
#endif
}
return true;
Expand Down