v0.13.1
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
ClipperLib Namespace Reference

Classes

class  Clipper
 
class  ClipperBase
 
class  clipperException
 
class  ClipperOffset
 
struct  DoublePoint
 
class  Int128
 
struct  IntersectNode
 
struct  IntPoint
 
struct  IntRect
 
struct  Join
 
struct  LocalMinimum
 
struct  LocMinSorter
 
struct  OutPt
 
struct  OutRec
 
class  PolyNode
 
class  PolyTree
 
struct  TEdge
 

Typedefs

typedef signed long long cInt
 
typedef signed long long long64
 
typedef unsigned long long ulong64
 
typedef std::vector< IntPointPath
 
typedef std::vector< PathPaths
 
typedef std::vector< PolyNode * > PolyNodes
 
typedef std::vector< OutRec * > PolyOutList
 
typedef std::vector< TEdge * > EdgeList
 
typedef std::vector< Join * > JoinList
 
typedef std::vector< IntersectNode * > IntersectList
 

Enumerations

enum  ClipType { ctIntersection , ctUnion , ctDifference , ctXor }
 
enum  PolyType { ptSubject , ptClip }
 
enum  PolyFillType { pftEvenOdd , pftNonZero , pftPositive , pftNegative }
 
enum  InitOptions { ioReverseSolution = 1 , ioStrictlySimple = 2 , ioPreserveCollinear = 4 }
 
enum  JoinType { jtSquare , jtRound , jtMiter }
 
enum  EndType {
  etClosedPolygon , etClosedLine , etOpenButt , etOpenSquare ,
  etOpenRound
}
 
enum  EdgeSide { esLeft = 1 , esRight = 2 }
 
enum  Direction { dRightToLeft , dLeftToRight }
 
enum  NodeType { ntAny , ntOpen , ntClosed }
 

Functions

Pathoperator<< (Path &poly, const IntPoint &p)
 
Pathsoperator<< (Paths &polys, const Path &p)
 
std::ostream & operator<< (std::ostream &s, const IntPoint &p)
 
std::ostream & operator<< (std::ostream &s, const Path &p)
 
std::ostream & operator<< (std::ostream &s, const Paths &p)
 
bool Orientation (const Path &poly)
 
double Area (const Path &poly)
 
int PointInPolygon (const IntPoint &pt, const Path &path)
 
void SimplifyPolygon (const Path &in_poly, Paths &out_polys, PolyFillType fillType=pftEvenOdd)
 
void SimplifyPolygons (const Paths &in_polys, Paths &out_polys, PolyFillType fillType=pftEvenOdd)
 
void SimplifyPolygons (Paths &polys, PolyFillType fillType=pftEvenOdd)
 
void CleanPolygon (const Path &in_poly, Path &out_poly, double distance=1.415)
 
void CleanPolygon (Path &poly, double distance=1.415)
 
void CleanPolygons (const Paths &in_polys, Paths &out_polys, double distance=1.415)
 
void CleanPolygons (Paths &polys, double distance=1.415)
 
void MinkowskiSum (const Path &pattern, const Path &path, Paths &solution, bool pathIsClosed)
 
void MinkowskiSum (const Path &pattern, const Paths &paths, Paths &solution, bool pathIsClosed)
 
void MinkowskiDiff (const Path &poly1, const Path &poly2, Paths &solution)
 
void PolyTreeToPaths (const PolyTree &polytree, Paths &paths)
 
void ClosedPathsFromPolyTree (const PolyTree &polytree, Paths &paths)
 
void OpenPathsFromPolyTree (PolyTree &polytree, Paths &paths)
 
void ReversePath (Path &p)
 
void ReversePaths (Paths &p)
 
cInt Round (double val)
 
cInt Abs (cInt val)
 
Int128 Int128Mul (long64 lhs, long64 rhs)
 
double Area (const OutPt *op)
 
double Area (const OutRec &outRec)
 
bool PointIsVertex (const IntPoint &Pt, OutPt *pp)
 
int PointInPolygon (const IntPoint &pt, OutPt *op)
 
bool Poly2ContainsPoly1 (OutPt *OutPt1, OutPt *OutPt2)
 
bool SlopesEqual (const TEdge &e1, const TEdge &e2, bool UseFullInt64Range)
 
bool SlopesEqual (const IntPoint pt1, const IntPoint pt2, const IntPoint pt3, bool UseFullInt64Range)
 
bool SlopesEqual (const IntPoint pt1, const IntPoint pt2, const IntPoint pt3, const IntPoint pt4, bool UseFullInt64Range)
 
bool IsHorizontal (TEdge &e)
 
double GetDx (const IntPoint pt1, const IntPoint pt2)
 
void SetDx (TEdge &e)
 
void SwapSides (TEdge &Edge1, TEdge &Edge2)
 
void SwapPolyIndexes (TEdge &Edge1, TEdge &Edge2)
 
cInt TopX (TEdge &edge, const cInt currentY)
 
void IntersectPoint (TEdge &Edge1, TEdge &Edge2, IntPoint &ip)
 
void ReversePolyPtLinks (OutPt *pp)
 
void DisposeOutPts (OutPt *&pp)
 
void InitEdge (TEdge *e, TEdge *eNext, TEdge *ePrev, const IntPoint &Pt)
 
void InitEdge2 (TEdge &e, PolyType Pt)
 
TEdgeRemoveEdge (TEdge *e)
 
void ReverseHorizontal (TEdge &e)
 
void SwapPoints (IntPoint &pt1, IntPoint &pt2)
 
bool GetOverlapSegment (IntPoint pt1a, IntPoint pt1b, IntPoint pt2a, IntPoint pt2b, IntPoint &pt1, IntPoint &pt2)
 
bool FirstIsBottomPt (const OutPt *btmPt1, const OutPt *btmPt2)
 
OutPtGetBottomPt (OutPt *pp)
 
bool Pt2IsBetweenPt1AndPt3 (const IntPoint pt1, const IntPoint pt2, const IntPoint pt3)
 
bool HorzSegmentsOverlap (cInt seg1a, cInt seg1b, cInt seg2a, cInt seg2b)
 
void RangeTest (const IntPoint &Pt, bool &useFullRange)
 
TEdgeFindNextLocMin (TEdge *E)
 
OutRecGetLowermostRec (OutRec *outRec1, OutRec *outRec2)
 
bool OutRec1RightOfOutRec2 (OutRec *outRec1, OutRec *outRec2)
 
bool IsMinima (TEdge *e)
 
bool IsMaxima (TEdge *e, const cInt Y)
 
bool IsIntermediate (TEdge *e, const cInt Y)
 
TEdgeGetMaximaPair (TEdge *e)
 
TEdgeGetMaximaPairEx (TEdge *e)
 
TEdgeGetNextInAEL (TEdge *e, Direction dir)
 
void GetHorzDirection (TEdge &HorzEdge, Direction &Dir, cInt &Left, cInt &Right)
 
bool IntersectListSort (IntersectNode *node1, IntersectNode *node2)
 
bool EdgesAdjacent (const IntersectNode &inode)
 
int PointCount (OutPt *Pts)
 
void SwapIntersectNodes (IntersectNode &int1, IntersectNode &int2)
 
bool E2InsertsBeforeE1 (TEdge &e1, TEdge &e2)
 
bool GetOverlap (const cInt a1, const cInt a2, const cInt b1, const cInt b2, cInt &Left, cInt &Right)
 
void UpdateOutPtIdxs (OutRec &outrec)
 
OutPtDupOutPt (OutPt *outPt, bool InsertAfter)
 
bool JoinHorz (OutPt *op1, OutPt *op1b, OutPt *op2, OutPt *op2b, const IntPoint Pt, bool DiscardLeft)
 
static OutRecParseFirstLeft (OutRec *FirstLeft)
 
DoublePoint GetUnitNormal (const IntPoint &pt1, const IntPoint &pt2)
 
double DistanceSqrd (const IntPoint &pt1, const IntPoint &pt2)
 
double DistanceFromLineSqrd (const IntPoint &pt, const IntPoint &ln1, const IntPoint &ln2)
 
bool SlopesNearCollinear (const IntPoint &pt1, const IntPoint &pt2, const IntPoint &pt3, double distSqrd)
 
bool PointsAreClose (IntPoint pt1, IntPoint pt2, double distSqrd)
 
OutPtExcludeOp (OutPt *op)
 
void Minkowski (const Path &poly, const Path &path, Paths &solution, bool isSum, bool isClosed)
 
void TranslatePath (const Path &input, Path &output, const IntPoint delta)
 
void AddPolyNodeToPaths (const PolyNode &polynode, NodeType nodetype, Paths &paths)
 

Variables

