KiCad PCB EDA Suite
SHAPE_RECT Class Reference

#include <shape_rect.h>

Inheritance diagram for SHAPE_RECT:
SHAPE

Public Member Functions

 SHAPE_RECT ()
 Constructor Creates an empty (0-sized) rectangle. More...
 
 SHAPE_RECT (int aX0, int aY0, int aW, int aH)
 Constructor Creates a rectangle defined by top-left corner (aX0, aY0), width aW and height aH. More...
 
 SHAPE_RECT (const VECTOR2I &aP0, int aW, int aH)
 Constructor Creates a rectangle defined by top-left corner aP0, width aW and height aH. More...
 
 SHAPE_RECT (const SHAPE_RECT &aOther)
 
SHAPEClone () const override
 Function Clone() More...
 
const BOX2I BBox (int aClearance=0) const override
 Function BBox() More...
 
int Diagonal () const
 Function Diagonal() More...
 
bool Collide (const SEG &aSeg, int aClearance=0) const override
 Function Collide() More...
 
const VECTOR2IGetPosition () const
 Function GetPosition() More...
 
const VECTOR2I GetSize () const
 Function GetSize() More...
 
const int GetWidth () const
 Function GetWidth() More...
 
const int GetHeight () const
 Function GetHeight() More...
 
void Move (const VECTOR2I &aVector) override
 
bool IsSolid () const override
 
const SHAPE_LINE_CHAIN Outline () const
 
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

VECTOR2I m_p0
 

Top-left corner

More...
 
int m_w
 

Width

More...
 
int m_h
 

Height

More...
 

Detailed Description

Definition at line 33 of file shape_rect.h.

Member Typedef Documentation

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 60 of file shape.h.

Constructor & Destructor Documentation

SHAPE_RECT::SHAPE_RECT ( )
inline

Constructor Creates an empty (0-sized) rectangle.

Definition at line 40 of file shape_rect.h.

Referenced by Clone().

40  :
41  SHAPE( SH_RECT ), m_w( 0 ), m_h( 0 )
42  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:69
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
Definition: shape.h:43
SHAPE_RECT::SHAPE_RECT ( int  aX0,
int  aY0,
int  aW,
int  aH 
)
inline

Constructor Creates a rectangle defined by top-left corner (aX0, aY0), width aW and height aH.

Definition at line 48 of file shape_rect.h.

48  :
49  SHAPE( SH_RECT ), m_p0( aX0, aY0 ), m_w( aW ), m_h( aH )
50  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:69
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
Definition: shape.h:43
SHAPE_RECT::SHAPE_RECT ( const VECTOR2I aP0,
int  aW,
int  aH 
)
inline

Constructor Creates a rectangle defined by top-left corner aP0, width aW and height aH.

Definition at line 56 of file shape_rect.h.

56  :
57  SHAPE( SH_RECT ), m_p0( aP0 ), m_w( aW ), m_h( aH )
58  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:69
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
Definition: shape.h:43
SHAPE_RECT::SHAPE_RECT ( const SHAPE_RECT aOther)
inline

Definition at line 60 of file shape_rect.h.

60  :
61  SHAPE( SH_RECT ),
62  m_p0( aOther.m_p0 ),
63  m_w( aOther.m_w ),
64  m_h( aOther.m_h )
65  {};
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:69
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
Definition: shape.h:43

Member Function Documentation

const BOX2I SHAPE_RECT::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 73 of file shape_rect.h.

References m_h, m_p0, m_w, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Collide().

74  {
75  BOX2I bbox( VECTOR2I( m_p0.x - aClearance, m_p0.y - aClearance ),
76  VECTOR2I( m_w + 2 * aClearance, m_h + 2 * aClearance ) );
77  //printf("bb : %s\n",bbox.Format().c_str());
78  return bbox;
79  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
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
SHAPE* SHAPE_RECT::Clone ( ) const
inlineoverridevirtual

Function Clone()

Returns a dynamically allocated copy of the shape

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 67 of file shape_rect.h.

References SHAPE_RECT().

68  {
69  return new SHAPE_RECT( *this );
70  }
SHAPE_RECT()
Constructor Creates an empty (0-sized) rectangle.
Definition: shape_rect.h:40
bool SHAPE_RECT::Collide ( const SEG aSeg,
int  aClearance = 0 
) const
overridevirtual

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 470 of file shape_collisions.cpp.

References SEG::A, SEG::B, BBox(), SEG::Distance(), m_h, m_p0, m_w, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Collide().

471 {
472  //VECTOR2I pmin = VECTOR2I( std::min( aSeg.a.x, aSeg.b.x ), std::min( aSeg.a.y, aSeg.b.y ) );
473  //VECTOR2I pmax = VECTOR2I( std::max( aSeg.a.x, aSeg.b.x ), std::max( aSeg.a.y, aSeg.b.y ));
474  //BOX2I r( pmin, VECTOR2I( pmax.x - pmin.x, pmax.y - pmin.y ) );
475 
476  //if( BBox( 0 ).SquaredDistance( r ) > aClearance * aClearance )
477  // return false;
478 
479  if( BBox( 0 ).Contains( aSeg.A ) || BBox( 0 ).Contains( aSeg.B ) )
480  return true;
481 
482  VECTOR2I vts[] = { VECTOR2I( m_p0.x, m_p0.y ),
483  VECTOR2I( m_p0.x, m_p0.y + m_h ),
484  VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ),
485  VECTOR2I( m_p0.x + m_w, m_p0.y ),
486  VECTOR2I( m_p0.x, m_p0.y ) };
487 
488  for( int i = 0; i < 4; i++ )
489  {
490  SEG s( vts[i], vts[i + 1], i );
491 
492  if( s.Distance( aSeg ) < aClearance )
493  return true;
494  }
495 
496  return false;
497 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
Definition: seg.h:37
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_rect.h:73
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48
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:37
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)
int SHAPE_RECT::Diagonal ( ) const
inline

