26 #ifndef __SHAPE_LINE_CHAIN
27 #define __SHAPE_LINE_CHAIN
32 #include <core/optional.h>
34 #include <math/vector2d.h>
35 #include <geometry/shape.h>
36 #include <geometry/seg.h>
38 #include "clipper/clipper.hpp"
52 typedef std::vector<VECTOR2I>::iterator point_iter;
53 typedef std::vector<VECTOR2I>::const_iterator point_citer;
71 typedef std::vector<INTERSECTION> INTERSECTIONS;
84 :
SHAPE( SH_LINE_CHAIN ),
85 m_points( aShape.m_points ),
86 m_closed( aShape.m_closed ),
87 m_width( aShape.m_width )
95 SHAPE( SH_LINE_CHAIN ), m_closed( false ), m_width( 0 )
103 SHAPE( SH_LINE_CHAIN ), m_closed( false ), m_width( 0 )
105 m_points.resize( 3 );
112 SHAPE( SH_LINE_CHAIN ), m_closed( false ), m_width( 0 )
114 m_points.resize( 4 );
123 SHAPE( SH_LINE_CHAIN ),
127 m_points.resize( aCount );
129 for(
int i = 0; i < aCount; i++ )
134 :
SHAPE( SH_LINE_CHAIN ), m_closed( true ), m_width( 0 )
136 m_points.reserve( aPath.size() );
138 for(
const auto& point : aPath )
139 m_points.emplace_back( point.X, point.Y );
205 int c = m_points.size() - 1;
209 return std::max( 0, c );
220 return m_points.size();
236 if( aIndex == (
int)( m_points.size() - 1 ) && m_closed )
237 return SEG( m_points[aIndex], m_points[0], aIndex );
239 return SEG( m_points[aIndex], m_points[aIndex + 1], aIndex );
255 if( aIndex == (
int)( m_points.size() - 1 ) && m_closed )
256 return SEG(
const_cast<VECTOR2I&
>( m_points[aIndex] ),
257 const_cast<VECTOR2I&
>( m_points[0] ), aIndex );
259 return SEG(
const_cast<VECTOR2I&
>( m_points[aIndex] ),
260 const_cast<VECTOR2I&
>( m_points[aIndex + 1] ), aIndex );
275 return m_points[aIndex];
292 return m_points[aIndex];
295 const std::vector<VECTOR2I>& CPoints()
const
322 if( aClearance != 0 || m_width != 0 )
323 bbox.
Inflate( aClearance + m_width );
346 bool Collide(
const SEG& aSeg,
int aClearance = 0 )
const override;
383 void Append(
int aX,
int aY,
bool aAllowDuplication =
false )
386 Append( v, aAllowDuplication );
400 if( m_points.size() == 0 )
403 if( m_points.size() == 0 || aAllowDuplication ||
CPoint( -1 ) != aP )
405 m_points.push_back( aP );
424 m_points.push_back( p );
428 for(
int i = 1; i < aOtherLine.
PointCount(); i++ )
431 m_points.push_back( p );
436 void Insert(
int aVertex,
const VECTOR2I& aP )
438 m_points.insert( m_points.begin() + aVertex, aP );
470 void Remove(
int aStartIndex,
int aEndIndex );
527 bool operator()(
const INTERSECTION& aA,
const INTERSECTION& aB )
529 return ( m_origin - aA.p ).EuclideanNorm() < ( m_origin - aB.p ).EuclideanNorm();
656 const std::string
Format()
const override;
659 bool Parse( std::stringstream& aStream )
override;
677 void Move(
const VECTOR2I& aVector )
override
679 for( std::vector<VECTOR2I>::iterator i = m_points.begin(); i != m_points.end(); ++i )
691 bool IsSolid()
const override
696 const VECTOR2I PointAlong(
int aPathLength )
const;
702 std::vector<VECTOR2I> m_points;
717 #endif // __SHAPE_LINE_CHAIN
VECTOR2I p
point of intersection between our and their.
Definition: shape_line_chain.h:68
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
SHAPE_LINE_CHAIN(const SHAPE_LINE_CHAIN &aShape)
Copy Constructor.
Definition: shape_line_chain.h:83
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Function Intersect()
const VECTOR2I & CLastPoint() const
Returns the last point in the line chain.
Definition: shape_line_chain.h:311
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:300
void SetWidth(int aWidth)
Sets the width of all segments in the chain.
Definition: shape_line_chain.h:183
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
Definition: shape_line_chain.h:383
SHAPE_LINE_CHAIN(const VECTOR2I &aA, const VECTOR2I &aB)
Constructor Initializes a 2-point line chain (a single segment)
Definition: shape_line_chain.h:94
void Clear()
Function Clear() Removes all points from the line chain.
Definition: shape_line_chain.h:151
const std::string Format() const override
SEG Segment(int aIndex)
Function Segment()
Definition: shape_line_chain.h:231
const SHAPE_LINE_CHAIN Slice(int aStartIndex, int aEndIndex=-1) const
Function Slice()
int EdgeContainingPoint(const VECTOR2I &aP) const
Function EdgeContainingPoint()
const OPT< INTERSECTION > SelfIntersecting() const
Function SelfIntersecting()
VECTOR2I & Point(int aIndex)
Function Point()
Definition: shape_line_chain.h:270
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
Definition: box2.h:384
int SegmentCount() const
Function SegmentCount()
Definition: shape_line_chain.h:203
void Replace(int aStartIndex, int aEndIndex, const VECTOR2I &aP)
Function Replace()
void Remove(int aStartIndex, int aEndIndex)
Function Remove()
const SEG CSegment(int aIndex) const
Function CSegment()
Definition: shape_line_chain.h:250
void SetClosed(bool aClosed)
Function SetClosed()
Definition: shape_line_chain.h:164
int Intersect(const SHAPE_LINE_CHAIN &aChain, INTERSECTIONS &aIp) const
Function Intersect()
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
bool PointInside(const VECTOR2I &aP) const
Function PointInside()
VECTOR2I & LastPoint()
Returns the last point in the line chain.
Definition: shape_line_chain.h:303
void Append(const SHAPE_LINE_CHAIN &aOtherLine)
Function Append()
Definition: shape_line_chain.h:416
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_line_chain.h:317
SHAPE * Clone() const override
Function Clone()
void Rotate(double aAngle, const VECTOR2I &aCenter)
Function Rotate rotates all vertices by a given angle.
SEG their
segment belonging from the aOther argument of Intersect()
Definition: shape_line_chain.h:66
void convertFromClipper(const ClipperLib::Path &aPath)
Function convertFromClipper() Appends the Clipper path to the current SHAPE_LINE_CHAIN.
int Distance(const VECTOR2I &aP, bool aOutlineOnly=false) const
Function Distance()
int PointCount() const
Function PointCount()
Definition: shape_line_chain.h:218
bool PointOnEdge(const VECTOR2I &aP) const
Function PointOnEdge()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
Definition: shape_line_chain.h:285
bool IsClosed() const
Function IsClosed()
Definition: shape_line_chain.h:174
void Replace(int aStartIndex, int aEndIndex, const SHAPE_LINE_CHAIN &aLine)
Function Replace()
Definition: shape_line_chain.h:522
SEG our
segment belonging from the (this) argument of Intersect()
Definition: shape_line_chain.h:64
bool Parse(std::stringstream &aStream) override
int Find(const VECTOR2I &aP) const
Function Find()
int PathLength(const VECTOR2I &aP) const
Function PathLength()
bool CheckClearance(const VECTOR2I &aP, const int aDist) const
Function CheckClearance()
void Append(const VECTOR2I &aP, bool aAllowDuplication=false)
Function Append()
Definition: shape_line_chain.h:398
int Width() const
Gets the current width of the segments in the chain.
Definition: shape_line_chain.h:192
int Split(const VECTOR2I &aP)
Function Split()
const VECTOR2I NearestPoint(const SEG &aSeg, int &dist) const
Function NearestPoint()
Class SHAPE_LINE_CHAIN.
Definition: shape_line_chain.h:50
Class SHAPE.
Definition: shape.h:59
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:89
int Length() const
Function Length()
ClipperLib::Path convertToClipper(bool aRequiredOrientation) const
Creates a new Clipper path from the SHAPE_LINE_CHAIN in a given orientation.
void Remove(int aIndex)
Function Remove() removes the aIndex-th point from the line chain.
Definition: shape_line_chain.h:477
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
int FindSegment(const VECTOR2I &aP) const
Function FindSegment()
const SHAPE_LINE_CHAIN Reverse() const
Function Reverse()
SHAPE_LINE_CHAIN()
Constructor Initializes an empty line chain.
Definition: shape_line_chain.h:77