static cInt const loRange = 0x3FFFFFFF
 
static cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL
 
static double const pi = 3.141592653589793238
 
static double const two_pi = pi *2
 
static double const def_arc_tolerance = 0.25
 
static int const Unassigned = -1
 
static int const Skip = -2
 

Typedef Documentation

◆ cInt

typedef signed long long ClipperLib::cInt

Definition at line 77 of file clipper.hpp.

◆ EdgeList

typedef std::vector< TEdge* > ClipperLib::EdgeList

Definition at line 209 of file clipper.hpp.

◆ IntersectList

typedef std::vector< IntersectNode* > ClipperLib::IntersectList

Definition at line 211 of file clipper.hpp.

◆ JoinList

typedef std::vector< Join* > ClipperLib::JoinList

Definition at line 210 of file clipper.hpp.

◆ long64

typedef signed long long ClipperLib::long64

Definition at line 80 of file clipper.hpp.

◆ Path

typedef std::vector< IntPoint > ClipperLib::Path

Definition at line 106 of file clipper.hpp.

◆ Paths

typedef std::vector< Path > ClipperLib::Paths

Definition at line 107 of file clipper.hpp.

◆ PolyNodes

typedef std::vector< PolyNode* > ClipperLib::PolyNodes

Definition at line 134 of file clipper.hpp.

◆ PolyOutList

typedef std::vector< OutRec* > ClipperLib::PolyOutList

Definition at line 208 of file clipper.hpp.

◆ ulong64

typedef unsigned long long ClipperLib::ulong64

Definition at line 81 of file clipper.hpp.

Enumeration Type Documentation

◆ ClipType

Enumerator
ctIntersection 
ctUnion 
ctDifference 
ctXor 

Definition at line 64 of file clipper.hpp.

◆ Direction

Enumerator
dRightToLeft 
dLeftToRight 

Definition at line 57 of file clipper.cpp.

◆ EdgeSide

Enumerator
esLeft 
esRight 

Definition at line 198 of file clipper.hpp.

198{ esLeft = 1, esRight = 2};

◆ EndType

Enumerator
etClosedPolygon 
etClosedLine 
etOpenButt 
etOpenSquare 
etOpenRound 

Definition at line 131 of file clipper.hpp.

◆ InitOptions

Enumerator
ioReverseSolution 
ioStrictlySimple 
ioPreserveCollinear 

Definition at line 129 of file clipper.hpp.

◆ JoinType

Enumerator
jtSquare 
jtRound 
jtMiter 

Definition at line 130 of file clipper.hpp.

◆ NodeType

Enumerator
ntAny 
ntOpen 
ntClosed 

Definition at line 4553 of file clipper.cpp.

◆ PolyFillType

Enumerator
pftEvenOdd 
pftNonZero 
pftPositive 
pftNegative 

Definition at line 70 of file clipper.hpp.

◆ PolyType

Enumerator
ptSubject 
ptClip 

Definition at line 65 of file clipper.hpp.

65{ ptSubject, ptClip };

Function Documentation

◆ Abs()

cInt ClipperLib::Abs ( cInt  val)
inline

Definition at line 143 of file clipper.cpp.

144{
145 return val < 0 ? -val : val;
146}

◆ AddPolyNodeToPaths()

void ClipperLib::AddPolyNodeToPaths ( const PolyNode polynode,
NodeType  nodetype,
Paths paths 
)

Definition at line 4555 of file clipper.cpp.

4556{
4557 bool match = true;
4558 if (nodetype == ntClosed) match = !polynode.IsOpen();
4559 else if (nodetype == ntOpen) return;
4560
4561 if (!polynode.Contour.empty() && match)
4562 paths.push_back(polynode.Contour);
4563 for (int i = 0; i < polynode.ChildCount(); ++i)
4564 AddPolyNodeToPaths(*polynode.Childs[i], nodetype, paths);
4565}
int ChildCount() const
Definition: clipper.cpp:187
bool IsOpen() const
Definition: clipper.cpp:235
FTensor::Index< 'i', SPACE_DIM > i
void AddPolyNodeToPaths(const PolyNode &polynode, NodeType nodetype, Paths &paths)
Definition: clipper.cpp:4555

◆ Area() [1/3]

double ClipperLib::Area ( const OutPt op)

Definition at line 406 of file clipper.cpp.

407{
408 const OutPt *startOp = op;
409 if (!op) return 0;
410 double a = 0;
411 do {
412 a += (double)(op->Prev->Pt.X + op->Pt.X) * (double)(op->Prev->Pt.Y - op->Pt.Y);
413 op = op->Next;
414 } while (op != startOp);
415 return a * 0.5;
416}
constexpr double a

◆ Area() [2/3]

double ClipperLib::Area ( const OutRec outRec)

Definition at line 419 of file clipper.cpp.

420{
421 return Area(outRec.Pts);
422}
double Area(const Path &poly)
Definition: clipper.cpp:391

◆ Area() [3/3]

double ClipperLib::Area ( const Path poly)

Definition at line 391 of file clipper.cpp.

392{
393 int size = (int)poly.size();
394 if (size < 3) return 0;
395
396 double a = 0;
397 for (int i = 0, j = size -1; i < size; ++i)
398 {
399 a += ((double)poly[j].X + poly[i].X) * ((double)poly[j].Y - poly[i].Y);
400 j = i;
401 }
402 return -a * 0.5;
403}
FTensor::Index< 'j', 3 > j

◆ CleanPolygon() [1/2]

void ClipperLib::CleanPolygon ( const Path in_poly,
Path out_poly,
double  distance = 1.415 
)

Definition at line 4383 of file clipper.cpp.

4384{
4385 //distance = proximity in units/pixels below which vertices
4386 //will be stripped. Default ~= sqrt(2).
4387
4388 size_t size = in_poly.size();
4389
4390 if (size == 0)
4391 {
4392 out_poly.clear();
4393 return;
4394 }
4395
4396 OutPt* outPts = new OutPt[size];
4397 for (size_t i = 0; i < size; ++i)
4398 {
4399 outPts[i].Pt = in_poly[i];
4400 outPts[i].Next = &outPts[(i + 1) % size];
4401 outPts[i].Next->Prev = &outPts[i];
4402 outPts[i].Idx = 0;
4403 }
4404
4405 double distSqrd = distance * distance;
4406 OutPt* op = &outPts[0];
4407 while (op->Idx == 0 && op->Next != op->Prev)
4408 {
4409 if (PointsAreClose(op->Pt, op->Prev->Pt, distSqrd))
4410 {
4411 op = ExcludeOp(op);
4412 size--;
4413 }
4414 else if (PointsAreClose(op->Prev->Pt, op->Next->Pt, distSqrd))
4415 {
4416 ExcludeOp(op->Next);
4417 op = ExcludeOp(op);
4418 size -= 2;
4419 }
4420 else if (SlopesNearCollinear(op->Prev->Pt, op->Pt, op->Next->Pt, distSqrd))
4421 {
4422 op = ExcludeOp(op);
4423 size--;
4424 }
4425 else
4426 {
4427 op->Idx = 1;
4428 op = op->Next;
4429 }
4430 }
4431
4432 if (size < 3) size = 0;
4433 out_poly.resize(size);
4434 for (size_t i = 0; i < size; ++i)
4435 {
4436 out_poly[i] = op->Pt;
4437 op = op->Next;
4438 }
4439 delete [] outPts;
4440}
OutPt * ExcludeOp(OutPt *op)
Definition: clipper.cpp:4373
bool PointsAreClose(IntPoint pt1, IntPoint pt2, double distSqrd)
Definition: clipper.cpp:4365
bool SlopesNearCollinear(const IntPoint &pt1, const IntPoint &pt2, const IntPoint &pt3, double distSqrd)
Definition: clipper.cpp:4338

◆ CleanPolygon() [2/2]

void ClipperLib::CleanPolygon ( Path poly,
double  distance = 1.415 
)

Definition at line 4443 of file clipper.cpp.

4444{
4445 CleanPolygon(poly, poly, distance);
4446}
void CleanPolygon(const Path &in_poly, Path &out_poly, double distance=1.415)
Definition: clipper.cpp:4383

◆ CleanPolygons() [1/2]

void ClipperLib::CleanPolygons ( const Paths in_polys,
Paths out_polys,
double  distance = 1.415 
)

Definition at line 4449 of file clipper.cpp.

4450{
4451 out_polys.resize(in_polys.size());
4452 for (Paths::size_type i = 0; i < in_polys.size(); ++i)
4453 CleanPolygon(in_polys[i], out_polys[i], distance);
4454}

◆ CleanPolygons() [2/2]

void ClipperLib::CleanPolygons ( Paths polys,
double  distance = 1.415 
)

Definition at line 4457 of file clipper.cpp.

4458{
4459 CleanPolygons(polys, polys, distance);
4460}
void CleanPolygons(const Paths &in_polys, Paths &out_polys, double distance=1.415)
Definition: clipper.cpp:4449

◆ ClosedPathsFromPolyTree()

void ClipperLib::ClosedPathsFromPolyTree ( const PolyTree polytree,
Paths paths 
)

Definition at line 4576 of file clipper.cpp.

4577{
4578 paths.resize(0);
4579 paths.reserve(polytree.Total());
4580 AddPolyNodeToPaths(polytree, ntClosed, paths);
4581}
int Total() const
Definition: clipper.cpp:170

◆ DisposeOutPts()

void ClipperLib::DisposeOutPts ( OutPt *&  pp)

Definition at line 706 of file clipper.cpp.

707{
708 if (pp == 0) return;
709 pp->Prev->Next = 0;
710 while( pp )
711 {
712 OutPt *tmpPp = pp;
713 pp = pp->Next;
714 delete tmpPp;
715 }
716}

◆ DistanceFromLineSqrd()

double ClipperLib::DistanceFromLineSqrd ( const IntPoint pt,
const IntPoint ln1,
const IntPoint ln2 
)

Definition at line 4321 of file clipper.cpp.

4323{
4324 //The equation of a line in general form (Ax + By + C = 0)
4325 //given 2 points (x,y) & (x,y) is ...
4326 //(y - y)x + (x - x)y + (y - y)x - (x - x)y = 0
4327 //A = (y - y); B = (x - x); C = (y - y)x - (x - x)y
4328 //perpendicular distance of point (x,y) = (Ax + By + C)/Sqrt(A + B)
4329 //see http://en.wikipedia.org/wiki/Perpendicular_distance
4330 double A = double(ln1.Y - ln2.Y);
4331 double B = double(ln2.X - ln1.X);
4332 double C = A * ln1.X + B * ln1.Y;
4333 C = A * pt.X + B * pt.Y - C;
4334 return (C * C) / (A * A + B * B);
4335}
constexpr AssemblyType A
Definition: plastic.cpp:35

◆ DistanceSqrd()

double ClipperLib::DistanceSqrd ( const IntPoint pt1,
const IntPoint pt2 
)
inline

Definition at line 4313 of file clipper.cpp.

4314{
4315 double Dx = ((double)pt1.X - pt2.X);
4316 double dy = ((double)pt1.Y - pt2.Y);
4317 return (Dx*Dx + dy*dy);
4318}

◆ DupOutPt()

OutPt * ClipperLib::DupOutPt ( OutPt outPt,
bool  InsertAfter 
)

Definition at line 3341 of file clipper.cpp.

3342{
3343 OutPt* result = new OutPt;
3344 result->Pt = outPt->Pt;
3345 result->Idx = outPt->Idx;
3346 if (InsertAfter)
3347 {
3348 result->Next = outPt->Next;
3349 result->Prev = outPt;
3350 outPt->Next->Prev = result;
3351 outPt->Next = result;
3352 }
3353 else
3354 {
3355 result->Prev = outPt->Prev;
3356 result->Next = outPt;
3357 outPt->Prev->Next = result;
3358 outPt->Prev = result;
3359 }
3360 return result;
3361}

◆ E2InsertsBeforeE1()

bool ClipperLib::E2InsertsBeforeE1 ( TEdge e1,
TEdge e2 
)
inline

Definition at line 3271 of file clipper.cpp.

3272{
3273 if (e2.Curr.X == e1.Curr.X)
3274 {
3275 if (e2.Top.Y > e1.Top.Y)
3276 return e2.Top.X < TopX(e1, e2.Top.Y);
3277 else return e1.Top.X > TopX(e2, e1.Top.Y);
3278 }
3279 else return e2.Curr.X < e1.Curr.X;
3280}
cInt TopX(TEdge &edge, const cInt currentY)
Definition: clipper.cpp:615
IntPoint Top
Definition: clipper.cpp:69
IntPoint Curr
Definition: clipper.cpp:68

◆ EdgesAdjacent()

bool ClipperLib::EdgesAdjacent ( const IntersectNode inode)
inline

Definition at line 2923 of file clipper.cpp.

2924{
2925 return (inode.Edge1->NextInSEL == inode.Edge2) ||
2926 (inode.Edge1->PrevInSEL == inode.Edge2);
2927}
TEdge * NextInSEL
Definition: clipper.cpp:82
TEdge * PrevInSEL
Definition: clipper.cpp:83

◆ ExcludeOp()

OutPt * ClipperLib::ExcludeOp ( OutPt op)

Definition at line 4373 of file clipper.cpp.

4374{
4375 OutPt* result = op->Prev;
4376 result->Next = op->Next;
4377 op->Next->Prev = result;
4378 result->Idx = 0;
4379 return result;
4380}

◆ FindNextLocMin()

TEdge * ClipperLib::FindNextLocMin ( TEdge E)

Definition at line 911 of file clipper.cpp.

912{
913 for (;;)
914 {
915 while (E->Bot != E->Prev->Bot || E->Curr == E->Top) E = E->Next;
916 if (!IsHorizontal(*E) && !IsHorizontal(*E->Prev)) break;
917 while (IsHorizontal(*E->Prev)) E = E->Prev;
918 TEdge* E2 = E;
919 while (IsHorizontal(*E)) E = E->Next;
920 if (E->Top.Y == E->Prev->Bot.Y) continue; //ie just an intermediate horz.
921 if (E2->Prev->Bot.X < E->Bot.X) E = E2;
922 break;
923 }
924 return E;
925}
bool IsHorizontal(TEdge &e)
Definition: clipper.cpp:578
IntPoint Bot
Definition: clipper.cpp:67

◆ FirstIsBottomPt()

bool ClipperLib::FirstIsBottomPt ( const OutPt btmPt1,
const OutPt btmPt2 
)

Definition at line 798 of file clipper.cpp.

799{
800 OutPt *p = btmPt1->Prev;
801 while ((p->Pt == btmPt1->Pt) && (p != btmPt1)) p = p->Prev;
802 double dx1p = std::fabs(GetDx(btmPt1->Pt, p->Pt));
803 p = btmPt1->Next;
804 while ((p->Pt == btmPt1->Pt) && (p != btmPt1)) p = p->Next;
805 double dx1n = std::fabs(GetDx(btmPt1->Pt, p->Pt));
806
807 p = btmPt2->Prev;
808 while ((p->Pt == btmPt2->Pt) && (p != btmPt2)) p = p->Prev;
809 double dx2p = std::fabs(GetDx(btmPt2->Pt, p->Pt));
810 p = btmPt2->Next;
811 while ((p->Pt == btmPt2->Pt) && (p != btmPt2)) p = p->Next;
812 double dx2n = std::fabs(GetDx(btmPt2->Pt, p->Pt));
813
814 if (std::max(dx1p, dx1n) == std::max(dx2p, dx2n) &&
815 std::min(dx1p, dx1n) == std::min(dx2p, dx2n))
816 return Area(btmPt1) > 0; //if otherwise identical use orientation
817 else
818 return (dx1p >= dx2p && dx1p >= dx2n) || (dx1n >= dx2p && dx1n >= dx2n);
819}
static Index< 'p', 3 > p
double GetDx(const IntPoint pt1, const IntPoint pt2)
Definition: clipper.cpp:584

◆ GetBottomPt()

OutPt * ClipperLib::GetBottomPt ( OutPt pp)

Definition at line 822 of file clipper.cpp.

823{
824 OutPt* dups = 0;
825 OutPt* p = pp->Next;
826 while (p != pp)
827 {
828 if (p->Pt.Y > pp->Pt.Y)
829 {
830 pp = p;
831 dups = 0;
832 }
833 else if (p->Pt.Y == pp->Pt.Y && p->Pt.X <= pp->Pt.X)
834 {
835 if (p->Pt.X < pp->Pt.X)
836 {
837 dups = 0;
838 pp = p;
839 } else
840 {
841 if (p->Next != pp && p->Prev != pp) dups = p;
842 }
843 }
844 p = p->Next;
845 }
846 if (dups)
847 {
848 //there appears to be at least 2 vertices at BottomPt so ...
849 while (dups != p)
850 {
851 if (!FirstIsBottomPt(p, dups)) pp = dups;
852 dups = dups->Next;
853 while (dups->Pt != pp->Pt) dups = dups->Next;
854 }
855 }
856 return pp;
857}
bool FirstIsBottomPt(const OutPt *btmPt1, const OutPt *btmPt2)
Definition: clipper.cpp:798

◆ GetDx()

double ClipperLib::GetDx ( const IntPoint  pt1,
const IntPoint  pt2 
)
inline

Definition at line 584 of file clipper.cpp.

585{
586 return (pt1.Y == pt2.Y) ?
587 HORIZONTAL : (double)(pt2.X - pt1.X) / (pt2.Y - pt1.Y);
588}
#define HORIZONTAL
Definition: clipper.cpp:62

◆ GetHorzDirection()

void ClipperLib::GetHorzDirection ( TEdge HorzEdge,
Direction Dir,
cInt Left,
cInt Right 
)

Definition at line 2610 of file clipper.cpp.

2611{
2612 if (HorzEdge.Bot.X < HorzEdge.Top.X)
2613 {
2614 Left = HorzEdge.Bot.X;
2615 Right = HorzEdge.Top.X;
2616 Dir = dLeftToRight;
2617 } else
2618 {
2619 Left = HorzEdge.Top.X;
2620 Right = HorzEdge.Bot.X;
2621 Dir = dRightToLeft;
2622 }
2623}

◆ GetLowermostRec()

OutRec * ClipperLib::GetLowermostRec ( OutRec outRec1,
OutRec outRec2 
)

Definition at line 2327 of file clipper.cpp.

2328{
2329 //work out which polygon fragment has the correct hole state ...
2330 if (!outRec1->BottomPt)
2331 outRec1->BottomPt = GetBottomPt(outRec1->Pts);
2332 if (!outRec2->BottomPt)
2333 outRec2->BottomPt = GetBottomPt(outRec2->Pts);
2334 OutPt *OutPt1 = outRec1->BottomPt;
2335 OutPt *OutPt2 = outRec2->BottomPt;
2336 if (OutPt1->Pt.Y > OutPt2->Pt.Y) return outRec1;
2337 else if (OutPt1->Pt.Y < OutPt2->Pt.Y) return outRec2;
2338 else if (OutPt1->Pt.X < OutPt2->Pt.X) return outRec1;
2339 else if (OutPt1->Pt.X > OutPt2->Pt.X) return outRec2;
2340 else if (OutPt1->Next == OutPt1) return outRec2;
2341 else if (OutPt2->Next == OutPt2) return outRec1;
2342 else if (FirstIsBottomPt(OutPt1, OutPt2)) return outRec1;
2343 else return outRec2;
2344}
OutPt * GetBottomPt(OutPt *pp)
Definition: clipper.cpp:822

◆ GetMaximaPair()

TEdge * ClipperLib::GetMaximaPair ( TEdge e)

Definition at line 2538 of file clipper.cpp.

2539{
2540 if ((e->Next->Top == e->Top) && !e->Next->NextInLML)
2541 return e->Next;
2542 else if ((e->Prev->Top == e->Top) && !e->Prev->NextInLML)
2543 return e->Prev;
2544 else return 0;
2545}
TEdge * NextInLML
Definition: clipper.cpp:79

◆ GetMaximaPairEx()

TEdge * ClipperLib::GetMaximaPairEx ( TEdge e)

Definition at line 2548 of file clipper.cpp.

2549{
2550 //as GetMaximaPair() but returns 0 if MaxPair isn't in AEL (unless it's horizontal)
2551 TEdge* result = GetMaximaPair(e);
2552 if (result && (result->OutIdx == Skip ||
2553 (result->NextInAEL == result->PrevInAEL && !IsHorizontal(*result)))) return 0;
2554 return result;
2555}
TEdge * GetMaximaPair(TEdge *e)
Definition: clipper.cpp:2538
TEdge * PrevInAEL
Definition: clipper.cpp:81
TEdge * NextInAEL
Definition: clipper.cpp:80

◆ GetNextInAEL()

TEdge * ClipperLib::GetNextInAEL ( TEdge e,
Direction  dir 
)

Definition at line 2604 of file clipper.cpp.

2605{
2606 return dir == dLeftToRight ? e->NextInAEL : e->PrevInAEL;
2607}

◆ GetOverlap()

bool ClipperLib::GetOverlap ( const cInt  a1,
const cInt  a2,
const cInt  b1,
const cInt  b2,
cInt Left,
cInt Right 
)

Definition at line 3283 of file clipper.cpp.

3285{
3286 if (a1 < a2)
3287 {
3288 if (b1 < b2) {Left = std::max(a1,b1); Right = std::min(a2,b2);}
3289 else {Left = std::max(a1,b2); Right = std::min(a2,b1);}
3290 }
3291 else
3292 {
3293 if (b1 < b2) {Left = std::max(a2,b1); Right = std::min(a1,b2);}
3294 else {Left = std::max(a2,b2); Right = std::min(a1,b1);}
3295 }
3296 return Left < Right;
3297}
constexpr double a2
constexpr double a1

◆ GetOverlapSegment()

bool ClipperLib::GetOverlapSegment ( IntPoint  pt1a,
IntPoint  pt1b,
IntPoint  pt2a,
IntPoint  pt2b,
IntPoint pt1,
IntPoint pt2 
)

Definition at line 776 of file clipper.cpp.

778{
779 //precondition: segments are Collinear.
780 if (Abs(pt1a.X - pt1b.X) > Abs(pt1a.Y - pt1b.Y))
781 {
782 if (pt1a.X > pt1b.X) SwapPoints(pt1a, pt1b);
783 if (pt2a.X > pt2b.X) SwapPoints(pt2a, pt2b);
784 if (pt1a.X > pt2a.X) pt1 = pt1a; else pt1 = pt2a;
785 if (pt1b.X < pt2b.X) pt2 = pt1b; else pt2 = pt2b;
786 return pt1.X < pt2.X;
787 } else
788 {
789 if (pt1a.Y < pt1b.Y) SwapPoints(pt1a, pt1b);
790 if (pt2a.Y < pt2b.Y) SwapPoints(pt2a, pt2b);
791 if (pt1a.Y < pt2a.Y) pt1 = pt1a; else pt1 = pt2a;
792 if (pt1b.Y > pt2b.Y) pt2 = pt1b; else pt2 = pt2b;
793 return pt1.Y > pt2.Y;
794 }
795}
cInt Abs(cInt val)
Definition: clipper.cpp:143
void SwapPoints(IntPoint &pt1, IntPoint &pt2)
Definition: clipper.cpp:768

◆ GetUnitNormal()

DoublePoint ClipperLib::GetUnitNormal ( const IntPoint pt1,
const IntPoint pt2 
)

Definition at line 3762 of file clipper.cpp.

3763{
3764 if(pt2.X == pt1.X && pt2.Y == pt1.Y)
3765 return DoublePoint(0, 0);
3766
3767 double Dx = (double)(pt2.X - pt1.X);
3768 double dy = (double)(pt2.Y - pt1.Y);
3769 double f = 1 *1.0/ std::sqrt( Dx*Dx + dy*dy );
3770 Dx *= f;
3771 dy *= f;
3772 return DoublePoint(dy, -Dx);
3773}

◆ HorzSegmentsOverlap()

bool ClipperLib::HorzSegmentsOverlap ( cInt  seg1a,
cInt  seg1b,
cInt  seg2a,
cInt  seg2b 
)

Definition at line 872 of file clipper.cpp.

873{
874 if (seg1a > seg1b) std::swap(seg1a, seg1b);
875 if (seg2a > seg2b) std::swap(seg2a, seg2b);
876 return (seg1a < seg2b) && (seg2a < seg1b);
877}

◆ InitEdge()

void ClipperLib::InitEdge ( TEdge e,
TEdge eNext,
TEdge ePrev,
const IntPoint Pt 
)
inline

Definition at line 719 of file clipper.cpp.

720{
721 std::memset(e, 0, sizeof(TEdge));
722 e->Next = eNext;
723 e->Prev = ePrev;
724 e->Curr = Pt;
725 e->OutIdx = Unassigned;
726}
static int const Unassigned
Definition: clipper.cpp:59

◆ InitEdge2()

void ClipperLib::InitEdge2 ( TEdge e,
PolyType  Pt 
)

Definition at line 729 of file clipper.cpp.

730{
731 if (e.Curr.Y >= e.Next->Curr.Y)
732 {
733 e.Bot = e.Curr;
734 e.Top = e.Next->Curr;
735 } else
736 {
737 e.Top = e.Curr;
738 e.Bot = e.Next->Curr;
739 }
740 SetDx(e);
741 e.PolyTyp = Pt;
742}
void SetDx(TEdge &e)
Definition: clipper.cpp:591
PolyType PolyTyp
Definition: clipper.cpp:71

◆ Int128Mul()

Int128 ClipperLib::Int128Mul ( long64  lhs,
long64  rhs 
)

