Horizon
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SHAPE_SIMPLE Class Reference

Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments. More...

#include <shape_simple.h>

Inheritance diagram for SHAPE_SIMPLE:
SHAPE_LINE_CHAIN_BASE SHAPE SHAPE_BASE

Public Member Functions

 SHAPE_SIMPLE ()
 Create an empty polygon.
 
 SHAPE_SIMPLE (const SHAPE_LINE_CHAIN &aPoly)
 
 SHAPE_SIMPLE (const SHAPE_SIMPLE &aOther)
 
SHAPEClone () const override
 Return a dynamically allocated copy of the shape.
 
void Clear ()
 Remove all points from the polygon.
 
const BOX2I BBox (int aClearance=0) const override
 Compute a bounding box of the shape, with a margin of aClearance a collision.
 
int PointCount () const
 Return the number of points (vertices) in this polygon.
 
const VECTOR2ICPoint (int aIndex) const
 Return a const reference to a given point in the polygon.
 
const VECTOR2D CDPoint (int aIndex) const
 Return a given point as a vector with elements of type double.
 
const SHAPE_LINE_CHAINVertices () const
 Return the list of vertices defining this simple polygon.
 
void Append (int aX, int aY)
 Append a new point at the end of the polygon.
 
void Append (const VECTOR2I &aP)
 Append a new point at the end of the polygon.
 
bool Collide (const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
 Check if the boundary of shape (this) lies closer to the point aP than aClearance, indicating a collision.
 
void Rotate (double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
 
void Move (const VECTOR2I &aVector) override
 
bool IsSolid () const override
 
virtual const VECTOR2I GetPoint (int aIndex) const override
 
virtual const SEG GetSegment (int aIndex) const override
 
virtual size_t GetPointCount () const override
 
virtual size_t GetSegmentCount () const override
 
bool IsClosed () const override
 
- Public Member Functions inherited from SHAPE_LINE_CHAIN_BASE
 SHAPE_LINE_CHAIN_BASE (SHAPE_TYPE aType)
 
virtual bool Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
 Check if point aP lies closer to us than aClearance.
 
SEG::ecoord SquaredDistance (const VECTOR2I &aP, bool aOutlineOnly=false) const
 
bool PointInside (const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
 Check if point aP lies inside a polygon (any type) defined by the line chain.
 
bool PointOnEdge (const VECTOR2I &aP, int aAccuracy=0) const
 Check if point aP lies on an edge or vertex of the line chain.
 
int EdgeContainingPoint (const VECTOR2I &aP, int aAccuracy=0) const
 Check if point aP lies on an edge or vertex of the line chain.
 
virtual BOX2IGetCachedBBox () const
 
- Public Member Functions inherited from SHAPE
 SHAPE (SHAPE_TYPE aType)
 Create an empty shape of type aType.
 
bool IsNull () const
 Return true if the shape is a null shape.
 
virtual bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const
 Check if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision.
 
virtual bool Collide (const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
 
virtual VECTOR2I Centre () const
 Compute a center-of-mass of the shape.
 
virtual bool Parse (std::stringstream &aStream)
 
virtual const std::string Format () const
 
- Public Member Functions inherited from SHAPE_BASE
 SHAPE_BASE (SHAPE_TYPE aType)
 Create an empty shape of type aType.
 
SHAPE_TYPE Type () const
 Return the type of the shape.
 
virtual bool HasIndexableSubshapes () const
 
virtual size_t GetIndexableSubshapeCount () const
 
virtual void GetIndexableSubshapes (std::vector< SHAPE * > &aSubshapes)
 

Additional Inherited Members

- Static Public Attributes inherited from SHAPE
static const int MIN_PRECISION_IU = 4
 This is the minimum precision for all the points in a shape.
 
- Protected Types inherited from SHAPE
typedef VECTOR2I::extended_type ecoord
 
- Protected Attributes inherited from SHAPE_BASE
SHAPE_TYPE m_type
 < type of our shape
 

Detailed Description

Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.

Internally the vertices are held in a SHAPE_LINE_CHAIN, please note that there is a "virtual" line segment between the last and first vertex.

Member Function Documentation

◆ Append() [1/2]

void SHAPE_SIMPLE::Append ( const VECTOR2I aP)
inline

Append a new point at the end of the polygon.

Parameters
aPis the new point.

◆ Append() [2/2]

void SHAPE_SIMPLE::Append ( int  aX,
int  aY 
)
inline

Append a new point at the end of the polygon.

Parameters
aXis X coordinate of the new point.
aYis Y coordinate of the new point.

◆ BBox()

const BOX2I SHAPE_SIMPLE::BBox ( int  aClearance = 0) const
inlineoverridevirtual

Compute a bounding box of the shape, with a margin of aClearance a collision.

Parameters
aClearancehow much the bounding box is expanded wrs to the minimum enclosing rectangle for the shape.
Returns
the bounding box.

Implements SHAPE.

◆ CDPoint()

const VECTOR2D SHAPE_SIMPLE::CDPoint ( int  aIndex) const
inline

Return a given point as a vector with elements of type double.

Parameters
aIndexis the index of the point.
Returns
the point with elements of type double.

◆ Clone()

SHAPE * SHAPE_SIMPLE::Clone ( ) const
inlineoverridevirtual

Return a dynamically allocated copy of the shape.

Return values
copyof the shape

Reimplemented from SHAPE.

◆ Collide()

bool SHAPE_SIMPLE::Collide ( const SEG aSeg,
int  aClearance = 0,
int *  aActual = nullptr,
VECTOR2I aLocation = nullptr 
) const
inlineoverridevirtual

Check if the boundary of shape (this) lies closer to the point aP than aClearance, indicating a collision.

Parameters
aActual[out] an optional pointer to an int to store the actual distance in the event of a collision.
aLocation[out] an option pointer to a point to store a nearby location in the event of a collision.
Returns
true, if there is a collision.

Reimplemented from SHAPE_LINE_CHAIN_BASE.

◆ CPoint()

const VECTOR2I & SHAPE_SIMPLE::CPoint ( int  aIndex) const
inline

Return a const reference to a given point in the polygon.

Negative indices count from the end of the point list, e.g. -1 means "last point", -2 means "second to last point" and so on.

Parameters
aIndexis the index of the point.
Returns
the const reference to the point.

◆ GetPoint()

virtual const VECTOR2I SHAPE_SIMPLE::GetPoint ( int  aIndex) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

◆ GetPointCount()

virtual size_t SHAPE_SIMPLE::GetPointCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

◆ GetSegment()

virtual const SEG SHAPE_SIMPLE::GetSegment ( int  aIndex) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

◆ GetSegmentCount()

virtual size_t SHAPE_SIMPLE::GetSegmentCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

◆ IsClosed()

bool SHAPE_SIMPLE::IsClosed ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

◆ IsSolid()

bool SHAPE_SIMPLE::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

◆ Move()

void SHAPE_SIMPLE::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

◆ PointCount()

int SHAPE_SIMPLE::PointCount ( ) const
inline

Return the number of points (vertices) in this polygon.

Returns
number of points.

◆ Rotate()

void SHAPE_SIMPLE::Rotate ( double  aAngle,
const VECTOR2I aCenter = { 0, 0 } 
)
inlineoverridevirtual
Parameters
aCenteris the rotation center.
aAnglerotation angle in radians.

Implements SHAPE.

◆ Vertices()

const SHAPE_LINE_CHAIN & SHAPE_SIMPLE::Vertices ( ) const
inline

Return the list of vertices defining this simple polygon.

Returns
the list of vertices defining this simple polygon.

The documentation for this class was generated from the following file: