KiCad PCB EDA Suite
SHAPE_RECT Class Reference

#include <shape_rect.h>

Inheritance diagram for SHAPE_RECT:
SHAPE SHAPE_BASE

Public Member Functions

 SHAPE_RECT ()
 Create an empty (0-sized) rectangle. More...
 
 SHAPE_RECT (int aX0, int aY0, int aW, int aH)
 Create a rectangle defined by top-left corner (aX0, aY0), width aW and height aH. More...
 
 SHAPE_RECT (const VECTOR2I &aP0, int aW, int aH)
 Create a rectangle defined by top-left corner aP0, width aW and height aH. More...
 
 SHAPE_RECT (const SHAPE_RECT &aOther)
 
SHAPEClone () const override
 Return a dynamically allocated copy of the shape. More...
 
const BOX2I BBox (int aClearance=0) const override
 Compute a bounding box of the shape, with a margin of aClearance a collision. More...
 
int Diagonal () const
 Return length of the diagonal of the rectangle. More...
 
bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const override
 Check if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision. More...
 
bool Collide (const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
 
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. More...
 
const VECTOR2IGetPosition () const
 
const VECTOR2I GetSize () const
 
const int GetWidth () const
 
const int GetHeight () const
 
void Move (const VECTOR2I &aVector) override
 
void Rotate (double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
 This function has limited utility for SHAPE_RECT as non-cartesian rotations will distort the rectangle. More...
 
bool IsSolid () const override
 
const SHAPE_LINE_CHAIN Outline () const
 
virtual const std::string Format () const override
 
bool IsNull () const
 Return true if the shape is a null shape. More...
 
virtual bool Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
 Check if the boundary of shape (this) lies closer to the point aP than aClearance, indicating a collision. More...
 
virtual VECTOR2I Centre () const
 Compute a center-of-mass of the shape. More...
 
virtual bool Parse (std::stringstream &aStream)
 
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. More...
 
virtual bool HasIndexableSubshapes () const
 
virtual size_t GetIndexableSubshapeCount () const
 
virtual void GetIndexableSubshapes (std::vector< SHAPE * > &aSubshapes)
 

Static Public Attributes

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

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 36 of file shape_rect.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 236 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_RECT() [1/4]

SHAPE_RECT::SHAPE_RECT ( )
inline

Create an empty (0-sized) rectangle.

Definition at line 42 of file shape_rect.h.

42  :
43  SHAPE( SH_RECT ),
44  m_w( 0 ),
45  m_h( 0 )
46  {}
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186
axis-aligned rectangle
Definition: shape.h:43

Referenced by Clone().

◆ SHAPE_RECT() [2/4]

SHAPE_RECT::SHAPE_RECT ( int  aX0,
int  aY0,
int  aW,
int  aH 
)
inline

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

Definition at line 51 of file shape_rect.h.

51  :
52  SHAPE( SH_RECT ),
53  m_p0( aX0, aY0 ),
54  m_w( aW ),
55  m_h( aH )
56  {}
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
VECTOR2I m_p0
Top-left corner.
Definition: shape_rect.h:185
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186
axis-aligned rectangle
Definition: shape.h:43

◆ SHAPE_RECT() [3/4]

SHAPE_RECT::SHAPE_RECT ( const VECTOR2I aP0,
int  aW,
int  aH 
)
inline

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

Definition at line 61 of file shape_rect.h.

61  :
62  SHAPE( SH_RECT ),
63  m_p0( aP0 ),
64  m_w( aW ),
65  m_h( aH )
66  {}
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
VECTOR2I m_p0
Top-left corner.
Definition: shape_rect.h:185
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186
axis-aligned rectangle
Definition: shape.h:43

◆ SHAPE_RECT() [4/4]

SHAPE_RECT::SHAPE_RECT ( const SHAPE_RECT aOther)
inline

Definition at line 68 of file shape_rect.h.

68  :
69  SHAPE( SH_RECT ),
70  m_p0( aOther.m_p0 ),
71  m_w( aOther.m_w ),
72  m_h( aOther.m_h )
73  {};
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
VECTOR2I m_p0
Top-left corner.
Definition: shape_rect.h:185
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186
axis-aligned rectangle
Definition: shape.h:43

Member Function Documentation

◆ BBox()

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

82  {
83  BOX2I bbox( VECTOR2I( m_p0.x - aClearance, m_p0.y - aClearance ),
84  VECTOR2I( m_w + 2 * aClearance, m_h + 2 * aClearance ) );
85  return bbox;
86  }
Define a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:43
VECTOR2I m_p0
Top-left corner.
Definition: shape_rect.h:185
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186

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

Referenced by Collide().

◆ CalcShape()

SGNODE * SHAPE::CalcShape ( SGNODE aParent,
SGNODE aColor,
WRL1_ORDER  aVertexOrder,
float  aCreaseLimit = 0.74317,
bool  isVRML2 = false 
)
inherited

Definition at line 713 of file wrlfacet.cpp.

715 {
716  if( facets.empty() || !facets.front()->HasMinPoints() )
717  return NULL;
718 
719  std::vector< std::list< FACET* > > flist;
720 
721  // determine the max. index and size flist as appropriate
722  std::list< FACET* >::iterator sF = facets.begin();
723  std::list< FACET* >::iterator eF = facets.end();
724 
725  int maxIdx = 0;
726  int tmi;
727  float maxV = 0.0;
728  float tV = 0.0;
729 
730  while( sF != eF )
731  {
732  tV = ( *sF )->CalcFaceNormal();
733  tmi = ( *sF )->GetMaxIndex();
734 
735  if( tmi > maxIdx )
736  maxIdx = tmi;
737 
738  if( tV > maxV )
739  maxV = tV;
740 
741  ++sF;
742  }
743 
744  ++maxIdx;
745 
746  if( maxIdx < 3 )
747  return NULL;
748 
749  flist.resize( maxIdx );
750 
751  // create the lists of facets common to indices
752  sF = facets.begin();
753 
754  while( sF != eF )
755  {
756  ( *sF )->Renormalize( tV );
757  ( *sF )->CollectVertices( flist );
758  ++sF;
759  }
760 
761  // calculate the normals
762  size_t vs = flist.size();
763 
764  for( size_t i = 0; i < vs; ++i )
765  {
766  sF = flist[i].begin();
767  eF = flist[i].end();
768 
769  while( sF != eF )
770  {
771  ( *sF )->CalcVertexNormal( static_cast<int>( i ), flist[i], aCreaseLimit );
772  ++sF;
773  }
774  }
775 
776  std::vector< WRLVEC3F > vertices;
777  std::vector< WRLVEC3F > normals;
778  std::vector< SGCOLOR > colors;
779 
780  // push the facet data to the final output list
781  sF = facets.begin();
782  eF = facets.end();
783 
784  while( sF != eF )
785  {
786  ( *sF )->GetData( vertices, normals, colors, aVertexOrder );
787  ++sF;
788  }
789 
790  flist.clear();
791 
792  if( vertices.size() < 3 )
793  return NULL;
794 
795  IFSG_SHAPE shapeNode( false );
796 
797  if( !isVRML2 )
798  {
799  shapeNode.NewNode( aParent );
800 
801  if( aColor )
802  {
803  if( NULL == S3D::GetSGNodeParent( aColor ) )
804  shapeNode.AddChildNode( aColor );
805  else
806  shapeNode.AddRefNode( aColor );
807  }
808  }
809 
810  std::vector< SGPOINT > lCPts; // vertex points in SGPOINT (double) format
811  std::vector< SGVECTOR > lCNorm; // per-vertex normals
812  vs = vertices.size();
813 
814  for( size_t i = 0; i < vs; ++i )
815  {
816  SGPOINT pt;
817  pt.x = vertices[i].x;
818  pt.y = vertices[i].y;
819  pt.z = vertices[i].z;
820  lCPts.push_back( pt );
821  lCNorm.emplace_back( normals[i].x, normals[i].y, normals[i].z );
822  }
823 
824  vertices.clear();
825  normals.clear();
826 
827  IFSG_FACESET fsNode( false );
828 
829  if( !isVRML2 )
830  fsNode.NewNode( shapeNode );
831  else
832  fsNode.NewNode( aParent );
833 
834  IFSG_COORDS cpNode( fsNode );
835  cpNode.SetCoordsList( lCPts.size(), &lCPts[0] );
836  IFSG_COORDINDEX ciNode( fsNode );
837 
838  for( int i = 0; i < (int)lCPts.size(); ++i )
839  ciNode.AddIndex( i );
840 
841  IFSG_NORMALS nmNode( fsNode );
842  nmNode.SetNormalList( lCNorm.size(), &lCNorm[0] );
843 
844  if( !colors.empty() )
845  {
846  IFSG_COLORS nmColor( fsNode );
847  nmColor.SetColorList( colors.size(), &colors[0] );
848  colors.clear();
849  }
850 
851  if( !isVRML2 )
852  return shapeNode.GetRawPtr();
853 
854  return fsNode.GetRawPtr();
855 }
double x
Definition: sg_base.h:70
IFSG_COORDS is the wrapper for SGCOORDS.
Definition: ifsg_coords.h:40
IFSG_COORDINDEX is the wrapper for SGCOORDINDEX.
IFSG_COLORS is the wrapper for SGCOLORS.
Definition: ifsg_colors.h:41
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:492
double y
Definition: sg_base.h:71
IFSG_NORMALS is the wrapper for the SGNORMALS class.
Definition: ifsg_normals.h:40
#define NULL
std::list< FACET * > facets
Definition: wrlfacet.h:143
IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:40
double z
Definition: sg_base.h:72
IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40

References IFSG_NODE::AddChildNode(), IFSG_INDEX::AddIndex(), IFSG_NODE::AddRefNode(), SHAPE::facets, IFSG_NODE::GetRawPtr(), S3D::GetSGNodeParent(), IFSG_SHAPE::NewNode(), IFSG_FACESET::NewNode(), NULL, IFSG_COLORS::SetColorList(), IFSG_COORDS::SetCoordsList(), IFSG_NORMALS::SetNormalList(), SGPOINT::x, SGPOINT::y, and SGPOINT::z.

Referenced by WRL1FACESET::TranslateToSG(), X3DIFACESET::TranslateToSG(), and WRL2FACESET::TranslateToSG().

◆ Centre()

virtual VECTOR2I SHAPE::Centre ( ) const
inlinevirtualinherited

Compute a center-of-mass of the shape.

Returns
the center-of-mass point

Definition at line 216 of file shape.h.

217  {
218  return BBox( 0 ).Centre(); // if nothing better is available....
219  }
virtual const BOX2I BBox(int aClearance=0) const =0
Compute a bounding box of the shape, with a margin of aClearance a collision.
Vec Centre() const
Definition: box2.h:69

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

Referenced by Collide().

◆ Clone()

SHAPE* SHAPE_RECT::Clone ( ) const
inlineoverridevirtual

Return a dynamically allocated copy of the shape.

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 75 of file shape_rect.h.

76  {
77  return new SHAPE_RECT( *this );
78  }
SHAPE_RECT()
Create an empty (0-sized) rectangle.
Definition: shape_rect.h:42

References SHAPE_RECT().

◆ Collide() [1/4]

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

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
aMTVminimum 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 from SHAPE.

Definition at line 98 of file shape_rect.h.

99  {
100  return SHAPE::Collide( aShape, aClearance, aMTV );
101  }
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition: shape.h:165

References SHAPE::Collide().

Referenced by Collide(), and SCH_JUNCTION::HitTest().

◆ Collide() [2/4]

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

Reimplemented from SHAPE.

Definition at line 103 of file shape_rect.h.

105  {
106  return SHAPE::Collide( aShape, aClearance, aActual, aLocation );
107  }
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition: shape.h:165

References SHAPE::Collide().

◆ Collide() [3/4]

bool SHAPE_RECT::Collide ( const SEG aSeg,
int  aClearance = 0,
int *  aActual = nullptr,
VECTOR2I aLocation = nullptr 
) const
overridevirtual

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.

Implements SHAPE.

Definition at line 28 of file shape_rect.cpp.

30 {
31  if( BBox( 0 ).Contains( aSeg.A ) )
32  {
33  if( aLocation )
34  *aLocation = aSeg.A;
35 
36  if( aActual )
37  *aActual = 0;
38 
39  return true;
40  }
41 
42  if( BBox( 0 ).Contains( aSeg.B ) )
43  {
44  if( aLocation )
45  *aLocation = aSeg.B;
46 
47  if( aActual )
48  *aActual = 0;
49 
50  return true;
51  }
52 
53  VECTOR2I corners[] = { VECTOR2I( m_p0.x, m_p0.y ),
54  VECTOR2I( m_p0.x, m_p0.y + m_h ),
55  VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ),
56  VECTOR2I( m_p0.x + m_w, m_p0.y ),
57  VECTOR2I( m_p0.x, m_p0.y ) };
58 
59  SEG::ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
60  VECTOR2I nearest;
61 
62  for( int i = 0; i < 4; i++ )
63  {
64  SEG side( corners[i], corners[ i + 1] );
65  SEG::ecoord dist_sq = side.SquaredDistance( aSeg );
66 
67  if( dist_sq < closest_dist_sq )
68  {
69  if ( aLocation )
70  {
71  nearest = side.NearestPoint( aSeg );
72  }
73 
74  closest_dist_sq = dist_sq;
75  }
76  }
77 
78  if( closest_dist_sq == 0 || closest_dist_sq < SEG::Square( aClearance ) )
79  {
80  if( aActual )
81  *aActual = sqrt( closest_dist_sq );
82 
83  if( aLocation )
84  *aLocation = nearest;
85 
86  return true;
87  }
88 
89  return false;
90 }
VECTOR2I::extended_type ecoord
Definition: seg.h:43
Define a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
static SEG::ecoord Square(int a)
Definition: seg.h:122
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:79
VECTOR2I m_p0
Top-left corner.
Definition: shape_rect.h:185
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186
Definition: seg.h:40
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Definition: shape_rect.h:81
VECTOR2I A
Definition: seg.h:48
VECTOR2I B
Definition: seg.h:49

References SEG::A, SEG::B, BBox(), SHAPE_POLY_SET::Contains(), VECTOR2< T >::ECOORD_MAX, m_h, m_p0, m_w, SEG::NearestPoint(), SEG::Square(), SEG::SquaredDistance(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Collide() [4/4]

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

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 in SHAPE_POLY_SET, SHAPE_LINE_CHAIN_BASE, SHAPE_ARC, and SHAPE_SEGMENT.

Definition at line 165 of file shape.h.

167  {
168  return Collide( SEG( aP, aP ), aClearance, aActual, aLocation );
169  }
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition: shape.h:165
Definition: seg.h:40

Referenced by DRC_RTREE::CheckColliding(), SHAPE_COMPOUND::Collide(), SHAPE_SEGMENT::Collide(), collide(), Collide(), SHAPE_POLY_SET::Collide(), PNS::ITEM::collideSimple(), PNS::SHOVE::onCollidingVia(), PNS::HIT_VISITOR::operator()(), DRC_RTREE::QueryColliding(), PNS::OPTIMIZER::smartPadsSingle(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::testAgainstEdge(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem(), and DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem().

◆ Diagonal()

int SHAPE_RECT::Diagonal ( ) const
inline

Return length of the diagonal of the rectangle.

Returns
diagonal length

Definition at line 93 of file shape_rect.h.

94  {
95  return VECTOR2I( m_w, m_h ).EuclideanNorm();
96  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293

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

◆ Format()

const std::string SHAPE_RECT::Format ( ) const
overridevirtual

Reimplemented from SHAPE.

Definition at line 92 of file shape_rect.cpp.

93 {
94  std::stringstream ss;
95 
96  ss << "SHAPE_RECT( ";
97  ss << m_p0.x;
98  ss << ", ";
99  ss << m_p0.y;
100  ss << ", ";
101  ss << m_w;
102  ss << ", ";
103  ss << m_h;
104  ss << ");";
105 
106  return ss.str();
107 }
VECTOR2I m_p0
Top-left corner.
Definition: shape_rect.h:185
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186

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

◆ GetHeight()

const int SHAPE_RECT::GetHeight ( ) const
inline
Returns
the height of the rectangle.

Definition at line 140 of file shape_rect.h.

141  {
142  return m_h;
143  }
int m_h
Height.
Definition: shape_rect.h:187

References m_h.

Referenced by KIGFX::PCB_PAINTER::draw().

◆ GetIndexableSubshapeCount()

virtual size_t SHAPE_BASE::GetIndexableSubshapeCount ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_POLY_SET, and SHAPE_COMPOUND.

Definition at line 104 of file shape.h.

104 { return 0; }

◆ GetIndexableSubshapes()

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

Reimplemented in SHAPE_POLY_SET, and SHAPE_COMPOUND.

Definition at line 106 of file shape.h.

106 { }

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

◆ GetPosition()

const VECTOR2I& SHAPE_RECT::GetPosition ( ) const
inline
Returns
the top left corner of the rectangle.

Definition at line 116 of file shape_rect.h.

117  {
118  return m_p0;
119  }
VECTOR2I m_p0
Top-left corner.
Definition: shape_rect.h:185

References m_p0.

Referenced by PNS::buildHullForPrimitiveShape(), Collide(), BOARD_ADAPTER::createPadWithClearance(), KIGFX::PCB_PAINTER::draw(), ROUTER_PREVIEW_ITEM::drawShape(), and PNS::OPTIMIZER::rectBreakouts().

◆ GetSize()

const VECTOR2I SHAPE_RECT::GetSize ( ) const
inline
Returns
the size of the rectangle.

Definition at line 124 of file shape_rect.h.

125  {
126  return VECTOR2I( m_w, m_h );
127  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186

References m_h, and m_w.

Referenced by PNS::buildHullForPrimitiveShape(), Collide(), BOARD_ADAPTER::createPadWithClearance(), KIGFX::PCB_PAINTER::draw(), ROUTER_PREVIEW_ITEM::drawShape(), and PNS::OPTIMIZER::rectBreakouts().

◆ GetWidth()

const int SHAPE_RECT::GetWidth ( ) const
inline
Returns
the width of the rectangle.

Definition at line 132 of file shape_rect.h.

133  {
134  return m_w;
135  }
int m_w
Width.
Definition: shape_rect.h:186

References m_w.

Referenced by KIGFX::PCB_PAINTER::draw().

◆ HasIndexableSubshapes()

virtual bool SHAPE_BASE::HasIndexableSubshapes ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_POLY_SET, and SHAPE_COMPOUND.

Definition at line 99 of file shape.h.

100  {
101  return false;
102  }

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

◆ IsNull()

bool SHAPE::IsNull ( ) const
inlineinherited

Return true if the shape is a null shape.

Return values
trueif null :-)

Definition at line 150 of file shape.h.

151  {
152  return m_type == SH_NULL;
153  }
SHAPE_TYPE m_type
< type of our shape
Definition: shape.h:110
empty shape (no shape...),
Definition: shape.h:51

References SHAPE_BASE::m_type, and SH_NULL.

◆ IsSolid()

bool SHAPE_RECT::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 165 of file shape_rect.h.

166  {
167  return true;
168  }

◆ Move()

void SHAPE_RECT::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 145 of file shape_rect.h.

146  {
147  m_p0 += aVector;
148  }
VECTOR2I m_p0
Top-left corner.
Definition: shape_rect.h:185

References m_p0.

◆ NewFacet()

FACET * SHAPE::NewFacet ( )
inherited

Definition at line 705 of file wrlfacet.cpp.

706 {
707  FACET* fp = new FACET;
708  facets.push_back( fp );
709  return fp;
710 }
Definition: wrlfacet.h:41
std::list< FACET * > facets
Definition: wrlfacet.h:143

References SHAPE::facets.

Referenced by WRL1FACESET::TranslateToSG(), X3DIFACESET::TranslateToSG(), and WRL2FACESET::TranslateToSG().

◆ Outline()

const SHAPE_LINE_CHAIN SHAPE_RECT::Outline ( ) const
inline

Definition at line 170 of file shape_rect.h.

171  {
172  SHAPE_LINE_CHAIN rv;
173  rv.Append( m_p0 );
174  rv.Append( m_p0.x, m_p0.y + m_h );
175  rv.Append( m_p0.x + m_w, m_p0.y + m_h );
176  rv.Append( m_p0.x + m_w, m_p0.y );
177  rv.Append( m_p0 );
178  rv.SetClosed( true );
179  return rv;
180  }
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:185
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186
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(), PCB_GRID_HELPER::computeAnchors(), and 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 }

◆ Rotate()

void SHAPE_RECT::Rotate ( double  aAngle,
const VECTOR2I aCenter = { 0, 0 } 
)
inlineoverridevirtual

This function has limited utility for SHAPE_RECT as non-cartesian rotations will distort the rectangle.

If you might need to handle non-90ยบ rotations then the SHAPE_RECT should first be converted to a SHAPE_SIMPLE which can then be free-rotated.

Implements SHAPE.

Definition at line 155 of file shape_rect.h.

155  { 0, 0 } ) override
156  {
157  m_p0 -= aCenter;
158  m_p0 = m_p0.Rotate( aAngle );
159  m_p0 += aCenter;
160 
161  if( abs( sin( aAngle ) ) == 1 )
162  std::swap( m_h, m_w );
163  }
VECTOR2I m_p0
Top-left corner.
Definition: shape_rect.h:185
int m_h
Height.
Definition: shape_rect.h:187
int m_w
Width.
Definition: shape_rect.h:186
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371

◆ Type()

SHAPE_TYPE SHAPE_BASE::Type ( ) const
inlineinherited

Member Data Documentation

◆ m_h

int SHAPE_RECT::m_h
private

Height.

Definition at line 187 of file shape_rect.h.

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

◆ m_p0

VECTOR2I SHAPE_RECT::m_p0
private

Top-left corner.

Definition at line 185 of file shape_rect.h.

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

◆ m_type

SHAPE_TYPE SHAPE_BASE::m_type
protectedinherited

< type of our shape

Definition at line 110 of file shape.h.

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

◆ m_w

int SHAPE_RECT::m_w
private

Width.

Definition at line 186 of file shape_rect.h.

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

◆ 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 122 of file shape.h.

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


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