KiCad PCB EDA Suite
SHAPE_SEGMENT Class Reference

#include <shape_segment.h>

Inheritance diagram for SHAPE_SEGMENT:
SHAPE SHAPE_BASE

Public Member Functions

 SHAPE_SEGMENT ()
 
 SHAPE_SEGMENT (const VECTOR2I &aA, const VECTOR2I &aB, int aWidth=0)
 
 SHAPE_SEGMENT (const SEG &aSeg, int aWidth=0)
 
 ~SHAPE_SEGMENT ()
 
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...
 
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 segment aSeg than aClearance, indicating a collision. More...
 
bool Collide (const VECTOR2I &aP, 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...
 
void SetSeg (const SEG &aSeg)
 
const SEGGetSeg () const
 
void SetWidth (int aWidth)
 
int GetWidth () const
 
bool IsSolid () const override
 
void Rotate (double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
 
void Move (const VECTOR2I &aVector) override
 
virtual const std::string Format () const override
 
bool IsNull () const
 Return true if the shape is a null shape. 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

SEG m_seg
 
int m_width
 

Detailed Description

Definition at line 35 of file shape_segment.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 236 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_SEGMENT() [1/3]

SHAPE_SEGMENT::SHAPE_SEGMENT ( )
inline

Definition at line 38 of file shape_segment.h.

38  :
39  SHAPE( SH_SEGMENT ),
40  m_width( 0 )
41  {};
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
line segment
Definition: shape.h:44

Referenced by Clone().

◆ SHAPE_SEGMENT() [2/3]

SHAPE_SEGMENT::SHAPE_SEGMENT ( const VECTOR2I aA,
const VECTOR2I aB,
int  aWidth = 0 
)
inline

Definition at line 43 of file shape_segment.h.

43  :
44  SHAPE( SH_SEGMENT ),
45  m_seg( aA, aB ),
46  m_width( aWidth )
47  {};
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
line segment
Definition: shape.h:44

◆ SHAPE_SEGMENT() [3/3]

SHAPE_SEGMENT::SHAPE_SEGMENT ( const SEG aSeg,
int  aWidth = 0 
)
inline

Definition at line 49 of file shape_segment.h.

49  :
50  SHAPE( SH_SEGMENT ),
51  m_seg( aSeg ),
52  m_width( aWidth )
53  {};
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
line segment
Definition: shape.h:44

◆ ~SHAPE_SEGMENT()

SHAPE_SEGMENT::~SHAPE_SEGMENT ( )
inline

Definition at line 55 of file shape_segment.h.

55 {};

Member Function Documentation

◆ BBox()

const BOX2I SHAPE_SEGMENT::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 62 of file shape_segment.h.

63  {
64  return BOX2I( m_seg.A, m_seg.B - m_seg.A ).Inflate( aClearance + ( m_width + 1 ) / 2 );
65  }
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:302
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50

References SEG::A, SEG::B, BOX2< Vec >::Inflate(), m_seg, and m_width.

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

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

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

Referenced by Collide().

◆ Clone()

SHAPE* SHAPE_SEGMENT::Clone ( ) const
inlineoverridevirtual

Return a dynamically allocated copy of the shape.

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 57 of file shape_segment.h.

58  {
59  return new SHAPE_SEGMENT( m_seg, m_width );
60  }

References m_seg, m_width, and SHAPE_SEGMENT().

Referenced by DRC_ENGINE::GetShape(), and PNS_KICAD_IFACE_BASE::syncPad().

◆ Collide() [1/4]

bool SHAPE_SEGMENT::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 67 of file shape_segment.h.

68  {
69  return SHAPE::Collide( aShape, aClearance, aMTV );
70  }
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().

◆ Collide() [2/4]

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

Reimplemented from SHAPE.

Definition at line 72 of file shape_segment.h.

74  {
75  return SHAPE::Collide( aShape, aClearance, aActual, aLocation );
76  }
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_SEGMENT::Collide ( const SEG aSeg,
int  aClearance = 0,
int *  aActual = nullptr,
VECTOR2I aLocation = nullptr 
) const
inlineoverridevirtual

Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating a collision.

Parameters
aActual[out] an optional pointer to an int to be updated with the actual distance int 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 78 of file shape_segment.h.

80  {
81  int min_dist = ( m_width + 1 ) / 2 + aClearance;
82  ecoord dist_sq = m_seg.SquaredDistance( aSeg );
83 
84  if( dist_sq == 0 || dist_sq < SEG::Square( min_dist ) )
85  {
86  if( aLocation )
87  *aLocation = m_seg.NearestPoint( aSeg );
88 
89  if( aActual )
90  *aActual = std::max( 0, (int) sqrt( dist_sq ) - ( m_width + 1 ) / 2 );
91 
92  return true;
93  }
94 
95  return false;
96  }
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:38
static SEG::ecoord Square(int a)
Definition: seg.h:123
VECTOR2I::extended_type ecoord
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition: seg.h:422

References m_seg, m_width, SEG::NearestPoint(), SEG::Square(), and SEG::SquaredDistance().

◆ Collide() [4/4]

bool SHAPE_SEGMENT::Collide ( const VECTOR2I aP,
int  aClearance = 0,
int *  aActual = nullptr,
VECTOR2I aLocation = nullptr 
) const
inlineoverridevirtual

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

Definition at line 98 of file shape_segment.h.

100  {
101  int min_dist = ( m_width + 1 ) / 2 + aClearance;
102  ecoord dist_sq = m_seg.SquaredDistance( aP );
103 
104  if( dist_sq == 0 || dist_sq < SEG::Square( min_dist ) )
105  {
106  if( aLocation )
107  *aLocation = m_seg.NearestPoint( aP );
108 
109  if( aActual )
110  *aActual = std::max( 0, (int) sqrt( dist_sq ) - ( m_width + 1 ) / 2 );
111 
112  return true;
113  }
114 
115  return false;
116  }
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:38
static SEG::ecoord Square(int a)
Definition: seg.h:123
VECTOR2I::extended_type ecoord
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition: seg.h:422

References m_seg, m_width, SEG::NearestPoint(), SEG::Square(), and SEG::SquaredDistance().

◆ Format()

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

Reimplemented from SHAPE.

Definition at line 29 of file shape_segment.cpp.

30 {
31  std::stringstream ss;
32 
33  ss << "SHAPE_SEGMENT( VECTOR2I( ";
34  ss << m_seg.A.x;
35  ss << ", ";
36  ss << m_seg.A.y;
37  ss << "), VECTOR2I( ";
38  ss << m_seg.B.x;
39  ss << ", ";
40  ss << m_seg.B.y;
41  ss << "), ";
42  ss << m_width;
43  ss << "); ";
44 
45  return ss.str();
46 }
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50

References SEG::A, SEG::B, m_seg, m_width, VECTOR2< T >::x, and VECTOR2< T >::y.

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

◆ GetSeg()

◆ GetWidth()

◆ 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_SEGMENT::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 138 of file shape_segment.h.

139  {
140  return true;
141  }

◆ Move()

void SHAPE_SEGMENT::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 155 of file shape_segment.h.

156  {
157  m_seg.A += aVector;
158  m_seg.B += aVector;
159  }
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50

References SEG::A, SEG::B, and m_seg.

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

◆ 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_SEGMENT::Rotate ( double  aAngle,
const VECTOR2I aCenter = { 0, 0 } 
)
inlineoverridevirtual
Parameters
aCenteris the rotation center.
aAnglerotation angle in radians.

Implements SHAPE.

Definition at line 143 of file shape_segment.h.

143  { 0, 0 } ) override
144  {
145  m_seg.A -= aCenter;
146  m_seg.B -= aCenter;
147 
148  m_seg.A = m_seg.A.Rotate( aAngle );
149  m_seg.B = m_seg.B.Rotate( aAngle );
150 
151  m_seg.A += aCenter;
152  m_seg.B += aCenter;
153  }
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50

◆ SetSeg()

void SHAPE_SEGMENT::SetSeg ( const SEG aSeg)
inline

Definition at line 118 of file shape_segment.h.

119  {
120  m_seg = aSeg;
121  }

References m_seg.

Referenced by PNS::SEGMENT::SetEnds(), and PNS::SEGMENT::SwapEnds().

◆ SetWidth()

void SHAPE_SEGMENT::SetWidth ( int  aWidth)
inline

Definition at line 128 of file shape_segment.h.

129  {
130  m_width = aWidth;
131  }

References m_width.

Referenced by PNS::SEGMENT::SetWidth(), and PNS_KICAD_IFACE_BASE::syncPad().

◆ Type()

SHAPE_TYPE SHAPE_BASE::Type ( ) const
inlineinherited

Member Data Documentation

◆ m_seg

SEG SHAPE_SEGMENT::m_seg
private

Definition at line 164 of file shape_segment.h.

Referenced by BBox(), Clone(), Collide(), Format(), GetSeg(), Move(), and SetSeg().

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

int SHAPE_SEGMENT::m_width
private

Definition at line 165 of file shape_segment.h.

Referenced by BBox(), Clone(), Collide(), Format(), GetWidth(), and SetWidth().

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


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