Definition at line 354 of file clipper.cpp.

355{
356 bool negate = (lhs < 0) != (rhs < 0);
357
358 if (lhs < 0) lhs = -lhs;
359 ulong64 int1Hi = ulong64(lhs) >> 32;
360 ulong64 int1Lo = ulong64(lhs & 0xFFFFFFFF);
361
362 if (rhs < 0) rhs = -rhs;
363 ulong64 int2Hi = ulong64(rhs) >> 32;
364 ulong64 int2Lo = ulong64(rhs & 0xFFFFFFFF);
365
366 //nb: see comments in clipper.pas
367 ulong64 a = int1Hi * int2Hi;
368 ulong64 b = int1Lo * int2Lo;
369 ulong64 c = int1Hi * int2Lo + int1Lo * int2Hi;
370
371 Int128 tmp;
372 tmp.hi = long64(a + (c >> 32));
373 tmp.lo = long64(c << 32);
374 tmp.lo += long64(b);
375 if (tmp.lo < b) tmp.hi++;
376 if (negate) tmp = -tmp;
377 return tmp;
378};
const double c
speed of light (cm/ns)
unsigned long long ulong64
Definition: clipper.hpp:81
signed long long long64
Definition: clipper.hpp:80

◆ IntersectListSort()

bool ClipperLib::IntersectListSort ( IntersectNode node1,
IntersectNode node2 
)

Definition at line 2917 of file clipper.cpp.

2918{
2919 return node2->Pt.Y < node1->Pt.Y;
2920}

◆ IntersectPoint()

void ClipperLib::IntersectPoint ( TEdge Edge1,
TEdge Edge2,
IntPoint ip 
)

Definition at line 622 of file clipper.cpp.

623{
624#ifdef use_xyz
625 ip.Z = 0;
626#endif
627
628 double b1, b2;
629 if (Edge1.Dx == Edge2.Dx)
630 {
631 ip.Y = Edge1.Curr.Y;
632 ip.X = TopX(Edge1, ip.Y);
633 return;
634 }
635 else if (Edge1.Dx == 0)
636 {
637 ip.X = Edge1.Bot.X;
638 if (IsHorizontal(Edge2))
639 ip.Y = Edge2.Bot.Y;
640 else
641 {
642 b2 = Edge2.Bot.Y - (Edge2.Bot.X / Edge2.Dx);
643 ip.Y = Round(ip.X / Edge2.Dx + b2);
644 }
645 }
646 else if (Edge2.Dx == 0)
647 {
648 ip.X = Edge2.Bot.X;
649 if (IsHorizontal(Edge1))
650 ip.Y = Edge1.Bot.Y;
651 else
652 {
653 b1 = Edge1.Bot.Y - (Edge1.Bot.X / Edge1.Dx);
654 ip.Y = Round(ip.X / Edge1.Dx + b1);
655 }
656 }
657 else
658 {
659 b1 = Edge1.Bot.X - Edge1.Bot.Y * Edge1.Dx;
660 b2 = Edge2.Bot.X - Edge2.Bot.Y * Edge2.Dx;
661 double q = (b2-b1) / (Edge1.Dx - Edge2.Dx);
662 ip.Y = Round(q);
663 if (std::fabs(Edge1.Dx) < std::fabs(Edge2.Dx))
664 ip.X = Round(Edge1.Dx * q + b1);
665 else
666 ip.X = Round(Edge2.Dx * q + b2);
667 }
668
669 if (ip.Y < Edge1.Top.Y || ip.Y < Edge2.Top.Y)
670 {
671 if (Edge1.Top.Y > Edge2.Top.Y)
672 ip.Y = Edge1.Top.Y;
673 else
674 ip.Y = Edge2.Top.Y;
675 if (std::fabs(Edge1.Dx) < std::fabs(Edge2.Dx))
676 ip.X = TopX(Edge1, ip.Y);
677 else
678 ip.X = TopX(Edge2, ip.Y);
679 }
680 //finally, don't allow 'ip' to be BELOW curr.Y (ie bottom of scanbeam) ...
681 if (ip.Y > Edge1.Curr.Y)
682 {
683 ip.Y = Edge1.Curr.Y;
684 //use the more vertical edge to derive X ...
685 if (std::fabs(Edge1.Dx) > std::fabs(Edge2.Dx))
686 ip.X = TopX(Edge2, ip.Y); else
687 ip.X = TopX(Edge1, ip.Y);
688 }
689}
cInt Round(double val)
Definition: clipper.cpp:136

◆ IsHorizontal()

bool ClipperLib::IsHorizontal ( TEdge e)
inline

Definition at line 578 of file clipper.cpp.

579{
580 return e.Dx == HORIZONTAL;
581}

◆ IsIntermediate()

bool ClipperLib::IsIntermediate ( TEdge e,
const cInt  Y 
)
inline

Definition at line 2532 of file clipper.cpp.

2533{
2534 return e->Top.Y == Y && e->NextInLML;
2535}

◆ IsMaxima()

bool ClipperLib::IsMaxima ( TEdge e,
const cInt  Y 
)
inline

Definition at line 2526 of file clipper.cpp.

2527{
2528 return e && e->Top.Y == Y && !e->NextInLML;
2529}

◆ IsMinima()

bool ClipperLib::IsMinima ( TEdge e)
inline

Definition at line 2520 of file clipper.cpp.

2521{
2522 return e && (e->Prev->NextInLML != e) && (e->Next->NextInLML != e);
2523}

◆ JoinHorz()

bool ClipperLib::JoinHorz ( OutPt op1,
OutPt op1b,
OutPt op2,
OutPt op2b,
const IntPoint  Pt,
bool  DiscardLeft 
)

Definition at line 3364 of file clipper.cpp.

