ClipperLib: Optimized PointInPolygon() to calculate cross products
with int64s instead of doubles. Polygon / ExPolygon: contains() reworked to use ClipperLib::PointInPolygon(). The Slic3r own implementation was not robust. Fixed test_perimeters after recent refactoring (sorting of extrusions into LayerIslands)
This commit is contained in:
parent
5eaec515ba
commit
9dca8403fe
8 changed files with 37 additions and 38 deletions
|
@ -225,7 +225,7 @@ int PointInPolygon(const IntPoint &pt, const Path &path)
|
|||
if (ipNext.x() > pt.x()) result = 1 - result;
|
||||
else
|
||||
{
|
||||
double d = (double)(ip.x() - pt.x()) * (ipNext.y() - pt.y()) - (double)(ipNext.x() - pt.x()) * (ip.y() - pt.y());
|
||||
auto d = CrossProductType(ip.x() - pt.x()) * CrossProductType(ipNext.y() - pt.y()) - CrossProductType(ipNext.x() - pt.x()) * CrossProductType(ip.y() - pt.y());
|
||||
if (!d) return -1;
|
||||
if ((d > 0) == (ipNext.y() > ip.y())) result = 1 - result;
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ int PointInPolygon(const IntPoint &pt, const Path &path)
|
|||
{
|
||||
if (ipNext.x() > pt.x())
|
||||
{
|
||||
double d = (double)(ip.x() - pt.x()) * (ipNext.y() - pt.y()) - (double)(ipNext.x() - pt.x()) * (ip.y() - pt.y());
|
||||
auto d = CrossProductType(ip.x() - pt.x()) * CrossProductType(ipNext.y() - pt.y()) - CrossProductType(ipNext.x() - pt.x()) * CrossProductType(ip.y() - pt.y());
|
||||
if (!d) return -1;
|
||||
if ((d > 0) == (ipNext.y() > ip.y())) result = 1 - result;
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ int PointInPolygon(const IntPoint &pt, const Path &path)
|
|||
//------------------------------------------------------------------------------
|
||||
|
||||
// Called by Poly2ContainsPoly1()
|
||||
int PointInPolygon (const IntPoint &pt, OutPt *op)
|
||||
int PointInPolygon(const IntPoint &pt, OutPt *op)
|
||||
{
|
||||
//returns 0 if false, +1 if true, -1 if pt ON polygon boundary
|
||||
int result = 0;
|
||||
|
@ -265,7 +265,7 @@ int PointInPolygon (const IntPoint &pt, OutPt *op)
|
|||
if (op->Next->Pt.x() > pt.x()) result = 1 - result;
|
||||
else
|
||||
{
|
||||
double d = (double)(op->Pt.x() - pt.x()) * (op->Next->Pt.y() - pt.y()) - (double)(op->Next->Pt.x() - pt.x()) * (op->Pt.y() - pt.y());
|
||||
auto d = CrossProductType(op->Pt.x() - pt.x()) * CrossProductType(op->Next->Pt.y() - pt.y()) - CrossProductType(op->Next->Pt.x() - pt.x()) * CrossProductType(op->Pt.y() - pt.y());
|
||||
if (!d) return -1;
|
||||
if ((d > 0) == (op->Next->Pt.y() > op->Pt.y())) result = 1 - result;
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ int PointInPolygon (const IntPoint &pt, OutPt *op)
|
|||
{
|
||||
if (op->Next->Pt.x() > pt.x())
|
||||
{
|
||||
double d = (double)(op->Pt.x() - pt.x()) * (op->Next->Pt.y() - pt.y()) - (double)(op->Next->Pt.x() - pt.x()) * (op->Pt.y() - pt.y());
|
||||
auto d = CrossProductType(op->Pt.x() - pt.x()) * CrossProductType(op->Next->Pt.y() - pt.y()) - CrossProductType(op->Next->Pt.x() - pt.x()) * CrossProductType(op->Pt.y() - pt.y());
|
||||
if (!d) return -1;
|
||||
if ((d > 0) == (op->Next->Pt.y() > op->Pt.y())) result = 1 - result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue