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

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 61 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_RECT() [1/4]

SHAPE_RECT::SHAPE_RECT ( )
inline

Constructor Creates an empty (0-sized) rectangle.

Definition at line 40 of file shape_rect.h.

40  :
41  SHAPE( SH_RECT ), m_w( 0 ), m_h( 0 )
42  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
Definition: shape.h:43

Referenced by Clone().

◆ SHAPE_RECT() [2/4]

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:70
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() [3/4]

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:70
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() [4/4]

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:70
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

◆ BBox()

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.

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:587
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

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

Referenced by Collide().

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

◆ Clone()

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.

68  {
69  return new SHAPE_RECT( *this );
70  }
SHAPE_RECT()
Constructor Creates an empty (0-sized) rectangle.
Definition: shape_rect.h:40

References SHAPE_RECT().

◆ Collide() [1/4]

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

560 {
561  //VECTOR2I pmin = VECTOR2I( std::min( aSeg.a.x, aSeg.b.x ), std::min( aSeg.a.y, aSeg.b.y ) );
562  //VECTOR2I pmax = VECTOR2I( std::max( aSeg.a.x, aSeg.b.x ), std::max( aSeg.a.y, aSeg.b.y ));
563  //BOX2I r( pmin, VECTOR2I( pmax.x - pmin.x, pmax.y - pmin.y ) );
564 
565  //if( BBox( 0 ).SquaredDistance( r ) > aClearance * aClearance )
566  // return false;
567 
568  if( BBox( 0 ).Contains( aSeg.A ) || BBox( 0 ).Contains( aSeg.B ) )
569  return true;
570 
571  VECTOR2I vts[] = { VECTOR2I( m_p0.x, m_p0.y ),
572  VECTOR2I( m_p0.x, m_p0.y + m_h ),
573  VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ),
574  VECTOR2I( m_p0.x + m_w, m_p0.y ),
575  VECTOR2I( m_p0.x, m_p0.y ) };
576 
577  for( int i = 0; i < 4; i++ )
578  {
579  SEG s( vts[i], vts[i + 1], i );
580 
581  if( s.Distance( aSeg ) < aClearance )
582  return true;
583  }
584 
585  return false;
586 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
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:36
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_rect.h:73
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:44
VECTOR2I B
Definition: seg.h:45

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

Referenced by Collide().

◆ Collide() [2/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() [3/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() [4/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().

◆ Diagonal()

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.

88  {
89  return VECTOR2I( m_w, m_h ).EuclideanNorm();
90  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:292

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

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

◆ GetHeight()

const int SHAPE_RECT::GetHeight ( ) const
inline

Function GetHeight()

Returns
height of the rectangle

Definition at line 130 of file shape_rect.h.

131  {
132  return m_h;
133  }
int m_h
Height
Definition: shape_rect.h:165

References m_h.

◆ GetPosition()

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.

101  {
102  return m_p0;
103  }
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159

References m_p0.

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

◆ GetSize()

const VECTOR2I SHAPE_RECT::GetSize ( ) const
inline

Function GetSize()

Returns
size of the rectangle

Definition at line 110 of file shape_rect.h.

111  {
112  return VECTOR2I( m_w, m_h );
113  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
int m_h
Height
Definition: shape_rect.h:165
int m_w
Width
Definition: shape_rect.h:162

References m_h, and m_w.

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

◆ GetWidth()

const int SHAPE_RECT::GetWidth ( ) const
inline

Function GetWidth()

Returns
width of the rectangle

Definition at line 120 of file shape_rect.h.

121  {
122  return m_w;
123  }
int m_w
Width
Definition: shape_rect.h:162

References m_w.

◆ IsSolid()

bool SHAPE_RECT::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 140 of file shape_rect.h.

141  {
142  return true;
143  }

◆ Move()

void SHAPE_RECT::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 135 of file shape_rect.h.

136  {
137  m_p0 += aVector;
138  }
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159

References m_p0.

◆ Outline()

const SHAPE_LINE_CHAIN SHAPE_RECT::Outline ( ) const
inline

Definition at line 145 of file shape_rect.h.

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.

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

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

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

Member Data Documentation

◆ m_h

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

◆ m_p0

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

◆ m_type

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 166 of file shape.h.

Referenced by SHAPE::Type().

◆ m_w

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: