KiCad PCB EDA Suite
SHAPE_SIMPLE Class Reference

Class SHAPE_SIMPLE. More...

#include <shape_simple.h>

Inheritance diagram for SHAPE_SIMPLE:
SHAPE

Public Member Functions

 SHAPE_SIMPLE ()
 Constructor Creates an empty polygon. More...
 
 SHAPE_SIMPLE (const SHAPE_SIMPLE &aOther)
 
SHAPEClone () const override
 Function Clone() More...
 
void Clear ()
 Function Clear() Removes all points from the polygon. More...
 
const BOX2I BBox (int aClearance=0) const override
 Function BBox() More...
 
int PointCount () const
 Function PointCount() More...
 
VECTOR2IPoint (int aIndex)
 Function Point() More...
 
const VECTOR2ICPoint (int aIndex) const
 Function CPoint() More...
 
const VECTOR2D CDPoint (int aIndex) const
 Function CDPoint() More...
 
const SHAPE_LINE_CHAINVertices () const
 Function Vertices() More...
 
void Append (int aX, int aY)
 Function Append() More...
 
void Append (const VECTOR2I &aP)
 Function Append() More...
 
bool Collide (const SEG &aSeg, int aClearance=0) const override
 Function Collide() More...
 
void Move (const VECTOR2I &aVector) override
 
bool IsSolid () const override
 
SHAPE_TYPE Type () const
 Function Type() More...
 
virtual bool Collide (const VECTOR2I &aP, int aClearance=0) const
 Function Collide() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I &aMTV) const
 Function Collide() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance=0) const
 
virtual VECTOR2I Centre () const
 Function Centre() More...
 
virtual bool Parse (std::stringstream &aStream)
 
virtual const std::string Format () const
 

Protected Types

typedef VECTOR2I::extended_type ecoord
 

Protected Attributes

SHAPE_TYPE m_type
 

type of our shape

More...
 

Private Attributes

SHAPE_LINE_CHAIN m_points
 

Detailed Description

Class SHAPE_SIMPLE.

Represents 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 42 of file shape_simple.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 61 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_SIMPLE() [1/2]

SHAPE_SIMPLE::SHAPE_SIMPLE ( )
inline

Constructor Creates an empty polygon.

Definition at line 49 of file shape_simple.h.