Function Diagonal()

Returns length of the diagonal of the rectangle

Returns
diagonal length

Definition at line 87 of file shape_rect.h.

References VECTOR2< T >::EuclideanNorm(), m_h, and m_w.

88  {
89  return VECTOR2I( m_w, m_h ).EuclideanNorm();
90  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:295
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
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 }
const int SHAPE_RECT::GetHeight ( ) const
inline

Function GetHeight()

Returns
height of the rectangle

Definition at line 130 of file shape_rect.h.

References m_h.

131  {
132  return m_h;
133  }
int m_h
Height
Definition: shape_rect.h:165
const VECTOR2I& SHAPE_RECT::GetPosition ( ) const
inline

Function GetPosition()

Returns
top-left corner of the rectangle

Definition at line 100 of file shape_rect.h.

References m_p0.

Referenced by Collide(), PNS::LOGGER::dumpShape(), PNS::SOLID::Hull(), PNS::OPTIMIZER::rectBreakouts(), and ROUTER_PREVIEW_ITEM::ViewDraw().

101  {
102  return m_p0;
103  }
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159
const VECTOR2I SHAPE_RECT::GetSize ( ) const
inline

Function GetSize()

Returns
size of the rectangle

Definition at line 110 of file shape_rect.h.

References m_h, and m_w.

Referenced by Collide(), PNS::LOGGER::dumpShape(), PNS::SOLID::Hull(), PNS::OPTIMIZER::rectBreakouts(), and ROUTER_PREVIEW_ITEM::ViewDraw().

111  {
112  return VECTOR2I( m_w, m_h );
113  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
const int SHAPE_RECT::GetWidth ( void  ) const
inline

Function GetWidth()

Returns
width of the rectangle

Definition at line 120 of file shape_rect.h.

References m_w.

121  {
122  return m_w;
123  }
int m_w
Width
Definition: shape_rect.h:162
bool SHAPE_RECT::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 140 of file shape_rect.h.

141  {
142  return true;
143  }
void SHAPE_RECT::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 135 of file shape_rect.h.

References m_p0.

136  {
137  m_p0 += aVector;
138  }
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159
const SHAPE_LINE_CHAIN SHAPE_RECT::Outline ( ) const
inline

Definition at line 145 of file shape_rect.h.

References SHAPE_LINE_CHAIN::Append(), m_h, m_p0, m_w, SHAPE_LINE_CHAIN::SetClosed(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Collide(), and D_PAD::MergePrimitivesAsPolygon().

146  {
147  SHAPE_LINE_CHAIN rv;
148  rv.Append( m_p0 );
149  rv.Append( m_p0.x, m_p0.y + m_h );
150  rv.Append( m_p0.x + m_w, m_p0.y + m_h );
151  rv.Append( m_p0.x + m_w, m_p0.y );
152  rv.Append( m_p0 );
153  rv.SetClosed( true );
154  return rv;
155  }
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void SetClosed(bool aClosed)
Function SetClosed()
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
Class SHAPE_LINE_CHAIN.
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 }
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

Member Data Documentation

int SHAPE_RECT::m_h
private

Height

Definition at line 165 of file shape_rect.h.

Referenced by BBox(), Collide(), Diagonal(), GetHeight(), GetSize(), and Outline().

VECTOR2I SHAPE_RECT::m_p0
private

Top-left corner

Definition at line 159 of file shape_rect.h.

Referenced by BBox(), Collide(), GetPosition(), Move(), and Outline().

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 165 of file shape.h.

Referenced by SHAPE::Type().

int SHAPE_RECT::m_w
private

Width

Definition at line 162 of file shape_rect.h.

Referenced by BBox(), Collide(), Diagonal(), GetSize(), GetWidth(), and Outline().


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