KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 (const EDA_ANGLE &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
 
void TransformToPolygon (SHAPE_POLY_SET &aBuffer, int aError, ERROR_LOC aErrorLoc) const override
 Fills a SHAPE_POLY_SET with a polygon representation of this shape.
 
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.
 
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
 
SEG::ecoord SquaredDistance (const VECTOR2I &aP, bool aOutlineOnly=false) const override
 
bool PointInside (const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const override
 Check if point aP lies inside a closed shape.
 
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
 
int GetClearance (const SHAPE *aOther) const
 Return the actual minimum distance between two shapes.
 
bool IsNull () const
 Return true if the shape is a null shape.
 
virtual VECTOR2I Centre () const
 Compute a center-of-mass of the shape.
 
virtual int Distance (const VECTOR2I &aP) const
 Returns the minimum distance from a given point to this shape.
 
virtual bool Parse (std::stringstream &aStream)
 
virtual const std::string Format (bool aCplusPlus=true) const
 
FACETNewFacet ()
 
SGNODECalcShape (SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
 
SHAPE_TYPE Type () const
 Return the type of the shape.
 
wxString TypeName () const
 
virtual bool HasIndexableSubshapes () const
 
virtual size_t GetIndexableSubshapeCount () const
 
virtual void GetIndexableSubshapes (std::vector< const SHAPE * > &aSubshapes) const
 

Static Public Attributes

static const int MIN_PRECISION_IU = 4
 This is the minimum precision for all the points in a shape.
 

Protected Types

typedef VECTOR2I::extended_type ecoord
 

Protected Attributes

SHAPE_TYPE m_type
 < type of our shape
 

Private Attributes

SHAPE_LINE_CHAIN m_points
 
std::list< FACET * > facets
 

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.

Definition at line 41 of file shape_simple.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 284 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_SIMPLE() [1/3]

SHAPE_SIMPLE::SHAPE_SIMPLE ( )
inline

Create an empty polygon.

Definition at line 47 of file shape_simple.h.

References m_points, and SHAPE_LINE_CHAIN::SetClosed().

Referenced by Clone().

◆ SHAPE_SIMPLE() [2/3]

SHAPE_SIMPLE::SHAPE_SIMPLE ( const SHAPE_LINE_CHAIN aPoly)
inline

Definition at line 53 of file shape_simple.h.

References m_points, and SHAPE_LINE_CHAIN::SetClosed().

◆ SHAPE_SIMPLE() [3/3]

SHAPE_SIMPLE::SHAPE_SIMPLE ( const SHAPE_SIMPLE aOther)
inline

Definition at line 60 of file shape_simple.h.

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.

Definition at line 146 of file shape_simple.h.

References SHAPE_LINE_CHAIN::Append(), and m_points.

◆ 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.

Definition at line 135 of file shape_simple.h.

References Append().

Referenced by Append(), EDA_TEXT::GetEffectiveTextShape(), PNS_KICAD_IFACE_BASE::syncTextItem(), and PNS_KICAD_IFACE_BASE::syncZone().

◆ 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.

Definition at line 78 of file shape_simple.h.

References SHAPE_LINE_CHAIN::BBox(), and m_points.

Referenced by PNS::ConvexHull(), and PNS::OPTIMIZER::customBreakouts().

◆ CalcShape()

◆ 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.

Definition at line 113 of file shape_simple.h.

References CPoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by ROUTER_PREVIEW_ITEM::drawShape().

◆ Centre()

virtual VECTOR2I SHAPE::Centre ( ) const
inlinevirtualinherited

Compute a center-of-mass of the shape.

Returns
the center-of-mass point

Definition at line 232 of file shape.h.

References SHAPE::BBox(), and BOX2< Vec >::Centre().

Referenced by PNS::TOPOLOGY::AssembleDiffPair(), Collide(), SCH_EASYEDA_PARSER::ParseSchematic(), and pickSegment().

◆ Clear()

void SHAPE_SIMPLE::Clear ( )
inline

Remove all points from the polygon.

Definition at line 72 of file shape_simple.h.

References SHAPE_LINE_CHAIN::Clear(), and m_points.

◆ Clone()

SHAPE * SHAPE_SIMPLE::Clone ( ) const
inlineoverridevirtual

Return a dynamically allocated copy of the shape.

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 64 of file shape_simple.h.

References SHAPE_SIMPLE().

◆ Collide() [1/4]

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.

Definition at line 152 of file shape_simple.h.

References SHAPE_LINE_CHAIN::Collide(), and m_points.

◆ Collide() [2/4]

bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance,
VECTOR2I aMTV 
) const
virtualinherited

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

Parameters
aShapeshape to check collision against
aClearanceminimum clearance
aMTV[out] minimum translation vector
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 in SHAPE_COMPOUND, SHAPE_RECT, and SHAPE_SEGMENT.

Definition at line 1172 of file shape_collisions.cpp.

References collideShapes().

◆ Collide() [3/4]

bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance = 0,
int *  aActual = nullptr,
VECTOR2I aLocation = nullptr 
) const
virtualinherited

Reimplemented in SHAPE_ARC, SHAPE_COMPOUND, SHAPE_POLY_SET, SHAPE_RECT, and SHAPE_SEGMENT.

Definition at line 1178 of file shape_collisions.cpp.

References collideShapes().

◆ Collide() [4/4]

bool SHAPE_LINE_CHAIN_BASE::Collide ( const VECTOR2I aP,
int  aClearance = 0,
int *  aActual = nullptr,
VECTOR2I aLocation = nullptr 
) const
overridevirtualinherited

Check if point aP lies closer to us than aClearance.

Parameters
aPthe point to check for collisions with
aClearanceminimum distance that does not qualify as a collision.
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, when a collision has been found

Reimplemented from SHAPE.

Reimplemented in SHAPE_LINE_CHAIN.

Definition at line 420 of file shape_line_chain.cpp.

References VECTOR2< int32_t >::ECOORD_MAX, SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SEG::NearestPoint(), SHAPE_LINE_CHAIN_BASE::PointInside(), and SEG::Square().

Referenced by Collide().

◆ 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.

Definition at line 102 of file shape_simple.h.

References SHAPE_LINE_CHAIN::CPoint(), and m_points.

Referenced by CDPoint(), and KIGFX::PCB_PAINTER::draw().

◆ Distance()

int SHAPE::Distance ( const VECTOR2I aP) const
virtualinherited

Returns the minimum distance from a given point to this shape.

Always returns zero if the point is inside a closed shape and aOutlineOnly is false.

Parameters
aPis the point to test
Returns
the distance from the shape to aP

Reimplemented in SHAPE_COMPOUND, and SHAPE_LINE_CHAIN.

Definition at line 108 of file shape.cpp.

References SHAPE::SquaredDistance().

◆ EdgeContainingPoint()

int SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint ( const VECTOR2I aP,
int  aAccuracy = 0 
) const
inherited

Check if point aP lies on an edge or vertex of the line chain.

Parameters
aPpoint to check
Returns
index of the first edge containing the point, otherwise negative

Definition at line 1990 of file shape_line_chain.cpp.

References SEG::A, SEG::B, SEG::Distance(), SHAPE_LINE_CHAIN_BASE::GetPoint(), SHAPE_LINE_CHAIN_BASE::GetPointCount(), SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SHAPE_LINE_CHAIN_BASE::PointOnEdge().

◆ Format()

const std::string SHAPE::Format ( bool  aCplusPlus = true) const
virtualinherited

◆ GetCachedBBox()

virtual BOX2I * SHAPE_LINE_CHAIN_BASE::GetCachedBBox ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_LINE_CHAIN.

Definition at line 351 of file shape.h.

Referenced by SHAPE_LINE_CHAIN_BASE::PointInside().

◆ GetClearance()

int SHAPE::GetClearance ( const SHAPE aOther) const
inherited

Return the actual minimum distance between two shapes.

Return values
distancein IU

POLY_SETs contain a bunch of polygons that are triangulated. But there are way more triangles than necessary for collision detection. Triangles check three vertices each but for the outline, we only need one. These are also fractured, so we don't need to worry about holes

Definition at line 54 of file shape.cpp.

References SHAPE_POLY_SET::COutline(), SHAPE_BASE::GetIndexableSubshapeCount(), SHAPE_BASE::GetIndexableSubshapes(), SHAPE_POLY_SET::OutlineCount(), and SHAPE_BASE::Type().

◆ GetIndexableSubshapeCount()

virtual size_t SHAPE_BASE::GetIndexableSubshapeCount ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_COMPOUND, and SHAPE_POLY_SET.

Definition at line 113 of file shape.h.

Referenced by SHAPE::GetClearance().

◆ GetIndexableSubshapes()

virtual void SHAPE_BASE::GetIndexableSubshapes ( std::vector< const SHAPE * > &  aSubshapes) const
inlinevirtualinherited

Reimplemented in SHAPE_COMPOUND, and SHAPE_POLY_SET.

Definition at line 115 of file shape.h.

Referenced by SHAPE_COMPOUND::AddShape(), SHAPE::GetClearance(), and ROUTER_PREVIEW_ITEM::ViewDraw().

◆ GetPoint()

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

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 173 of file shape_simple.h.

References SHAPE_LINE_CHAIN::CPoint(), and m_points.

◆ GetPointCount()

virtual size_t SHAPE_SIMPLE::GetPointCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 175 of file shape_simple.h.

References m_points, and SHAPE_LINE_CHAIN::PointCount().

◆ GetSegment()

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

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 174 of file shape_simple.h.

References SHAPE_LINE_CHAIN::CSegment(), and m_points.

Referenced by KIGFX::PCB_PAINTER::draw(), and STROKE_PARAMS::Stroke().

◆ GetSegmentCount()

virtual size_t SHAPE_SIMPLE::GetSegmentCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 176 of file shape_simple.h.

References m_points, and SHAPE_LINE_CHAIN::SegmentCount().

Referenced by KIGFX::PCB_PAINTER::draw(), and STROKE_PARAMS::Stroke().

◆ HasIndexableSubshapes()

virtual bool SHAPE_BASE::HasIndexableSubshapes ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_COMPOUND, and SHAPE_POLY_SET.

Definition at line 108 of file shape.h.

Referenced by ROUTER_PREVIEW_ITEM::ViewDraw().

◆ IsClosed()

bool SHAPE_SIMPLE::IsClosed ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 178 of file shape_simple.h.

◆ IsNull()

bool SHAPE::IsNull ( ) const
inlineinherited

Return true if the shape is a null shape.

Return values
trueif null :-)

Definition at line 166 of file shape.h.

References SHAPE_BASE::m_type, and SH_NULL.

◆ IsSolid()

bool SHAPE_SIMPLE::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 168 of file shape_simple.h.

◆ Move()

void SHAPE_SIMPLE::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 163 of file shape_simple.h.

References m_points, and SHAPE_LINE_CHAIN::Move().

◆ NewFacet()

FACET * SHAPE::NewFacet ( )
inherited

◆ Parse()

bool SHAPE::Parse ( std::stringstream &  aStream)
virtualinherited

Reimplemented in SHAPE_LINE_CHAIN, and SHAPE_POLY_SET.

Definition at line 39 of file shape.cpp.

◆ PointCount()

int SHAPE_SIMPLE::PointCount ( ) const
inline

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

Returns
number of points.

Definition at line 88 of file shape_simple.h.

References m_points, and SHAPE_LINE_CHAIN::PointCount().

Referenced by KIGFX::PCB_PAINTER::draw(), and ROUTER_PREVIEW_ITEM::drawShape().

◆ PointInside()

bool SHAPE_LINE_CHAIN_BASE::PointInside ( const VECTOR2I aPt,
int  aAccuracy = 0,
bool  aUseBBoxCache = false 
) const
overridevirtualinherited

◆ PointOnEdge()

bool SHAPE_LINE_CHAIN_BASE::PointOnEdge ( const VECTOR2I aP,
int  aAccuracy = 0 
) const
inherited

Check if point aP lies on an edge or vertex of the line chain.

Parameters
aPpoint to check
Returns
true if the point lies on the edge.

Definition at line 1984 of file shape_line_chain.cpp.

References SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint().

Referenced by getPNSLine(), PCB_TUNING_PATTERN::initBaseLine(), FABMASTER::loadZones(), SHAPE_LINE_CHAIN_BASE::PointInside(), PNS::LINE_PLACER::splitHeadTail(), and PNS::LINE::Walkaround().

◆ Rotate()

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

Implements SHAPE.

Definition at line 158 of file shape_simple.h.

◆ SquaredDistance()

SEG::ecoord SHAPE_LINE_CHAIN_BASE::SquaredDistance ( const VECTOR2I aP,
bool  aOutlineOnly = false 
) const
overridevirtualinherited

◆ TransformToPolygon()

void SHAPE_SIMPLE::TransformToPolygon ( SHAPE_POLY_SET aBuffer,
int  aError,
ERROR_LOC  aErrorLoc 
) const
overridevirtual

Fills a SHAPE_POLY_SET with a polygon representation of this shape.

Parameters
aBuffer[out] will be filled with the polygonal representation of this shape.
aErrorcontrols the maximum allowed deviation when converting rounded shapes to segments
aErrorLoccontrols where the error is placed when approximating rounded shapes

Reimplemented from SHAPE_LINE_CHAIN_BASE.

Definition at line 138 of file shape.cpp.

References SHAPE_POLY_SET::AddOutline(), and m_points.

◆ Type()

◆ TypeName()

wxString SHAPE_BASE::TypeName ( ) const
inlineinherited

Definition at line 103 of file shape.h.

References SHAPE_BASE::m_type, and SHAPE_TYPE_asString().

Referenced by Collide().

◆ 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.

Definition at line 124 of file shape_simple.h.

References m_points.

Referenced by PNS::ConvexHull(), BOARD_ADAPTER::createPadWithMargin(), PNS::OPTIMIZER::customBreakouts(), and KIGFX::PCB_PAINTER::draw().

Member Data Documentation

◆ facets

std::list< FACET* > SHAPE::facets
privateinherited

Definition at line 143 of file wrlfacet.h.

Referenced by SHAPE::CalcShape(), and SHAPE::NewFacet().

◆ m_points

◆ m_type

SHAPE_TYPE SHAPE_BASE::m_type
protectedinherited

< type of our shape

Definition at line 119 of file shape.h.

Referenced by SHAPE::Format(), SHAPE::IsNull(), SHAPE_BASE::Type(), and SHAPE_BASE::TypeName().

◆ MIN_PRECISION_IU

const int SHAPE::MIN_PRECISION_IU = 4
staticinherited

This is the minimum precision for all the points in a shape.

Definition at line 131 of file shape.h.

Referenced by BOOST_AUTO_TEST_CASE(), DIRECTION_45::BuildInitialTrace(), CompareLength(), CIRCLE::Contains(), EDIT_TOOL::FilletTracks(), CIRCLE::IntersectLine(), and LINE_FILLET_ROUTINE::ProcessLinePair().


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