49  :
50  SHAPE( SH_SIMPLE )
51  {
52  m_points.SetClosed( true );
53  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
void SetClosed(bool aClosed)
Function SetClosed()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186
circle
Definition: shape.h:47

References m_points, and SHAPE_LINE_CHAIN::SetClosed().

Referenced by Clone().

◆ SHAPE_SIMPLE() [2/2]

SHAPE_SIMPLE::SHAPE_SIMPLE ( const SHAPE_SIMPLE aOther)
inline

Definition at line 55 of file shape_simple.h.

55  :
56  SHAPE( SH_SIMPLE ), m_points( aOther.m_points )
57  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186
circle
Definition: shape.h:47

Member Function Documentation

◆ Append() [1/2]

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

Function Append()

Appends 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 151 of file shape_simple.h.

152  {
153  VECTOR2I v( aX, aY );
154  Append( v );
155  }
void Append(int aX, int aY)
Function Append()
Definition: shape_simple.h:151

Referenced by PNS_KICAD_IFACE::syncPad(), and PNS_KICAD_IFACE::syncZone().

◆ Append() [2/2]

void SHAPE_SIMPLE::Append ( const VECTOR2I aP)
inline

Function Append()

Appends a new point at the end of the polygon.

Parameters
aPthe new point

Definition at line 163 of file shape_simple.h.

164  {
165  m_points.Append( aP );
166  }
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186

References SHAPE_LINE_CHAIN::Append(), and m_points.

◆ BBox()

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

Function BBox()

Computes 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 74 of file shape_simple.h.

75  {
76  return m_points.BBox( aClearance );
77  }
const BOX2I BBox(int aClearance=0) const override
Function BBox()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186

References SHAPE_LINE_CHAIN::BBox(), and m_points.

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

◆ CDPoint()

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

Function CDPoint()

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

Parameters
aIndexindex of the point
Returns
the point with elements of type double

Definition at line 126 of file shape_simple.h.

127  {
128  const VECTOR2I& v = CPoint( aIndex );
129  return VECTOR2D( v.x, v.y );
130  }
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
Definition: shape_simple.h:113
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586

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

Referenced by ROUTER_PREVIEW_ITEM::ViewDraw().

◆ Centre()

virtual VECTOR2I SHAPE::Centre ( ) const
inlinevirtualinherited

Function Centre()

Computes a center-of-mass of the shape

Returns
the center-of-mass point

Definition at line 151 of file shape.h.

152  {
153  return BBox( 0 ).Centre(); // if nothing better is available....
154  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:77

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

◆ Clear()

void SHAPE_SIMPLE::Clear ( )
inline

Function Clear() Removes all points from the polygon.

Definition at line 68 of file shape_simple.h.

69  {
70  m_points.Clear();
71  }
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186
void Clear()
Function Clear() Removes all points from the line chain.

References SHAPE_LINE_CHAIN::Clear(), and m_points.

◆ Clone()

SHAPE* SHAPE_SIMPLE::Clone ( ) const
inlineoverridevirtual

Function Clone()

Returns a dynamically allocated copy of the shape

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 59 of file shape_simple.h.

60  {
61  return new SHAPE_SIMPLE( *this );
62  }
SHAPE_SIMPLE()
Constructor Creates an empty polygon.
Definition: shape_simple.h:49

References SHAPE_SIMPLE().

◆ Collide() [1/4]

virtual bool SHAPE::Collide ( const VECTOR2I aP,
int  aClearance = 0 
) const
inlinevirtualinherited

Function Collide()

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

Returns
true, if there is a collision.

Reimplemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN, SHAPE_ARC, and SHAPE_SEGMENT.

Definition at line 107 of file shape.h.

108  {
109  return Collide( SEG( aP, aP ), aClearance );
110  }
virtual bool Collide(const VECTOR2I &aP, int aClearance=0) const
Function Collide()
Definition: shape.h:107
Definition: seg.h:36

Referenced by collide(), PNS::ITEM::collideSimple(), and PNS::HIT_VISITOR::operator()().

◆ Collide() [2/4]

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

Function Collide()

Checks 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
aMTVminimum translation vector
Returns
true, if there is a collision.

Definition at line 545 of file shape_collisions.cpp.

546 {
547  return CollideShapes( this, aShape, aClearance, true, aMTV );
548 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

References CollideShapes().

◆ Collide() [3/4]

bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance = 0 
) const
virtualinherited

Definition at line 551 of file shape_collisions.cpp.

552 {
553  VECTOR2I dummy;
554 
555  return CollideShapes( this, aShape, aClearance, false, dummy );
556 }
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

References CollideShapes(), and dummy().

◆ Collide() [4/4]

bool SHAPE_SIMPLE::Collide ( const SEG aSeg,
int  aClearance = 0 
) const
inlineoverridevirtual

Function Collide()

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

Returns
true, if there is a collision.

Implements SHAPE.

Definition at line 169 of file shape_simple.h.

170  {
171  return m_points.Collide( aSeg, aClearance );
172  }
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186

References SHAPE_LINE_CHAIN::Collide(), and m_points.

◆ CPoint()

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

Function CPoint()

Returns 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
aIndexindex of the point
Returns
const reference to the point

Definition at line 113 of file shape_simple.h.

114  {
115  return m_points.CPoint( aIndex );
116  }
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186

References SHAPE_LINE_CHAIN::CPoint(), and m_points.

Referenced by CDPoint(), and PNS::LOGGER::dumpShape().

◆ Format()

const std::string SHAPE::Format ( ) const
virtualinherited

Reimplemented in SHAPE_POLY_SET, and SHAPE_LINE_CHAIN.

Definition at line 35 of file shape.cpp.

36 {
37  assert( false );
38  return std::string( "" );
39 }

Referenced by SHAPE_FILE_IO::Write().

◆ IsSolid()

bool SHAPE_SIMPLE::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 179 of file shape_simple.h.

180  {
181  return true;
182  }

◆ Move()

void SHAPE_SIMPLE::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 174 of file shape_simple.h.

175  {
176  m_points.Move( aVector );
177  }
void Move(const VECTOR2I &aVector) override
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186

References m_points, and SHAPE_LINE_CHAIN::Move().

◆ Parse()

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

Reimplemented in SHAPE_POLY_SET, and SHAPE_LINE_CHAIN.

Definition at line 28 of file shape.cpp.

29 {
30  assert( false );
31  return false;
32 }

◆ Point()

VECTOR2I& SHAPE_SIMPLE::Point ( int  aIndex)
inline

Function Point()

Returns a 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
aIndexindex of the point
Returns
reference to the point

Definition at line 99 of file shape_simple.h.

100  {
101  return m_points.Point( aIndex );
102  }
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186
VECTOR2I & Point(int aIndex)
Function Point()

References m_points, and SHAPE_LINE_CHAIN::Point().

◆ PointCount()

int SHAPE_SIMPLE::PointCount ( ) const
inline

Function PointCount()

Returns the number of points (vertices) in this polygon

Returns
number of points

Definition at line 85 of file shape_simple.h.

86  {
87  return m_points.PointCount();
88  }
int PointCount() const
Function PointCount()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186

References m_points, and SHAPE_LINE_CHAIN::PointCount().

Referenced by PNS::LOGGER::dumpShape(), and ROUTER_PREVIEW_ITEM::ViewDraw().

◆ Type()

SHAPE_TYPE SHAPE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 83 of file shape.h.

84  {
85  return m_type;
86  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:166

References SHAPE::m_type.

Referenced by PNS::DP_GATEWAYS::BuildFromPrimitivePair(), CollideShapes(), PNS::OPTIMIZER::computeBreakouts(), PNS::LOGGER::dumpShape(), PNS::SOLID::Hull(), ROUTER_PREVIEW_ITEM::ViewDraw(), and SHAPE_FILE_IO::Write().

◆ Vertices()

const SHAPE_LINE_CHAIN& SHAPE_SIMPLE::Vertices ( ) const
inline

Function Vertices()

Returns the list of vertices defining this simple polygon.

Returns
the list of vertices defining this simple polygon

Definition at line 139 of file shape_simple.h.

140  {
141  return m_points;
142  }
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:186

References m_points.

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

Member Data Documentation

◆ m_points

SHAPE_LINE_CHAIN SHAPE_SIMPLE::m_points
private

◆ m_type

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 166 of file shape.h.

Referenced by SHAPE::Type().


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