1
0
Fork 0

Sync clipper library with latest code from SF

Picked from here:
https://sourceforge.net/p/polyclipping/code/HEAD/tree/trunk/cpp/
This commit is contained in:
Torsten Dreyer 2018-02-12 22:32:52 +01:00
parent 9d25a4c4b1
commit e6f652ab91
4 changed files with 5042 additions and 4948 deletions

File diff suppressed because it is too large Load diff

View file

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

View file

@ -110,7 +110,7 @@ void tgChopper::Add( const tgPolygon& subject, const std::string& type )
double clip_top = b_clip.get_center_lat() + 0.0630; double clip_top = b_clip.get_center_lat() + 0.0630;
tgPolygon clip_row, clipped; tgPolygon clip_row, clipped;
SG_LOG( SG_GENERAL, SG_DEBUG, " CLIPPED row " << row << " center lat is " << b_clip.get_center_lat() << " clip_botton is " << clip_bottom << " clip_top is " << clip_top ); SG_LOG( SG_GENERAL, SG_DEBUG, " CLIPPED row " << row << " of " << dy << ", center lat is " << b_clip.get_center_lat() << " clip_botton is " << clip_bottom << " clip_top is " << clip_top );
clip_row.AddNode( 0, SGGeod::fromDeg(-180.0, clip_bottom) ); clip_row.AddNode( 0, SGGeod::fromDeg(-180.0, clip_bottom) );
clip_row.AddNode( 0, SGGeod::fromDeg( 180.0, clip_bottom) ); clip_row.AddNode( 0, SGGeod::fromDeg( 180.0, clip_bottom) );

View file

@ -70,18 +70,18 @@ double CalculateTheta( const SGVec3d& dirCur, const SGVec3d& dirNext )
ClipperLib::IntPoint SGGeod_ToClipper( const SGGeod& p ) ClipperLib::IntPoint SGGeod_ToClipper( const SGGeod& p )
{ {
ClipperLib::cUInt x, y; ClipperLib::cInt x, y;
if ( p.getLongitudeDeg() > 0 ) { if ( p.getLongitudeDeg() > 0 ) {
x = (ClipperLib::cUInt)( (p.getLongitudeDeg() * CLIPPER_FIXEDPT) + 0.5 ); x = (ClipperLib::cInt)( (p.getLongitudeDeg() * CLIPPER_FIXEDPT) + 0.5 );
} else { } else {
x = (ClipperLib::cUInt)( (p.getLongitudeDeg() * CLIPPER_FIXEDPT) - 0.5 ); x = (ClipperLib::cInt)( (p.getLongitudeDeg() * CLIPPER_FIXEDPT) - 0.5 );
} }
if ( p.getLatitudeDeg() > 0 ) { if ( p.getLatitudeDeg() > 0 ) {
y = (ClipperLib::cUInt)( (p.getLatitudeDeg() * CLIPPER_FIXEDPT) + 0.5 ); y = (ClipperLib::cInt)( (p.getLatitudeDeg() * CLIPPER_FIXEDPT) + 0.5 );
} else { } else {
y = (ClipperLib::cUInt)( (p.getLatitudeDeg() * CLIPPER_FIXEDPT) - 0.5 ); y = (ClipperLib::cInt)( (p.getLatitudeDeg() * CLIPPER_FIXEDPT) - 0.5 );
} }
return ClipperLib::IntPoint( x, y ); return ClipperLib::IntPoint( x, y );
@ -377,4 +377,4 @@ bool intersection(const SGGeod &p0, const SGGeod &p1, const SGGeod& p2, const SG
// handle the no intersection case. // handle the no intersection case.
return false; return false;
} }
} }