Reverted commits that remove boost::polygon dependency (need more testing).

This commit is contained in:
Maciej Suminski
2015-07-14 22:23:13 +02:00
parent 9f18e5a98f
commit d2ebf688f9
57 changed files with 5030 additions and 1209 deletions
-4
View File
@@ -255,9 +255,6 @@ public:
if( aIndex < 0 )
aIndex += PointCount();
if( aIndex >= PointCount() )
aIndex -= PointCount();
return m_points[aIndex];
}
@@ -581,7 +578,6 @@ public:
{
return false;
}
private:
/// array of vertices
std::vector<VECTOR2I> m_points;
+24 -222
View File
@@ -32,103 +32,25 @@
#include "clipper.hpp"
/**
* Class SHAPE_POLY_SET
*
* Represents a set of closed polygons. Polygons may be nonconvex, self-intersecting
* and have holes. Provides boolean operations (using Clipper library as the backend).
*
* TODO: add convex partitioning & spatial index
* TODO: document, derive from class SHAPE, add convex partitioning & spatial index
*/
class SHAPE_POLY_SET : public SHAPE
{
public:
///> represents a single polygon outline with holes. The first entry is the outline,
///> the remaining (if any), are the holes
typedef std::vector<SHAPE_LINE_CHAIN> POLYGON;
/**
* Class ITERATOR_TEMPLATE
*
* Base class for iterating over all vertices in a given SHAPE_POLY_SET
*/
template <class T>
class ITERATOR_TEMPLATE {
public:
bool IsEndContour() const
{
return m_currentVertex + 1 == m_poly->CPolygon( m_currentOutline )[0].PointCount();
}
bool IsLastContour() const
{
return m_currentOutline == m_lastOutline;
}
operator bool() const
{
return m_currentOutline <= m_lastOutline;
}
void Advance()
{
m_currentVertex ++;
if( m_currentVertex >= m_poly->CPolygon( m_currentOutline )[0].PointCount() )
{
m_currentVertex = 0;
m_currentOutline++;
}
}
void operator++( int dummy )
{
Advance();
}
void operator++()
{
Advance();
}
T& Get()
{
return m_poly->Polygon( m_currentOutline )[0].Point( m_currentVertex );
}
T& operator*()
{
return Get();
}
T* operator->()
{
return &Get();
}
private:
friend class SHAPE_POLY_SET;
SHAPE_POLY_SET* m_poly;
int m_currentOutline;
int m_lastOutline;
int m_currentVertex;
};
typedef ITERATOR_TEMPLATE<VECTOR2I> ITERATOR;
typedef ITERATOR_TEMPLATE<const VECTOR2I> CONST_ITERATOR;
SHAPE_POLY_SET();
~SHAPE_POLY_SET();
SHAPE_POLY_SET() : SHAPE( SH_POLY_SET ) {};
~SHAPE_POLY_SET() {};
///> Creates a new empty polygon in the set and returns its index
int NewOutline();
///> Creates a new hole in a given outline
int NewHole( int aOutline = -1 );
///> Cretes a new empty hole in the given outline (default: last one) and returns its index
int NewHole( int aOutline = -1);
///> Adds a new outline to the set and returns its index
int AddOutline( const SHAPE_LINE_CHAIN& aOutline );
@@ -136,20 +58,11 @@ class SHAPE_POLY_SET : public SHAPE
///> Adds a new hole to the given outline (default: last) and returns its index
int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
///> Appends a vertex at the end of the given outline/hole (default: the last outline)
int Append( int x, int y, int aOutline = -1, int aHole = -1 );
///> Merges polygons from two sets.
void Append( const SHAPE_POLY_SET& aSet );
///> Appends a vertex at the end of the given outline/hole (default: the last outline)
void Append( const VECTOR2I& aP, int aOutline = -1, int aHole = -1 );
///> Appends a vertex at the end of the given outline/hole (default: last hole in the last outline)
int AppendVertex( int x, int y, int aOutline = -1, int aHole = -1 );
///> Returns the index-th vertex in a given hole outline within a given outline
VECTOR2I& Vertex( int index, int aOutline = -1, int aHole = -1 );
///> Returns the index-th vertex in a given hole outline within a given outline
const VECTOR2I& CVertex( int index, int aOutline = -1, int aHole = -1 ) const;
const VECTOR2I GetVertex( int index, int aOutline = -1, int aHole = -1) const;
///> Returns true if any of the outlines is self-intersecting
bool IsSelfIntersecting();
@@ -160,109 +73,28 @@ class SHAPE_POLY_SET : public SHAPE
///> Returns the number of vertices in a given outline/hole
int VertexCount( int aOutline = -1, int aHole = -1 ) const;
///> Returns the number of holes in a given outline
int HoleCount( int aOutline ) const;
///> Returns the reference to aIndex-th outline in the set
SHAPE_LINE_CHAIN& Outline( int aIndex )
{
return m_polys[aIndex][0];
}
///> Returns the reference to aHole-th hole in the aIndex-th outline
SHAPE_LINE_CHAIN& Hole( int aOutline, int aHole )
{
return m_polys[aOutline][aHole + 1];
}
///> Returns the aIndex-th subpolygon in the set
POLYGON& Polygon( int aIndex )
///> Returns the internal representation (ClipperLib) of a given polygon (outline + holes)
const ClipperLib::Paths& GetPoly( int aIndex ) const
{
return m_polys[aIndex];
}
const SHAPE_LINE_CHAIN& COutline( int aIndex ) const
{
return m_polys[aIndex][0];
}
const SHAPE_LINE_CHAIN& CHole( int aOutline, int aHole ) const
{
return m_polys[aOutline][aHole + 1];
}
const POLYGON& CPolygon( int aIndex ) const
{
return m_polys[aIndex];
}
///> Returns an iterator object, for iterating between aFirst and aLast outline.
ITERATOR Iterate( int aFirst, int aLast )
{
ITERATOR iter;
iter.m_poly = this;
iter.m_currentOutline = aFirst;
iter.m_lastOutline = aLast < 0 ? OutlineCount() - 1 : aLast;
iter.m_currentVertex = 0;
return iter;
}
///> Returns an iterator object, for iterating aOutline-th outline
ITERATOR Iterate( int aOutline )
{
return Iterate( aOutline, aOutline );
}
///> Returns an iterator object, for all outlines in the set (no holes)
ITERATOR Iterate()
{
return Iterate( 0, OutlineCount() - 1 );
}
CONST_ITERATOR CIterate( int aFirst, int aLast ) const
{
CONST_ITERATOR iter;
iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
iter.m_currentOutline = aFirst;
iter.m_lastOutline = aLast < 0 ? OutlineCount() - 1 : aLast;
iter.m_currentVertex = 0;
return iter;
}
CONST_ITERATOR CIterate( int aOutline ) const
{
return CIterate( aOutline, aOutline );
}
CONST_ITERATOR CIterate() const
{
return CIterate( 0, OutlineCount() - 1 );
}
///> Performs boolean polyset union
void BooleanAdd( const SHAPE_POLY_SET& b );
///> Performs boolean polyset difference
void BooleanSubtract( const SHAPE_POLY_SET& b );
void Subtract( const SHAPE_POLY_SET& b );
///> Performs outline inflation/deflation, using round corners.
void Inflate( int aFactor, int aCircleSegmentsCount );
///> Performs boolean polyset union
void Add( const SHAPE_POLY_SET& b );
///> Performs smooth outline inflation (Minkowski sum of the outline and a circle of a given radius)
void SmoothInflate( int aFactor );
///> Performs outline erosion/shrinking
void Erode( int aFactor );
///> Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the outer ring
///> to the inner holes
void Fracture();
///> Converts a set of slitted polygons to a set of polygons with holes
void Unfracture();
///> Returns true if the polygon set has any holes.
bool HasHoles() const;
///> Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
void Simplify();
@@ -272,10 +104,8 @@ class SHAPE_POLY_SET : public SHAPE
/// @copydoc SHAPE::Parse()
bool Parse( std::stringstream& aStream );
/// @copydoc SHAPE::Move()
void Move( const VECTOR2I& aVector );
void Move( const VECTOR2I& aVector ) { assert(false ); };
/// @copydoc SHAPE::IsSolid()
bool IsSolid() const
{
return true;
@@ -287,43 +117,15 @@ class SHAPE_POLY_SET : public SHAPE
bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const { return false; }
bool Collide( const SEG& aSeg, int aClearance = 0 ) const { return false; }
///> Returns true is a given subpolygon contains the point aP. If aSubpolyIndex < 0 (default value),
///> checks all polygons in the set
bool Contains( const VECTOR2I& aP, int aSubpolyIndex = -1 ) const;
///> Returns true if the set is empty (no polygons at all)
bool IsEmpty() const
{
return m_polys.size() == 0;
}
///> Removes all outlines & holes (clears) the polygon set.
void RemoveAllContours();
///> Returns total number of vertices stored in the set.
int TotalVertices() const;
///> Deletes aIdx-th polygon from the set
void DeletePolygon( int aIdx );
private:
SHAPE_LINE_CHAIN& getContourForCorner( int aCornerId, int& aIndexWithinContour );
VECTOR2I& vertex( int aCornerId );
const VECTOR2I& cvertex( int aCornerId ) const;
void fractureSingle( POLYGON& paths );
void importTree( ClipperLib::PolyTree* tree );
void fractureSingle( ClipperLib::Paths& paths );
void importTree( ClipperLib::PolyTree* tree);
void booleanOp( ClipperLib::ClipType type, const SHAPE_POLY_SET& b );
bool pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const;
const ClipperLib::Path convert( const SHAPE_LINE_CHAIN& aPath );
const ClipperLib::Path convertToClipper( const SHAPE_LINE_CHAIN& aPath, bool aRequiredOrientation );
const SHAPE_LINE_CHAIN convertFromClipper( const ClipperLib::Path& aPath );
typedef std::vector<POLYGON> Polyset;
typedef std::vector<ClipperLib::Paths> Polyset;
Polyset m_polys;
};