Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed Clipper library (our own fork of it) when working with Z coordinate #7180

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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
30 changes: 23 additions & 7 deletions src/clipper/clipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ inline cInt Round(double val)
return static_cast<cInt>((val < 0) ? (val - 0.5) : (val + 0.5));
}

// Overriding the Eigen operators because we don't want to compare Z coordinate if IntPoint is 3 dimensional.
inline bool operator==(const IntPoint &l, const IntPoint &r) { return l.x() == r.x() && l.y() == r.y(); }
inline bool operator!=(const IntPoint &l, const IntPoint &r) { return l.x() != r.x() || l.y() != r.y(); }

//------------------------------------------------------------------------------
// PolyTree methods ...
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -189,19 +193,25 @@ double Area(const Path &poly)
}
//------------------------------------------------------------------------------

double Area(const OutRec &outRec)
double Area(const OutPt *op)
{
OutPt *op = outRec.Pts;
const OutPt *startOp = op;
if (!op) return 0;
double a = 0;
do {
a += (double)(op->Prev->Pt.x() + op->Pt.x()) * (double)(op->Prev->Pt.y() - op->Pt.y());
op = op->Next;
} while (op != outRec.Pts);
} while (op != startOp);
return a * 0.5;
}
//------------------------------------------------------------------------------

double Area(const OutRec &outRec)
{
return Area(outRec.Pts);
}
//------------------------------------------------------------------------------

bool PointIsVertex(const IntPoint &Pt, OutPt *pp)
{
OutPt *pp2 = pp;
Expand Down Expand Up @@ -536,27 +546,32 @@ bool FirstIsBottomPt(const OutPt* btmPt1, const OutPt* btmPt2)
p = btmPt2->Next;
while ((p->Pt == btmPt2->Pt) && (p != btmPt2)) p = p->Next;
double dx2n = std::fabs(GetDx(btmPt2->Pt, p->Pt));
return (dx1p >= dx2p && dx1p >= dx2n) || (dx1n >= dx2p && dx1n >= dx2n);

if (std::max(dx1p, dx1n) == std::max(dx2p, dx2n) &&
std::min(dx1p, dx1n) == std::min(dx2p, dx2n))
return Area(btmPt1) > 0; //if otherwise identical use orientation
else
return (dx1p >= dx2p && dx1p >= dx2n) || (dx1n >= dx2p && dx1n >= dx2n);
}
//------------------------------------------------------------------------------

// Called by GetLowermostRec()
OutPt* GetBottomPt(OutPt *pp)
{
OutPt* dups = 0;
OutPt* dups = nullptr;
OutPt* p = pp->Next;
while (p != pp)
{
if (p->Pt.y() > pp->Pt.y())
{
pp = p;
dups = 0;
dups = nullptr;
}
else if (p->Pt.y() == pp->Pt.y() && p->Pt.x() <= pp->Pt.x())
{
if (p->Pt.x() < pp->Pt.x())
{
dups = 0;
dups = nullptr;
pp = p;
} else
{
Expand All @@ -577,6 +592,7 @@ OutPt* GetBottomPt(OutPt *pp)
}
return pp;
}

//------------------------------------------------------------------------------

bool Pt2IsBetweenPt1AndPt3(const IntPoint &pt1,
Expand Down