KiCad PCB EDA Suite
SHAPE_CIRCLE Class Reference

#include <shape_circle.h>

Inheritance diagram for SHAPE_CIRCLE:
SHAPE

Public Member Functions

 SHAPE_CIRCLE ()
 
 SHAPE_CIRCLE (const VECTOR2I &aCenter, int aRadius)
 
 SHAPE_CIRCLE (const SHAPE_CIRCLE &aOther)
 
 ~SHAPE_CIRCLE ()
 
SHAPEClone () const override
 Function Clone() More...
 
SHAPE_CIRCLEoperator= (const SHAPE_CIRCLE &)=default
 
const BOX2I BBox (int aClearance=0) const override
 Function BBox() More...
 
bool Collide (const SEG &aSeg, int aClearance=0, int *aActual=nullptr) const override
 Function Collide() More...
 
void SetRadius (int aRadius)
 
void SetCenter (const VECTOR2I &aCenter)
 
int GetRadius () const
 
const VECTOR2I GetCenter () const
 
void Move (const VECTOR2I &aVector) override
 
void Rotate (double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
 Function Rotate. More...
 
bool IsSolid () const override
 
SHAPE_TYPE Type () const
 Function Type() More...
 
virtual bool Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr) 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, int *aActual=nullptr) const
 
virtual VECTOR2I Centre () const
 Function Centre() More...
 
virtual bool Parse (std::stringstream &aStream)
 
virtual const std::string Format () const
 
FACETNewFacet ()
 
