2013-05-26 04:36:44 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* *
|
|
|
|
* Author : Angus Johnson *
|
2015-11-02 12:45:33 +00:00
|
|
|
* Version : 6.4.0 *
|
|
|
|
* Date : 2 July 2015 *
|
2013-05-26 04:36:44 +00:00
|
|
|
* Website : http://www.angusj.com *
|
2015-11-02 12:45:33 +00:00
|
|
|
* Copyright : Angus Johnson 2010-2015 *
|
2013-05-26 04:36:44 +00:00
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* Use, modification & distribution is subject to Boost Software License Ver 1. *
|
|
|
|
* http://www.boost.org/LICENSE_1_0.txt *
|
|
|
|
* *
|
|
|
|
* Attributions: *
|
|
|
|
* The code in this library is an extension of Bala Vatti's clipping algorithm: *
|
|
|
|
* "A generic solution to polygon clipping" *
|
|
|
|
* Communications of the ACM, Vol 35, Issue 7 (July 1992) pp 56-63. *
|
|
|
|
* http://portal.acm.org/citation.cfm?id=129906 *
|
|
|
|
* *
|
|
|
|
* Computer graphics and geometric modeling: implementation and algorithms *
|
|
|
|
* By Max K. Agoston *
|
|
|
|
* Springer; 1 edition (January 4, 2005) *
|
|
|
|
* http://books.google.com/books?q=vatti+clipping+agoston *
|
|
|
|
* *
|
|
|
|
* See also: *
|
|
|
|
* "Polygon Offsetting by Computing Winding Numbers" *
|
|
|
|
* Paper no. DETC2005-85513 pp. 565-575 *
|
|
|
|
* ASME 2005 International Design Engineering Technical Conferences *
|
|
|
|
* and Computers and Information in Engineering Conference (IDETC/CIE2005) *
|
|
|
|
* September 24-28, 2005 , Long Beach, California, USA *
|
|
|
|
* http://www.me.berkeley.edu/~mcmains/pubs/DAC05OffsetPolygon.pdf *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef clipper_hpp
|
|
|
|
#define clipper_hpp
|
|
|
|
|
2015-11-02 12:45:33 +00:00
|
|
|
#define CLIPPER_VERSION "6.2.6"
|
2014-01-03 17:39:28 +00:00
|
|
|
|
|
|
|
//use_int32: When enabled 32bit ints are used instead of 64bit ints. This
|
|
|
|
//improve performance but coordinate values are limited to the range +/- 46340
|
|
|
|
//#define use_int32
|
|
|
|
|
|
|
|
//use_xyz: adds a Z member to IntPoint. Adds a minor cost to perfomance.
|
|
|
|
//#define use_xyz
|
|
|
|
|
|
|
|
//use_lines: Enables line clipping. Adds a very minor cost to performance.
|
2015-11-02 12:45:33 +00:00
|
|
|
#define use_lines
|
2014-01-07 19:42:34 +00:00
|
|
|
|
2014-11-12 17:58:39 +00:00
|
|
|
//use_deprecated: Enables temporary support for the obsolete functions
|
|
|
|
//#define use_deprecated
|
2014-01-03 17:39:28 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
#include <vector>
|
2015-11-02 12:45:33 +00:00
|
|
|
#include <list>
|
2014-01-03 17:39:28 +00:00
|
|
|
#include <set>
|
2013-05-26 04:36:44 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <ostream>
|
2014-01-03 17:39:28 +00:00
|
|
|
#include <functional>
|
2014-11-12 17:58:39 +00:00
|
|
|
#include <queue>
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
namespace ClipperLib {
|
|
|
|
|
|
|
|
enum ClipType { ctIntersection, ctUnion, ctDifference, ctXor };
|
|
|
|
enum PolyType { ptSubject, ptClip };
|
|
|
|
//By far the most widely used winding rules for polygon filling are
|
|
|
|
//EvenOdd & NonZero (GDI, GDI+, XLib, OpenGL, Cairo, AGG, Quartz, SVG, Gr32)
|
|
|
|
//Others rules include Positive, Negative and ABS_GTR_EQ_TWO (only in OpenGL)
|
|
|
|
//see http://glprogramming.com/red/chapter11.html
|
|
|
|
enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative };
|
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
#ifdef use_int32
|
2014-11-12 17:58:39 +00:00
|
|
|
typedef int cInt;
|
|
|
|
static cInt const loRange = 0x7FFF;
|
|
|
|
static cInt const hiRange = 0x7FFF;
|
2014-01-03 17:39:28 +00:00
|
|
|
#else
|
2014-11-12 17:58:39 +00:00
|
|
|
typedef signed long long cInt;
|
|
|
|
static cInt const loRange = 0x3FFFFFFF;
|
|
|
|
static cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL;
|
|
|
|
typedef signed long long long64; //used by Int128 class
|
|
|
|
typedef unsigned long long ulong64;
|
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
#endif
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
struct IntPoint {
|
2014-01-03 17:39:28 +00:00
|
|
|
cInt X;
|
|
|
|
cInt Y;
|
|
|
|
#ifdef use_xyz
|
|
|
|
cInt Z;
|
|
|
|
IntPoint(cInt x = 0, cInt y = 0, cInt z = 0): X(x), Y(y), Z(z) {};
|
|
|
|
#else
|
|
|
|
IntPoint(cInt x = 0, cInt y = 0): X(x), Y(y) {};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
friend inline bool operator== (const IntPoint& a, const IntPoint& b)
|
|
|
|
{
|
|
|
|
return a.X == b.X && a.Y == b.Y;
|
|
|
|
}
|
|
|
|
friend inline bool operator!= (const IntPoint& a, const IntPoint& b)
|
|
|
|
{
|
2014-01-07 19:42:34 +00:00
|
|
|
return a.X != b.X || a.Y != b.Y;
|
2014-01-03 17:39:28 +00:00
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
};
|
2014-01-03 17:39:28 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
typedef std::vector< IntPoint > Path;
|
|
|
|
typedef std::vector< Path > Paths;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
inline Path& operator <<(Path& poly, const IntPoint& p) {poly.push_back(p); return poly;}
|
|
|
|
inline Paths& operator <<(Paths& polys, const Path& p) {polys.push_back(p); return polys;}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
struct DoublePoint
|
|
|
|
{
|
|
|
|
double X;
|
|
|
|
double Y;
|
|
|
|
DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
|
|
|
|
DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {}
|
|
|
|
};
|
|
|
|
//------------------------------------------------------------------------------
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
#ifdef use_xyz
|
2014-11-12 17:58:39 +00:00
|
|
|
typedef void (*ZFillCallback)(IntPoint& e1bot, IntPoint& e1top, IntPoint& e2bot, IntPoint& e2top, IntPoint& pt);
|
2014-01-03 17:39:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
enum InitOptions {ioReverseSolution = 1, ioStrictlySimple = 2, ioPreserveCollinear = 4};
|
|
|
|
enum JoinType {jtSquare, jtRound, jtMiter};
|
|
|
|
enum EndType {etClosedPolygon, etClosedLine, etOpenButt, etOpenSquare, etOpenRound};
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
class PolyNode;
|
|
|
|
typedef std::vector< PolyNode* > PolyNodes;
|
|
|
|
|
2014-01-07 19:42:34 +00:00
|
|
|
class PolyNode
|
|
|
|
{
|
2013-05-26 04:36:44 +00:00
|
|
|
public:
|
|
|
|
PolyNode();
|
2014-11-12 17:58:39 +00:00
|
|
|
virtual ~PolyNode(){};
|
2014-01-03 17:39:28 +00:00
|
|
|
Path Contour;
|
2013-05-26 04:36:44 +00:00
|
|
|
PolyNodes Childs;
|
|
|
|
PolyNode* Parent;
|
|
|
|
PolyNode* GetNext() const;
|
|
|
|
bool IsHole() const;
|
2014-01-03 17:39:28 +00:00
|
|
|
bool IsOpen() const;
|
2013-05-26 04:36:44 +00:00
|
|
|
int ChildCount() const;
|
|
|
|
private:
|
|
|
|
unsigned Index; //node index in Parent.Childs
|
2014-01-03 17:39:28 +00:00
|
|
|
bool m_IsOpen;
|
|
|
|
JoinType m_jointype;
|
|
|
|
EndType m_endtype;
|
|
|
|
PolyNode* GetNextSiblingUp() const;
|
2013-05-26 04:36:44 +00:00
|
|
|
void AddChild(PolyNode& child);
|
|
|
|
friend class Clipper; //to access Index
|
2014-01-07 19:42:34 +00:00
|
|
|
friend class ClipperOffset;
|
2013-05-26 04:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PolyTree: public PolyNode
|
2014-01-07 19:42:34 +00:00
|
|
|
{
|
2013-05-26 04:36:44 +00:00
|
|
|
public:
|
|
|
|
~PolyTree(){Clear();};
|
|
|
|
PolyNode* GetFirst() const;
|
|
|
|
void Clear();
|
|
|
|
int Total() const;
|
|
|
|
private:
|
|
|
|
PolyNodes AllNodes;
|
|
|
|
friend class Clipper; //to access AllNodes
|
|
|
|
};
|
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
bool Orientation(const Path &poly);
|
|
|
|
double Area(const Path &poly);
|
2014-09-29 10:51:04 +00:00
|
|
|
int PointInPolygon(const IntPoint &pt, const Path &path);
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
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);
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
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);
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-09-29 10:51:04 +00:00
|
|
|
void MinkowskiSum(const Path& pattern, const Path& path, Paths& solution, bool pathIsClosed);
|
2014-11-12 17:58:39 +00:00
|
|
|
void MinkowskiSum(const Path& pattern, const Paths& paths, Paths& solution, bool pathIsClosed);
|
2014-09-29 10:51:04 +00:00
|
|
|
void MinkowskiDiff(const Path& poly1, const Path& poly2, Paths& solution);
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
void PolyTreeToPaths(const PolyTree& polytree, Paths& paths);
|
|
|
|
void ClosedPathsFromPolyTree(const PolyTree& polytree, Paths& paths);
|
|
|
|
void OpenPathsFromPolyTree(PolyTree& polytree, Paths& paths);
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
void ReversePath(Path& p);
|
|
|
|
void ReversePaths(Paths& p);
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
struct IntRect { cInt left; cInt top; cInt right; cInt bottom; };
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
//enums that are used internally ...
|
|
|
|
enum EdgeSide { esLeft = 1, esRight = 2};
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2014-01-03 17:39:28 +00:00
|
|
|
//forward declarations (for stuff used internally) ...
|
|
|
|
struct TEdge;
|
|
|
|
struct IntersectNode;
|
2014-11-12 17:58:39 +00:00
|
|
|
struct LocalMinimum;
|
2014-01-03 17:39:28 +00:00
|
|
|
struct OutPt;
|
|
|
|
struct OutRec;
|
|
|
|
struct Join;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
typedef std::vector < OutRec* > PolyOutList;
|
|
|
|
typedef std::vector < TEdge* > EdgeList;
|
2014-01-03 17:39:28 +00:00
|
|
|
typedef std::vector < Join* > JoinList;
|
|
|
|
typedef std::vector < IntersectNode* > IntersectList;
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
//ClipperBase is the ancestor to the Clipper class. It should not be
|
|
|
|
//instantiated directly. This class simply abstracts the conversion of sets of
|
|
|
|
//polygon coordinates into edge objects that are stored in a LocalMinima list.
|
|
|
|
class ClipperBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ClipperBase();
|
|
|
|
virtual ~ClipperBase();
|
2015-11-02 12:45:33 +00:00
|
|
|
virtual bool AddPath(const Path &pg, PolyType PolyTyp, bool Closed);
|
2014-01-03 17:39:28 +00:00
|
|
|
bool AddPaths(const Paths &ppg, PolyType PolyTyp, bool Closed);
|
2013-05-26 04:36:44 +00:00
|
|
|
virtual void Clear();
|
|
|
|
IntRect GetBounds();
|
2014-01-03 17:39:28 +00:00
|
|
|
bool PreserveCollinear() {return m_PreserveCollinear;};
|
|
|
|
void PreserveCollinear(bool value) {m_PreserveCollinear = value;};
|
2013-05-26 04:36:44 +00:00
|
|
|
protected:
|
|
|
|
void DisposeLocalMinimaList();
|
2014-01-03 17:39:28 +00:00
|
|
|
TEdge* AddBoundsToLML(TEdge *e, bool IsClosed);
|
2013-05-26 04:36:44 +00:00
|
|
|
virtual void Reset();
|
2014-01-03 17:39:28 +00:00
|
|
|
TEdge* ProcessBound(TEdge* E, bool IsClockwise);
|
2015-11-02 12:45:33 +00:00
|
|
|
void InsertScanbeam(const cInt Y);
|
|
|
|
bool PopScanbeam(cInt &Y);
|
|
|
|
bool LocalMinimaPending();
|
|
|
|
bool PopLocalMinima(cInt Y, const LocalMinimum *&locMin);
|
|
|
|
OutRec* CreateOutRec();
|
|
|
|
void DisposeAllOutRecs();
|
|
|
|
void DisposeOutRec(PolyOutList::size_type index);
|
|
|
|
void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2);
|
|
|
|
void DeleteFromAEL(TEdge *e);
|
|
|
|
void UpdateEdgeIntoAEL(TEdge *&e);
|
2014-11-12 17:58:39 +00:00
|
|
|
|
|
|
|
typedef std::vector<LocalMinimum> MinimaList;
|
|
|
|
MinimaList::iterator m_CurrentLM;
|
|
|
|
MinimaList m_MinimaList;
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
bool m_UseFullRange;
|
|
|
|
EdgeList m_edges;
|
2015-11-02 12:45:33 +00:00
|
|
|
bool m_PreserveCollinear;
|
|
|
|
bool m_HasOpenPaths;
|
|
|
|
PolyOutList m_PolyOuts;
|
|
|
|
TEdge *m_ActiveEdges;
|
|
|
|
|
|
|
|
typedef std::priority_queue<cInt> ScanbeamList;
|
|
|
|
ScanbeamList m_Scanbeam;
|
2013-05-26 04:36:44 +00:00
|
|
|
};
|
2014-01-03 17:39:28 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
class Clipper : public virtual ClipperBase
|
|
|
|
{
|
|
|
|
public:
|
2014-01-03 17:39:28 +00:00
|
|
|
Clipper(int initOptions = 0);
|
2013-05-26 04:36:44 +00:00
|
|
|
bool Execute(ClipType clipType,
|
2015-11-02 12:45:33 +00:00
|
|
|
Paths &solution,
|
|
|
|
PolyFillType fillType = pftEvenOdd);
|
|
|
|
bool Execute(ClipType clipType,
|
|
|
|
Paths &solution,
|
|
|
|
PolyFillType subjFillType,
|
|
|
|
PolyFillType clipFillType);
|
2013-05-26 04:36:44 +00:00
|
|
|
bool Execute(ClipType clipType,
|
2015-11-02 12:45:33 +00:00
|
|
|
PolyTree &polytree,
|
|
|
|
PolyFillType fillType = pftEvenOdd);
|
|
|
|
bool Execute(ClipType clipType,
|
|
|
|
PolyTree &polytree,
|
|
|
|
PolyFillType subjFillType,
|
|
|
|
PolyFillType clipFillType);
|
|
|
|
bool ReverseSolution() { return m_ReverseOutput; };
|
2013-05-26 04:36:44 +00:00
|
|
|
void ReverseSolution(bool value) {m_ReverseOutput = value;};
|
2014-01-03 17:39:28 +00:00
|
|
|
bool StrictlySimple() {return m_StrictSimple;};
|
|
|
|
void StrictlySimple(bool value) {m_StrictSimple = value;};
|
|
|
|
//set the callback function for z value filling on intersections (otherwise Z is 0)
|
|
|
|
#ifdef use_xyz
|
2014-11-12 17:58:39 +00:00
|
|
|
void ZFillFunction(ZFillCallback zFillFunc);
|
2014-01-03 17:39:28 +00:00
|
|
|
#endif
|
2013-05-26 04:36:44 +00:00
|
|
|
protected:
|
|
|
|
virtual bool ExecuteInternal();
|
|
|
|
private:
|
2015-11-02 12:45:33 +00:00
|
|
|
JoinList m_Joins;
|
|
|
|
JoinList m_GhostJoins;
|
|
|
|
IntersectList m_IntersectList;
|
|
|
|
ClipType m_ClipType;
|
|
|
|
typedef std::list<cInt> MaximaList;
|
|
|
|
MaximaList m_Maxima;
|
2013-05-26 04:36:44 +00:00
|
|
|
TEdge *m_SortedEdges;
|
|
|
|
bool m_ExecuteLocked;
|
|
|
|
PolyFillType m_ClipFillType;
|
|
|
|
PolyFillType m_SubjFillType;
|
|
|
|
bool m_ReverseOutput;
|
2014-01-07 19:42:34 +00:00
|
|
|
bool m_UsingPolyTree;
|
2014-01-03 17:39:28 +00:00
|
|
|
bool m_StrictSimple;
|
|
|
|
#ifdef use_xyz
|
2014-11-12 17:58:39 +00:00
|
|
|
ZFillCallback m_ZFill; //custom callback
|
2014-01-03 17:39:28 +00:00
|
|
|
#endif
|
2013-05-26 04:36:44 +00:00
|
|
|
void SetWindingCount(TEdge& edge);
|
|
|
|
bool IsEvenOddFillType(const TEdge& edge) const;
|
|
|
|
bool IsEvenOddAltFillType(const TEdge& edge) const;
|
2014-01-03 17:39:28 +00:00
|
|
|
void InsertLocalMinimaIntoAEL(const cInt botY);
|
|
|
|
void InsertEdgeIntoAEL(TEdge *edge, TEdge* startEdge);
|
2013-05-26 04:36:44 +00:00
|
|
|
void AddEdgeToSEL(TEdge *edge);
|
2015-11-02 12:45:33 +00:00
|
|
|
bool PopEdgeFromSEL(TEdge *&edge);
|
2013-05-26 04:36:44 +00:00
|
|
|
void CopyAELToSEL();
|
|
|
|
void DeleteFromSEL(TEdge *e);
|
|
|
|
void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2);
|
|
|
|
bool IsContributing(const TEdge& edge) const;
|
2014-01-03 17:39:28 +00:00
|
|
|
bool IsTopHorz(const cInt XPos);
|
|
|
|
void DoMaxima(TEdge *e);
|
2015-11-02 12:45:33 +00:00
|
|
|
void ProcessHorizontals();
|
|
|
|
void ProcessHorizontal(TEdge *horzEdge);
|
2013-05-26 04:36:44 +00:00
|
|
|
void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
|
2014-01-03 17:39:28 +00:00
|
|
|
OutPt* AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt);
|
|
|
|
OutRec* GetOutRec(int idx);
|
2013-05-26 04:36:44 +00:00
|
|
|
void AppendPolygon(TEdge *e1, TEdge *e2);
|
2014-11-12 17:58:39 +00:00
|
|
|
void IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &pt);
|
2014-01-03 17:39:28 +00:00
|
|
|
OutPt* AddOutPt(TEdge *e, const IntPoint &pt);
|
2015-11-02 12:45:33 +00:00
|
|
|
OutPt* GetLastOutPt(TEdge *e);
|
2014-11-12 17:58:39 +00:00
|
|
|
bool ProcessIntersections(const cInt topY);
|
|
|
|
void BuildIntersectList(const cInt topY);
|
2013-05-26 04:36:44 +00:00
|
|
|
void ProcessIntersectList();
|
2014-01-03 17:39:28 +00:00
|
|
|
void ProcessEdgesAtTopOfScanbeam(const cInt topY);
|
|
|
|
void BuildResult(Paths& polys);
|
2013-05-26 04:36:44 +00:00
|
|
|
void BuildResult2(PolyTree& polytree);
|
2014-01-03 17:39:28 +00:00
|
|
|
void SetHoleState(TEdge *e, OutRec *outrec);
|
2013-05-26 04:36:44 +00:00
|
|
|
void DisposeIntersectNodes();
|
|
|
|
bool FixupIntersectionOrder();
|
2014-01-03 17:39:28 +00:00
|
|
|
void FixupOutPolygon(OutRec &outrec);
|
2015-11-02 12:45:33 +00:00
|
|
|
void FixupOutPolyline(OutRec &outrec);
|
2013-05-26 04:36:44 +00:00
|
|
|
bool IsHole(TEdge *e);
|
2014-01-03 17:39:28 +00:00
|
|
|
bool FindOwnerFromSplitRecs(OutRec &outRec, OutRec *&currOrfl);
|
|
|
|
void FixHoleLinkage(OutRec &outrec);
|
|
|
|
void AddJoin(OutPt *op1, OutPt *op2, const IntPoint offPt);
|
2013-05-26 04:36:44 +00:00
|
|
|
void ClearJoins();
|
2014-01-03 17:39:28 +00:00
|
|
|
void ClearGhostJoins();
|
|
|
|
void AddGhostJoin(OutPt *op, const IntPoint offPt);
|
|
|
|
bool JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2);
|
2013-05-26 04:36:44 +00:00
|
|
|
void JoinCommonEdges();
|
2014-01-03 17:39:28 +00:00
|
|
|
void DoSimplePolygons();
|
2013-05-26 04:36:44 +00:00
|
|
|
void FixupFirstLefts1(OutRec* OldOutRec, OutRec* NewOutRec);
|
2015-11-02 12:45:33 +00:00
|
|
|
void FixupFirstLefts2(OutRec* InnerOutRec, OutRec* OuterOutRec);
|
|
|
|
void FixupFirstLefts3(OutRec* OldOutRec, OutRec* NewOutRec);
|
2014-01-03 17:39:28 +00:00
|
|
|
#ifdef use_xyz
|
2014-11-12 17:58:39 +00:00
|
|
|
void SetZ(IntPoint& pt, TEdge& e1, TEdge& e2);
|
2014-01-03 17:39:28 +00:00
|
|
|
#endif
|
2013-05-26 04:36:44 +00:00
|
|
|
};
|
|
|
|
//------------------------------------------------------------------------------
|
2014-01-03 17:39:28 +00:00
|
|
|
|
2014-01-07 19:42:34 +00:00
|
|
|
class ClipperOffset
|
2014-01-03 17:39:28 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ClipperOffset(double miterLimit = 2.0, double roundPrecision = 0.25);
|
|
|
|
~ClipperOffset();
|
|
|
|
void AddPath(const Path& path, JoinType joinType, EndType endType);
|
|
|
|
void AddPaths(const Paths& paths, JoinType joinType, EndType endType);
|
|
|
|
void Execute(Paths& solution, double delta);
|
|
|
|
void Execute(PolyTree& solution, double delta);
|
|
|
|
void Clear();
|
|
|
|
double MiterLimit;
|
|
|
|
double ArcTolerance;
|
|
|
|
private:
|
|
|
|
Paths m_destPolys;
|
|
|
|
Path m_srcPoly;
|
|
|
|
Path m_destPoly;
|
|
|
|
std::vector<DoublePoint> m_normals;
|
|
|
|
double m_delta, m_sinA, m_sin, m_cos;
|
|
|
|
double m_miterLim, m_StepsPerRad;
|
|
|
|
IntPoint m_lowest;
|
|
|
|
PolyNode m_polyNodes;
|
|
|
|
|
|
|
|
void FixOrientations();
|
|
|
|
void DoOffset(double delta);
|
|
|
|
void OffsetPoint(int j, int& k, JoinType jointype);
|
|
|
|
void DoSquare(int j, int k);
|
|
|
|
void DoMiter(int j, int k, double r);
|
|
|
|
void DoRound(int j, int k);
|
|
|
|
};
|
2013-05-26 04:36:44 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class clipperException : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
clipperException(const char* description): m_descr(description) {}
|
|
|
|
virtual ~clipperException() throw() {}
|
|
|
|
virtual const char* what() const throw() {return m_descr.c_str();}
|
|
|
|
private:
|
|
|
|
std::string m_descr;
|
|
|
|
};
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
} //ClipperLib namespace
|
|
|
|
|
|
|
|
#endif //clipper_hpp
|
|
|
|
|
|
|
|
|