3366{
3367 Direction Dir1 = (op1->Pt.X > op1b->Pt.X ? dRightToLeft : dLeftToRight);
3368 Direction Dir2 = (op2->Pt.X > op2b->Pt.X ? dRightToLeft : dLeftToRight);
3369 if (Dir1 == Dir2) return false;
3370
3371 //When DiscardLeft, we want Op1b to be on the Left of Op1, otherwise we
3372 //want Op1b to be on the Right. (And likewise with Op2 and Op2b.)
3373 //So, to facilitate this while inserting Op1b and Op2b ...
3374 //when DiscardLeft, make sure we're AT or RIGHT of Pt before adding Op1b,
3375 //otherwise make sure we're AT or LEFT of Pt. (Likewise with Op2b.)
3376 if (Dir1 == dLeftToRight)
3377 {
3378 while (op1->Next->Pt.X <= Pt.X &&
3379 op1->Next->Pt.X >= op1->Pt.X && op1->Next->Pt.Y == Pt.Y)
3380 op1 = op1->Next;
3381 if (DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next;
3382 op1b = DupOutPt(op1, !DiscardLeft);
3383 if (op1b->Pt != Pt)
3384 {
3385 op1 = op1b;
3386 op1->Pt = Pt;
3387 op1b = DupOutPt(op1, !DiscardLeft);
3388 }
3389 }
3390 else
3391 {
3392 while (op1->Next->Pt.X >= Pt.X &&
3393 op1->Next->Pt.X <= op1->Pt.X && op1->Next->Pt.Y == Pt.Y)
3394 op1 = op1->Next;
3395 if (!DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next;
3396 op1b = DupOutPt(op1, DiscardLeft);
3397 if (op1b->Pt != Pt)
3398 {
3399 op1 = op1b;
3400 op1->Pt = Pt;
3401 op1b = DupOutPt(op1, DiscardLeft);
3402 }
3403 }
3404
3405 if (Dir2 == dLeftToRight)
3406 {
3407 while (op2->Next->Pt.X <= Pt.X &&
3408 op2->Next->Pt.X >= op2->Pt.X && op2->Next->Pt.Y == Pt.Y)
3409 op2 = op2->Next;
3410 if (DiscardLeft && (op2->Pt.X != Pt.X)) op2 = op2->Next;
3411 op2b = DupOutPt(op2, !DiscardLeft);
3412 if (op2b->Pt != Pt)
3413 {
3414 op2 = op2b;
3415 op2->Pt = Pt;
3416 op2b = DupOutPt(op2, !DiscardLeft);
3417 };
3418 } else
3419 {
3420 while (op2->Next->Pt.X >= Pt.X &&
3421 op2->Next->Pt.X <= op2->Pt.X && op2->Next->Pt.Y == Pt.Y)
3422 op2 = op2->Next;
3423 if (!DiscardLeft && (op2->Pt.X != Pt.X)) op2 = op2->Next;
3424 op2b = DupOutPt(op2, DiscardLeft);
3425 if (op2b->Pt != Pt)
3426 {
3427 op2 = op2b;
3428 op2->Pt = Pt;
3429 op2b = DupOutPt(op2, DiscardLeft);
3430 };
3431 };
3432
3433 if ((Dir1 == dLeftToRight) == DiscardLeft)
3434 {
3435 op1->Prev = op2;
3436 op2->Next = op1;
3437 op1b->Next = op2b;
3438 op2b->Prev = op1b;
3439 }
3440 else
3441 {
3442 op1->Next = op2;
3443 op2->Prev = op1;
3444 op1b->Prev = op2b;
3445 op2b->Next = op1b;
3446 }
3447 return true;
3448}
OutPt * DupOutPt(OutPt *outPt, bool InsertAfter)
Definition: clipper.cpp:3341

◆ Minkowski()

void ClipperLib::Minkowski ( const Path poly,
const Path path,
Paths solution,
bool  isSum,
bool  isClosed 
)

Definition at line 4463 of file clipper.cpp.

4465{
4466 int delta = (isClosed ? 1 : 0);
4467 size_t polyCnt = poly.size();
4468 size_t pathCnt = path.size();
4469 Paths pp;
4470 pp.reserve(pathCnt);
4471 if (isSum)
4472 for (size_t i = 0; i < pathCnt; ++i)
4473 {
4474 Path p;
4475 p.reserve(polyCnt);
4476 for (size_t j = 0; j < poly.size(); ++j)
4477 p.push_back(IntPoint(path[i].X + poly[j].X, path[i].Y + poly[j].Y));
4478 pp.push_back(p);
4479 }
4480 else
4481 for (size_t i = 0; i < pathCnt; ++i)
4482 {
4483 Path p;
4484 p.reserve(polyCnt);
4485 for (size_t j = 0; j < poly.size(); ++j)
4486 p.push_back(IntPoint(path[i].X - poly[j].X, path[i].Y - poly[j].Y));
4487 pp.push_back(p);
4488 }
4489
4490 solution.clear();
4491 solution.reserve((pathCnt + delta) * (polyCnt + 1));
4492 for (size_t i = 0; i < pathCnt - 1 + delta; ++i)
4493 for (size_t j = 0; j < polyCnt; ++j)
4494 {
4495 Path quad;
4496 quad.reserve(4);
4497 quad.push_back(pp[i % pathCnt][j % polyCnt]);
4498 quad.push_back(pp[(i + 1) % pathCnt][j % polyCnt]);
4499 quad.push_back(pp[(i + 1) % pathCnt][(j + 1) % polyCnt]);
4500 quad.push_back(pp[i % pathCnt][(j + 1) % polyCnt]);
4501 if (!Orientation(quad)) ReversePath(quad);
4502 solution.push_back(quad);
4503 }
4504}
std::vector< Path > Paths
Definition: clipper.hpp:107
bool Orientation(const Path &poly)
Definition: clipper.cpp:385
void ReversePath(Path &p)
Definition: clipper.cpp:4276
std::vector< IntPoint > Path
Definition: clipper.hpp:106
static constexpr double delta

◆ MinkowskiDiff()

void ClipperLib::MinkowskiDiff ( const Path poly1,
const Path poly2,
Paths solution 
)

Definition at line 4544 of file clipper.cpp.

4545{
4546 Minkowski(poly1, poly2, solution, false, true);
4547 Clipper c;
4548 c.AddPaths(solution, ptSubject, true);
4549 c.Execute(ctUnion, solution, pftNonZero, pftNonZero);
4550}
void Minkowski(const Path &poly, const Path &path, Paths &solution, bool isSum, bool isClosed)
Definition: clipper.cpp:4463

◆ MinkowskiSum() [1/2]

void ClipperLib::MinkowskiSum ( const Path pattern,
const Path path,
Paths solution,
bool  pathIsClosed 
)

Definition at line 4507 of file clipper.cpp.

4508{
4509 Minkowski(pattern, path, solution, true, pathIsClosed);
4510 Clipper c;
4511 c.AddPaths(solution, ptSubject, true);
4512 c.Execute(ctUnion, solution, pftNonZero, pftNonZero);
4513}

◆ MinkowskiSum() [2/2]

void ClipperLib::MinkowskiSum ( const Path pattern,
const Paths paths,
Paths solution,
bool  pathIsClosed 
)

Definition at line 4525 of file clipper.cpp.

4526{
4527 Clipper c;
4528 for (size_t i = 0; i < paths.size(); ++i)
4529 {
4530 Paths tmp;
4531 Minkowski(pattern, paths[i], tmp, true, pathIsClosed);
4532 c.AddPaths(tmp, ptSubject, true);
4533 if (pathIsClosed)
4534 {
4535 Path tmp2;
4536 TranslatePath(paths[i], tmp2, pattern[0]);
4537 c.AddPath(tmp2, ptClip, true);
4538 }
4539 }
4540 c.Execute(ctUnion, solution, pftNonZero, pftNonZero);
4541}
void TranslatePath(const Path &input, Path &output, const IntPoint delta)
Definition: clipper.cpp:4516

◆ OpenPathsFromPolyTree()

void ClipperLib::OpenPathsFromPolyTree ( PolyTree polytree,
Paths paths 
)

Definition at line 4584 of file clipper.cpp.

4585{
4586 paths.resize(0);
4587 paths.reserve(polytree.Total());
4588 //Open paths are top level only, so ...
4589 for (int i = 0; i < polytree.ChildCount(); ++i)
4590 if (polytree.Childs[i]->IsOpen())
4591 paths.push_back(polytree.Childs[i]->Contour);
4592}

◆ operator<<() [1/5]

Path & ClipperLib::operator<< ( Path poly,
const IntPoint p 
)
inline

Definition at line 109 of file clipper.hpp.

109{poly.push_back(p); return poly;}

◆ operator<<() [2/5]

Paths & ClipperLib::operator<< ( Paths polys,
const Path p 
)
inline

Definition at line 110 of file clipper.hpp.

110{polys.push_back(p); return polys;}

◆ operator<<() [3/5]

std::ostream & ClipperLib::operator<< ( std::ostream &  s,
const IntPoint p 
)

Definition at line 4595 of file clipper.cpp.

4596{
4597 s << "(" << p.X << "," << p.Y << ")";
4598 return s;
4599}

◆ operator<<() [4/5]

std::ostream & ClipperLib::operator<< ( std::ostream &  s,
const Path p 
)

Definition at line 4602 of file clipper.cpp.

4603{
4604 if (p.empty()) return s;
4605 Path::size_type last = p.size() -1;
4606 for (Path::size_type i = 0; i < last; i++)
4607 s << "(" << p[i].X << "," << p[i].Y << "), ";
4608 s << "(" << p[last].X << "," << p[last].Y << ")\n";
4609 return s;
4610}

◆ operator<<() [5/5]

std::ostream & ClipperLib::operator<< ( std::ostream &  s,
const Paths p 
)

Definition at line 4613 of file clipper.cpp.

4614{
4615 for (Paths::size_type i = 0; i < p.size(); i++)
4616 s << p[i];
4617 s << "\n";
4618 return s;
4619}

◆ Orientation()

bool ClipperLib::Orientation ( const Path poly)

Definition at line 385 of file clipper.cpp.

386{
387 return Area(poly) >= 0;
388}

◆ OutRec1RightOfOutRec2()

bool ClipperLib::OutRec1RightOfOutRec2 ( OutRec outRec1,
OutRec outRec2 
)

Definition at line 2347 of file clipper.cpp.

2348{
2349 do
2350 {
2351 outRec1 = outRec1->FirstLeft;
2352 if (outRec1 == outRec2) return true;
2353 } while (outRec1);
2354 return false;
2355}
OutRec * FirstLeft
Definition: clipper.cpp:106

◆ ParseFirstLeft()

static OutRec * ClipperLib::ParseFirstLeft ( OutRec FirstLeft)
static

Definition at line 3610 of file clipper.cpp.

3611{
3612 while (FirstLeft && !FirstLeft->Pts)
3613 FirstLeft = FirstLeft->FirstLeft;
3614 return FirstLeft;
3615}

◆ PointCount()

int ClipperLib::PointCount ( OutPt Pts)

Definition at line 3177 of file clipper.cpp.

3178{
3179 if (!Pts) return 0;
3180 int result = 0;
3181 OutPt* p = Pts;
3182 do
3183 {
3184 result++;
3185 p = p->Next;
3186 }
3187 while (p != Pts);
3188 return result;
3189}

◆ PointInPolygon() [1/2]

int ClipperLib::PointInPolygon ( const IntPoint pt,
const Path path 
)

Definition at line 440 of file clipper.cpp.

441{
442 //returns 0 if false, +1 if true, -1 if pt ON polygon boundary
443 int result = 0;
444 size_t cnt = path.size();
445 if (cnt < 3) return 0;
446 IntPoint ip = path[0];
447 for(size_t i = 1; i <= cnt; ++i)
448 {
449 IntPoint ipNext = (i == cnt ? path[0] : path[i]);
450 if (ipNext.Y == pt.Y)
451 {
452 if ((ipNext.X == pt.X) || (ip.Y == pt.Y &&
453 ((ipNext.X > pt.X) == (ip.X < pt.X)))) return -1;
454 }
455 if ((ip.Y < pt.Y) != (ipNext.Y < pt.Y))
456 {
457 if (ip.X >= pt.X)
458 {
459 if (ipNext.X > pt.X) result = 1 - result;
460 else
461 {
462 double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) -
463 (double)(ipNext.X - pt.X) * (ip.Y - pt.Y);
464 if (!d) return -1;
465 if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result;
466 }
467 } else
468 {
469 if (ipNext.X > pt.X)
470 {
471 double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) -
472 (double)(ipNext.X - pt.X) * (ip.Y - pt.Y);
473 if (!d) return -1;
474 if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result;
475 }
476 }
477 }
478 ip = ipNext;
479 }
480 return result;
481}
const Tensor1_Expr< const dTensor0< T, Dim, i >, typename promote< T, double >::V, Dim, i > d(const Tensor0< T * > &a, const Index< i, Dim > index, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: dTensor0.hpp:27

◆ PointInPolygon() [2/2]

int ClipperLib::PointInPolygon ( const IntPoint pt,
OutPt op 
)

Definition at line 484 of file clipper.cpp.

485{
486 //returns 0 if false, +1 if true, -1 if pt ON polygon boundary
487 int result = 0;
488 OutPt* startOp = op;
489 for(;;)
490 {
491 if (op->Next->Pt.Y == pt.Y)
492 {
493 if ((op->Next->Pt.X == pt.X) || (op->Pt.Y == pt.Y &&
494 ((op->Next->Pt.X > pt.X) == (op->Pt.X < pt.X)))) return -1;
495 }
496 if ((op->Pt.Y < pt.Y) != (op->Next->Pt.Y < pt.Y))
497 {
498 if (op->Pt.X >= pt.X)
499 {
500 if (op->Next->Pt.X > pt.X) result = 1 - result;
501 else
502 {
503 double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) -
504 (double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y);
505 if (!d) return -1;
506 if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result;
507 }
508 } else
509 {
510 if (op->Next->Pt.X > pt.X)
511 {
512 double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) -
513 (double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y);
514 if (!d) return -1;
515 if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result;
516 }
517 }
518 }
519 op = op->Next;
520 if (startOp == op) break;
521 }
522 return result;
523}

◆ PointIsVertex()

bool ClipperLib::PointIsVertex ( const IntPoint Pt,
OutPt pp 
)

Definition at line 425 of file clipper.cpp.

426{
427 OutPt *pp2 = pp;
428 do
429 {
430 if (pp2->Pt == Pt) return true;
431 pp2 = pp2->Next;
432 }
433 while (pp2 != pp);
434 return false;
435}

◆ PointsAreClose()

bool ClipperLib::PointsAreClose ( IntPoint  pt1,
IntPoint  pt2,
double  distSqrd 
)

Definition at line 4365 of file clipper.cpp.

4366{
4367 double Dx = (double)pt1.X - pt2.X;
4368 double dy = (double)pt1.Y - pt2.Y;
4369 return ((Dx * Dx) + (dy * dy) <= distSqrd);
4370}

◆ Poly2ContainsPoly1()

bool ClipperLib::Poly2ContainsPoly1 ( OutPt OutPt1,
OutPt OutPt2 
)

Definition at line 526 of file clipper.cpp.

527{
528 OutPt* op = OutPt1;
529 do
530 {
531 //nb: PointInPolygon returns 0 if false, +1 if true, -1 if pt on polygon
532 int res = PointInPolygon(op->Pt, OutPt2);
533 if (res >= 0) return res > 0;
534 op = op->Next;
535 }
536 while (op != OutPt1);
537 return true;
538}
int PointInPolygon(const IntPoint &pt, const Path &path)
Definition: clipper.cpp:440

◆ PolyTreeToPaths()

void ClipperLib::PolyTreeToPaths ( const PolyTree polytree,
Paths paths 
)

Definition at line 4568 of file clipper.cpp.

4569{
4570 paths.resize(0);
4571 paths.reserve(polytree.Total());
4572 AddPolyNodeToPaths(polytree, ntAny, paths);
4573}

◆ Pt2IsBetweenPt1AndPt3()

bool ClipperLib::Pt2IsBetweenPt1AndPt3 ( const IntPoint  pt1,
const IntPoint  pt2,
const IntPoint  pt3 
)

Definition at line 860 of file clipper.cpp.

862{
863 if ((pt1 == pt3) || (pt1 == pt2) || (pt3 == pt2))
864 return false;
865 else if (pt1.X != pt3.X)
866 return (pt2.X > pt1.X) == (pt2.X < pt3.X);
867 else
868 return (pt2.Y > pt1.Y) == (pt2.Y < pt3.Y);
869}

◆ RangeTest()

void ClipperLib::RangeTest ( const IntPoint Pt,
bool useFullRange 
)

Definition at line 896 of file clipper.cpp.

897{
898 if (useFullRange)
899 {
900 if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange)
901 throw clipperException("Coordinate outside allowed range");
902 }
903 else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange)
904 {
905 useFullRange = true;
906 RangeTest(Pt, useFullRange);
907 }
908}

◆ RemoveEdge()

TEdge * ClipperLib::RemoveEdge ( TEdge e)

Definition at line 745 of file clipper.cpp.

746{
747 //removes e from double_linked_list (but without removing from memory)
748 e->Prev->Next = e->Next;
749 e->Next->Prev = e->Prev;
750 TEdge* result = e->Next;
751 e->Prev = 0; //flag as removed (see ClipperBase.Clear)
752 return result;
753}

◆ ReverseHorizontal()

void ClipperLib::ReverseHorizontal ( TEdge e)
inline

Definition at line 756 of file clipper.cpp.

757{
758 //swap horizontal edges' Top and Bottom x's so they follow the natural
759 //progression of the bounds - ie so their xbots will align with the
760 //adjoining lower edge. [Helpful in the ProcessHorizontal() method.]
761 std::swap(e.Top.X, e.Bot.X);
762#ifdef use_xyz
763 std::swap(e.Top.Z, e.Bot.Z);
764#endif
765}

◆ ReversePath()

void ClipperLib::ReversePath ( Path p)

Definition at line 4276 of file clipper.cpp.

4277{
4278 std::reverse(p.begin(), p.end());
4279}

◆ ReversePaths()

void ClipperLib::ReversePaths ( Paths p)

Definition at line 4282 of file clipper.cpp.

4283{
4284 for (Paths::size_type i = 0; i < p.size(); ++i)
4285 ReversePath(p[i]);
4286}

◆ ReversePolyPtLinks()

void ClipperLib::ReversePolyPtLinks ( OutPt pp)

Definition at line 692 of file clipper.cpp.

693{
694 if (!pp) return;
695 OutPt *pp1, *pp2;
696 pp1 = pp;
697 do {
698 pp2 = pp1->Next;
699 pp1->Next = pp1->Prev;
700 pp1->Prev = pp2;
701 pp1 = pp2;
702 } while( pp1 != pp );
703}

◆ Round()

cInt ClipperLib::Round ( double  val)
inline

Definition at line 136 of file clipper.cpp.

137{
138 if ((val < 0)) return static_cast<cInt>(val - 0.5);
139 else return static_cast<cInt>(val + 0.5);
140}
signed long long cInt
Definition: clipper.hpp:77

◆ SetDx()

void ClipperLib::SetDx ( TEdge e)
inline

Definition at line 591 of file clipper.cpp.

592{
593 cInt dy = (e.Top.Y - e.Bot.Y);
594 if (dy == 0) e.Dx = HORIZONTAL;
595 else e.Dx = (double)(e.Top.X - e.Bot.X) / dy;
596}

◆ SimplifyPolygon()

void ClipperLib::SimplifyPolygon ( const Path in_poly,
Paths out_polys,
PolyFillType  fillType = pftEvenOdd 
)

Definition at line 4289 of file clipper.cpp.

4290{
4291 Clipper c;
4292 c.StrictlySimple(true);
4293 c.AddPath(in_poly, ptSubject, true);
4294 c.Execute(ctUnion, out_polys, fillType, fillType);
4295}

◆ SimplifyPolygons() [1/2]

void ClipperLib::SimplifyPolygons ( const Paths in_polys,
Paths out_polys,
PolyFillType  fillType = pftEvenOdd 
)

Definition at line 4298 of file clipper.cpp.

4299{
4300 Clipper c;
4301 c.StrictlySimple(true);
4302 c.AddPaths(in_polys, ptSubject, true);
4303 c.Execute(ctUnion, out_polys, fillType, fillType);
4304}

◆ SimplifyPolygons() [2/2]

void ClipperLib::SimplifyPolygons ( Paths polys,
PolyFillType  fillType = pftEvenOdd 
)

Definition at line 4307 of file clipper.cpp.

4308{
4309 SimplifyPolygons(polys, polys, fillType);
4310}
void SimplifyPolygons(const Paths &in_polys, Paths &out_polys, PolyFillType fillType=pftEvenOdd)
Definition: clipper.cpp:4298

◆ SlopesEqual() [1/3]

bool ClipperLib::SlopesEqual ( const IntPoint  pt1,
const IntPoint  pt2,
const IntPoint  pt3,
bool  UseFullInt64Range 
)

Definition at line 554 of file clipper.cpp.

556{
557#ifndef use_int32
558 if (UseFullInt64Range)
559 return Int128Mul(pt1.Y-pt2.Y, pt2.X-pt3.X) == Int128Mul(pt1.X-pt2.X, pt2.Y-pt3.Y);
560 else
561#endif
562 return (pt1.Y-pt2.Y)*(pt2.X-pt3.X) == (pt1.X-pt2.X)*(pt2.Y-pt3.Y);
563}
Int128 Int128Mul(long64 lhs, long64 rhs)
Definition: clipper.cpp:354

◆ SlopesEqual() [2/3]

bool ClipperLib::SlopesEqual ( const IntPoint  pt1,
const IntPoint  pt2,
const IntPoint  pt3,
const IntPoint  pt4,
bool  UseFullInt64Range 
)

Definition at line 566 of file clipper.cpp.

568{
569#ifndef use_int32
570 if (UseFullInt64Range)
571 return Int128Mul(pt1.Y-pt2.Y, pt3.X-pt4.X) == Int128Mul(pt1.X-pt2.X, pt3.Y-pt4.Y);
572 else
573#endif
574 return (pt1.Y-pt2.Y)*(pt3.X-pt4.X) == (pt1.X-pt2.X)*(pt3.Y-pt4.Y);
575}

◆ SlopesEqual() [3/3]

bool ClipperLib::SlopesEqual ( const TEdge e1,
const TEdge e2,
bool  UseFullInt64Range 
)

Definition at line 541 of file clipper.cpp.

542{
543#ifndef use_int32
544 if (UseFullInt64Range)
545 return Int128Mul(e1.Top.Y - e1.Bot.Y, e2.Top.X - e2.Bot.X) ==
546 Int128Mul(e1.Top.X - e1.Bot.X, e2.Top.Y - e2.Bot.Y);
547 else
548#endif
549 return (e1.Top.Y - e1.Bot.Y) * (e2.Top.X - e2.Bot.X) ==
550 (e1.Top.X - e1.Bot.X) * (e2.Top.Y - e2.Bot.Y);
551}

◆ SlopesNearCollinear()

bool ClipperLib::SlopesNearCollinear ( const IntPoint pt1,
const IntPoint pt2,
const IntPoint pt3,
double  distSqrd 
)

Definition at line 4338 of file clipper.cpp.

4340{
4341 //this function is more accurate when the point that's geometrically
4342 //between the other 2 points is the one that's tested for distance.
4343 //ie makes it more likely to pick up 'spikes' ...
4344 if (Abs(pt1.X - pt2.X) > Abs(pt1.Y - pt2.Y))
4345 {
4346 if ((pt1.X > pt2.X) == (pt1.X < pt3.X))
4347 return DistanceFromLineSqrd(pt1, pt2, pt3) < distSqrd;
4348 else if ((pt2.X > pt1.X) == (pt2.X < pt3.X))
4349 return DistanceFromLineSqrd(pt2, pt1, pt3) < distSqrd;
4350 else
4351 return DistanceFromLineSqrd(pt3, pt1, pt2) < distSqrd;
4352 }
4353 else
4354 {
4355 if ((pt1.Y > pt2.Y) == (pt1.Y < pt3.Y))
4356 return DistanceFromLineSqrd(pt1, pt2, pt3) < distSqrd;
4357 else if ((pt2.Y > pt1.Y) == (pt2.Y < pt3.Y))
4358 return DistanceFromLineSqrd(pt2, pt1, pt3) < distSqrd;
4359 else
4360 return DistanceFromLineSqrd(pt3, pt1, pt2) < distSqrd;
4361 }
4362}
double DistanceFromLineSqrd(const IntPoint &pt, const IntPoint &ln1, const IntPoint &ln2)
Definition: clipper.cpp:4321

◆ SwapIntersectNodes()

void ClipperLib::SwapIntersectNodes ( IntersectNode int1,
IntersectNode int2 
)

Definition at line 3258 of file clipper.cpp.

3259{
3260 //just swap the contents (because fIntersectNodes is a single-linked-list)
3261 IntersectNode inode = int1; //gets a copy of Int1
3262 int1.Edge1 = int2.Edge1;
3263 int1.Edge2 = int2.Edge2;
3264 int1.Pt = int2.Pt;
3265 int2.Edge1 = inode.Edge1;
3266 int2.Edge2 = inode.Edge2;
3267 int2.Pt = inode.Pt;
3268}

◆ SwapPoints()

void ClipperLib::SwapPoints ( IntPoint pt1,
IntPoint pt2 
)

Definition at line 768 of file clipper.cpp.

769{
770 IntPoint tmp = pt1;
771 pt1 = pt2;
772 pt2 = tmp;
773}

◆ SwapPolyIndexes()

void ClipperLib::SwapPolyIndexes ( TEdge Edge1,
TEdge Edge2 
)
inline

Definition at line 607 of file clipper.cpp.

608{
609 int OutIdx = Edge1.OutIdx;
610 Edge1.OutIdx = Edge2.OutIdx;
611 Edge2.OutIdx = OutIdx;
612}

◆ SwapSides()

void ClipperLib::SwapSides ( TEdge Edge1,
TEdge Edge2 
)
inline

Definition at line 599 of file clipper.cpp.

600{
601 EdgeSide Side = Edge1.Side;
602 Edge1.Side = Edge2.Side;
603 Edge2.Side = Side;
604}
EdgeSide Side
Definition: clipper.cpp:72

◆ TopX()

cInt ClipperLib::TopX ( TEdge edge,
const cInt  currentY 
)
inline

Definition at line 615 of file clipper.cpp.

616{
617 return ( currentY == edge.Top.Y ) ?
618 edge.Top.X : edge.Bot.X + Round(edge.Dx *(currentY - edge.Bot.Y));
619}

◆ TranslatePath()

void ClipperLib::TranslatePath ( const Path input,
Path output,
const IntPoint  delta 
)

Definition at line 4516 of file clipper.cpp.

4517{
4518 //precondition: input != output
4519 output.resize(input.size());
4520 for (size_t i = 0; i < input.size(); ++i)
4521 output[i] = IntPoint(input[i].X + delta.X, input[i].Y + delta.Y);
4522}

◆ UpdateOutPtIdxs()

void ClipperLib::UpdateOutPtIdxs ( OutRec outrec)
inline

Definition at line 3300 of file clipper.cpp.

3301{
3302 OutPt* op = outrec.Pts;
3303 do
3304 {
3305 op->Idx = outrec.Idx;
3306 op = op->Prev;
3307 }
3308 while(op != outrec.Pts);
3309}

Variable Documentation

◆ def_arc_tolerance

double const ClipperLib::def_arc_tolerance = 0.25
static

Definition at line 55 of file clipper.cpp.

◆ hiRange

cInt const ClipperLib::hiRange = 0x3FFFFFFFFFFFFFFFLL
static

Definition at line 79 of file clipper.hpp.

◆ loRange

cInt const ClipperLib::loRange = 0x3FFFFFFF
static

Definition at line 78 of file clipper.hpp.

◆ pi

double const ClipperLib::pi = 3.141592653589793238
static

Definition at line 53 of file clipper.cpp.

◆ Skip

int const ClipperLib::Skip = -2
static

Definition at line 60 of file clipper.cpp.

◆ two_pi

double const ClipperLib::two_pi = pi *2
static

Definition at line 54 of file clipper.cpp.

◆ Unassigned

int const ClipperLib::Unassigned = -1
static

Definition at line 59 of file clipper.cpp.