KiCad PCB EDA Suite
SHAPE_CONVEX Class Reference

Class SHAPE_CONVEX. More...

#include <shape_convex.h>

Inheritance diagram for SHAPE_CONVEX:
SHAPE

Public Member Functions

 SHAPE_CONVEX ()
 Constructor Creates an empty polygon. More...
 
 SHAPE_CONVEX (const SHAPE_CONVEX &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_CONVEX.

Represents a convex 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_convex.h.

Member Typedef Documentation

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 60 of file shape.h.

Constructor & Destructor Documentation

SHAPE_CONVEX::SHAPE_CONVEX ( )
inline

Constructor Creates an empty polygon.

Definition at line 49 of file shape_convex.h.

References m_points, and SHAPE_LINE_CHAIN::SetClosed().

Referenced by Clone().

49  :
50  SHAPE( SH_CONVEX )
51  {
52  m_points.SetClosed( true );
53  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:69
void SetClosed(bool aClosed)
Function SetClosed()
SHAPE_LINE_CHAIN m_points
Definition: shape_convex.h:186
circle
Definition: shape.h:47
SHAPE_CONVEX::SHAPE_CONVEX ( const SHAPE_CONVEX aOther)
inline

Definition at line 55 of file shape_convex.h.

55  :
56  SHAPE( SH_CONVEX ), m_points( aOther.m_points )
57  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:69
SHAPE_LINE_CHAIN m_points
Definition: shape_convex.h:186
circle
Definition: shape.h:47

Member Function Documentation

void SHAPE_CONVEX::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_convex.h.

Referenced by PNS_KICAD_IFACE::syncPad().

152  {
153  VECTOR2I v( aX, aY );
154  Append( v );
155  }
void Append(int aX, int aY)
Function Append()
Definition: shape_convex.h:151
void SHAPE_CONVEX::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_convex.h.

References SHAPE_LINE_CHAIN::Append(), and m_points.

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_convex.h:186
const BOX2I SHAPE_CONVEX::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_convex.h.

References SHAPE_LINE_CHAIN::BBox(), and m_points.

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

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_convex.h:186
const VECTOR2D SHAPE_CONVEX::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_convex.h.

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

Referenced by ROUTER_PREVIEW_ITEM::ViewDraw().

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_convex.h:113
VECTOR2< double > VECTOR2D
Definition: vector2d.h:588
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 150 of file shape.h.

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

151  {
152  return BBox( 0 ).Centre(); // if nothing better is available....
153  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:67
void SHAPE_CONVEX::Clear ( )
inline

Function Clear() Removes all points from the polygon.

Definition at line 68 of file shape_convex.h.

References SHAPE_LINE_CHAIN::Clear(), and m_points.

69  {
70  m_points.Clear();
71  }
SHAPE_LINE_CHAIN m_points
Definition: shape_convex.h:186
void Clear()
Function Clear() Removes all points from the line chain.
SHAPE* SHAPE_CONVEX::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_convex.h.

References SHAPE_CONVEX().

60  {
61  return new SHAPE_CONVEX( *this );
62  }
SHAPE_CONVEX()
Constructor Creates an empty polygon.
Definition: shape_convex.h:49
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, and SHAPE_SEGMENT.

Definition at line 106 of file shape.h.

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

107  {
108  return Collide( SEG( aP, aP ), aClearance );
109  }
virtual bool Collide(const VECTOR2I &aP, int aClearance=0) const
Function Collide()
Definition: shape.h:106
Definition: seg.h:36
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 456 of file shape_collisions.cpp.

References CollideShapes().

457 {
458  return CollideShapes( this, aShape, aClerance, true, aMTV );
459 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance = 0 
) const
virtualinherited

Definition at line 462 of file shape_collisions.cpp.

References CollideShapes(), and dummy().

463 {
464  VECTOR2I dummy;
465 
466  return CollideShapes( this, aShape, aClerance, false, dummy );
467 }
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)
bool SHAPE_CONVEX::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_convex.h.

References SHAPE_LINE_CHAIN::Collide(), and m_points.

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_convex.h:186
const VECTOR2I& SHAPE_CONVEX::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_convex.h.

References SHAPE_LINE_CHAIN::CPoint(), and m_points.

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

114  {
115  return m_points.CPoint( aIndex );
116  }
SHAPE_LINE_CHAIN m_points
Definition: shape_convex.h:186
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
const std::string SHAPE::Format ( ) const
virtualinherited

Reimplemented in SHAPE_POLY_SET, and SHAPE_LINE_CHAIN.

Definition at line 35 of file shape.cpp.

Referenced by SHAPE_FILE_IO::Write().

36 {
37  assert( false );
38  return std::string( "" );
39 }
bool SHAPE_CONVEX::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 179 of file shape_convex.h.

180  {
181  return true;
182  }
void SHAPE_CONVEX::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 174 of file shape_convex.h.

References m_points, and SHAPE_LINE_CHAIN::Move().

175  {
176  m_points.Move( aVector );
177  }
void Move(const VECTOR2I &aVector) override
SHAPE_LINE_CHAIN m_points
Definition: shape_convex.h:186
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 }
VECTOR2I& SHAPE_CONVEX::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_convex.h.

References m_points, and SHAPE_LINE_CHAIN::Point().

100  {
101  return m_points.Point( aIndex );
102  }
SHAPE_LINE_CHAIN m_points
Definition: shape_convex.h:186
VECTOR2I & Point(int aIndex)
Function Point()
int SHAPE_CONVEX::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_convex.h.

References m_points, and SHAPE_LINE_CHAIN::PointCount().

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

86  {
87  return m_points.PointCount();
88  }
int PointCount() const
Function PointCount()
SHAPE_LINE_CHAIN m_points
Definition: shape_convex.h:186
SHAPE_TYPE SHAPE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 82 of file shape.h.

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().

83  {
84  return m_type;
85  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:165
const SHAPE_LINE_CHAIN& SHAPE_CONVEX::Vertices ( ) const
inline

Function Vertices()

Returns the list of vertices defining this convex polygon.

Returns
the list of vertices defining this convex polygon

Definition at line 139 of file shape_convex.h.

References m_points.

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

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

Member Data Documentation

SHAPE_LINE_CHAIN SHAPE_CONVEX::m_points
private
SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 165 of file shape.h.

Referenced by SHAPE::Type().


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