SGNODECalcShape (SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
 

Protected Types

typedef VECTOR2I::extended_type ecoord
 

Protected Attributes

SHAPE_TYPE m_type
 

type of our shape

More...
 

Private Attributes

int m_radius
 
VECTOR2I m_center
 

Detailed Description

Definition at line 32 of file shape_circle.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 77 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_CIRCLE() [1/3]

SHAPE_CIRCLE::SHAPE_CIRCLE ( )
inline

Definition at line 35 of file shape_circle.h.

35  :
36  SHAPE( SH_CIRCLE ), m_radius( 0 )
37  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
line chain (polyline)
Definition: shape.h:44

Referenced by Clone().

◆ SHAPE_CIRCLE() [2/3]

SHAPE_CIRCLE::SHAPE_CIRCLE ( const VECTOR2I aCenter,
int  aRadius 
)
inline

Definition at line 39 of file shape_circle.h.

39  :
40  SHAPE( SH_CIRCLE ), m_radius( aRadius ), m_center( aCenter )
41  {}
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
VECTOR2I m_center
Definition: shape_circle.h:118
line chain (polyline)
Definition: shape.h:44

◆ SHAPE_CIRCLE() [3/3]

SHAPE_CIRCLE::SHAPE_CIRCLE ( const SHAPE_CIRCLE aOther)
inline

Definition at line 43 of file shape_circle.h.

43  :
44  SHAPE( SH_CIRCLE ),
45  m_radius( aOther.m_radius ),
46  m_center( aOther.m_center )
47  {};
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
VECTOR2I m_center
Definition: shape_circle.h:118
line chain (polyline)
Definition: shape.h:44

◆ ~SHAPE_CIRCLE()

SHAPE_CIRCLE::~SHAPE_CIRCLE ( )
inline

Definition at line 49 of file shape_circle.h.

50  {}

Member Function Documentation

◆ BBox()

const BOX2I SHAPE_CIRCLE::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 59 of file shape_circle.h.

60  {
61  const VECTOR2I rc( m_radius + aClearance, m_radius + aClearance );
62 
63  return BOX2I( m_center - rc, rc * 2 );
64  }
BOX2< VECTOR2I > BOX2I
Definition: box2.h:521
VECTOR2I m_center
Definition: shape_circle.h:118
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61

References m_center, and m_radius.

◆ 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( 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:636
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
static VRML_COLOR colors[VRML_COLOR_LAST]
IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40

References IFSG_NODE::AddChildNode(), IFSG_INDEX::AddIndex(), IFSG_NODE::AddRefNode(), colors, SHAPE::facets, IFSG_NODE::GetRawPtr(), S3D::GetSGNodeParent(), IFSG_FACESET::NewNode(), IFSG_SHAPE::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

Function Centre()

Computes a center-of-mass of the shape

Returns
the center-of-mass point

Definition at line 173 of file shape.h.

174  {
175  return BBox( 0 ).Centre(); // if nothing better is available....
176  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:78

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

Referenced by PNS_PCBNEW_RULE_RESOLVER::CollideHoles().

◆ Clone()

SHAPE* SHAPE_CIRCLE::Clone ( ) const
inlineoverridevirtual

Function Clone()

Returns a dynamically allocated copy of the shape

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 52 of file shape_circle.h.

53  {
54  return new SHAPE_CIRCLE( *this );
55  }

References SHAPE_CIRCLE().

◆ Collide() [1/4]

bool SHAPE_CIRCLE::Collide ( const SEG aSeg,
int  aClearance = 0,
int *  aActual = nullptr 
) const
inlineoverridevirtual

Function Collide()

Checks if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating a collision. @aActual an optional pointer to an int to be updated with the actual distance in the case of collision.

Returns
true, if there is a collision.

Implements SHAPE.

Definition at line 66 of file shape_circle.h.

67  {
68  int minDist = aClearance + m_radius;
69  ecoord dist_sq = aSeg.SquaredDistance( m_center );
70 
71  if( dist_sq == 0 || dist_sq < (ecoord) minDist * minDist )
72  {
73  if( aActual )
74  *aActual = std::max( 0, (int) sqrt( dist_sq ) - m_radius );
75 
76  return true;
77  }
78 
79  return false;
80  }
VECTOR2I m_center
Definition: shape_circle.h:118
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:37
VECTOR2I::extended_type ecoord

References m_center, m_radius, and SEG::SquaredDistance().

Referenced by Collide().

◆ Collide() [2/4]

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

Function Collide()

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

Parameters
aActualan optional pointer to an int to store the actual distance in the event of 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 125 of file shape.h.

126  {
127  return Collide( SEG( aP, aP ), aClearance );
128  }
Definition: seg.h:39
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr) const
Function Collide()
Definition: shape.h:125

Referenced by collide(), PNS::ITEM::collideSimple(), PNS::SHOVE::onCollidingVia(), PNS::HIT_VISITOR::operator()(), and PNS::OPTIMIZER::smartPadsSingle().

◆ 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
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, if there is a collision.

Definition at line 607 of file shape_collisions.cpp.

608 {
609  return CollideShapes( this, aShape, aClearance, nullptr, aMTV );
610 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References CollideShapes().

◆ Collide() [4/4]

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

Definition at line 613 of file shape_collisions.cpp.

614 {
615  return CollideShapes( this, aShape, aClearance, aActual, nullptr );
616 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References CollideShapes().

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

◆ GetCenter()

◆ GetRadius()

◆ IsSolid()

bool SHAPE_CIRCLE::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 112 of file shape_circle.h.

113  {
114  return true;
115  }

◆ Move()

void SHAPE_CIRCLE::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 102 of file shape_circle.h.

103  {
104  m_center += aVector;
105  }
VECTOR2I m_center
Definition: shape_circle.h:118

References m_center.

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

◆ operator=()

SHAPE_CIRCLE& SHAPE_CIRCLE::operator= ( const SHAPE_CIRCLE )
default

◆ 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_CIRCLE::Rotate ( double  aAngle,
const VECTOR2I aCenter = { 0, 0 } 
)
inlineoverridevirtual

Function Rotate.

Parameters
aCenteris the rotation center
aAnglerotation angle in radians

Implements SHAPE.

Definition at line 107 of file shape_circle.h.

107  { 0, 0 } ) override
108  {
109  // That was easy....
110  }

◆ SetCenter()

void SHAPE_CIRCLE::SetCenter ( const VECTOR2I aCenter)
inline

Definition at line 87 of file shape_circle.h.

88  {
89  m_center = aCenter;
90  }
VECTOR2I m_center
Definition: shape_circle.h:118

References m_center.

Referenced by Collide(), and PNS::VIA::SetPos().

◆ SetRadius()

void SHAPE_CIRCLE::SetRadius ( int  aRadius)
inline

Definition at line 82 of file shape_circle.h.

83  {
84  m_radius = aRadius;
85  }

References m_radius.

Referenced by PNS::VIA::SetDiameter().

◆ Type()

SHAPE_TYPE SHAPE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 99 of file shape.h.

100  {
101  return m_type;
102  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:195

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_center

VECTOR2I SHAPE_CIRCLE::m_center
private

Definition at line 118 of file shape_circle.h.

Referenced by BBox(), Collide(), GetCenter(), Move(), and SetCenter().

◆ m_radius

int SHAPE_CIRCLE::m_radius
private

Definition at line 117 of file shape_circle.h.

Referenced by BBox(), Collide(), GetRadius(), and SetRadius().

◆ m_type

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 195 of file shape.h.

Referenced by SHAPE::Type().


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