KiCad PCB EDA Suite
SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI Struct Reference

#include <shape_poly_set.h>

Inheritance diagram for SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI:
SHAPE_LINE_CHAIN_BASE SHAPE SHAPE_BASE

Public Member Functions

 TRI (int _a=0, int _b=0, int _c=0, TRIANGULATED_POLYGON *aParent=nullptr)
 
virtual void Rotate (double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
 
virtual void Move (const VECTOR2I &aVector) override
 
virtual bool IsSolid () const override
 
virtual bool IsClosed () const override
 
virtual const BOX2I BBox (int aClearance=0) const override
 Compute a bounding box of the shape, with a margin of aClearance a collision. More...
 
virtual const VECTOR2I GetPoint (int aIndex) const override
 
virtual const SEG GetSegment (int aIndex) const override
 
virtual size_t GetPointCount () const override
 
virtual size_t GetSegmentCount () const override
 
virtual bool Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
 Check if point aP lies closer to us than aClearance. More...
 
virtual bool Collide (const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
 Check if segment aSeg lies closer to us than aClearance. More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const
 Check if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision. More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
 
SEG::ecoord SquaredDistance (const VECTOR2I &aP, bool aOutlineOnly=false) const
 
bool PointInside (const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
 Check if point aP lies inside a polygon (any type) defined by the line chain. More...
 
bool PointOnEdge (const VECTOR2I &aP, int aAccuracy=0) const
 Check if point aP lies on an edge or vertex of the line chain. More...
 
int EdgeContainingPoint (const VECTOR2I &aP, int aAccuracy=0) const
 Check if point aP lies on an edge or vertex of the line chain. More...
 
virtual BOX2IGetCachedBBox () const
 
virtual SHAPEClone () const
 Return a dynamically allocated copy of the shape. More...
 
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)
 
virtual const std::string Format () const
 
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)
 

Public Attributes

int a
 
int b
 
int c
 
TRIANGULATED_POLYGONparent
 

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

Detailed Description

Definition at line 75 of file shape_poly_set.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 236 of file shape.h.

Constructor & Destructor Documentation

◆ TRI()

SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::TRI ( int  _a = 0,
int  _b = 0,
int  _c = 0,
TRIANGULATED_POLYGON aParent = nullptr 
)
inline

Definition at line 77 of file shape_poly_set.h.

77  :
79  a( _a ),
80  b( _b ),
81  c( _c ),
82  parent( aParent )
83  {
84  }
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:243
a single triangle belonging to a POLY_SET triangulation
Definition: shape.h:52

Member Function Documentation

◆ BBox()

const BOX2I SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::BBox ( int  aClearance = 0) const
overridevirtual

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 2478 of file shape_poly_set.cpp.

2479 {
2480  BOX2I bbox( parent->m_vertices[a] );
2481  bbox.Merge( parent->m_vertices[b] );
2482  bbox.Merge( parent->m_vertices[c] );
2483 
2484  if( aClearance != 0 )
2485  bbox.Inflate( aClearance );
2486 
2487  return bbox;
2488 }
A 2D bounding box built on top of an origin point and size vector.
Definition: box2.h:41

References BOX2< Vec >::Inflate(), and BOX2< Vec >::Merge().

◆ CalcShape()

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

Definition at line 703 of file wrlfacet.cpp.

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

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

Referenced by Collide().

◆ Clone()

virtual SHAPE* SHAPE::Clone ( ) const
inlinevirtualinherited

Return a dynamically allocated copy of the shape.

Return values
copyof the shape

Reimplemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN, SHAPE_ARC, SHAPE_RECT, SHAPE_SIMPLE, SHAPE_CIRCLE, SHAPE_SEGMENT, SHAPE_COMPOUND, and SHAPE_NULL.

Definition at line 139 of file shape.h.

140  {
141  assert( false );
142  return nullptr;
143  };

Referenced by PNS::ROUTER::markViolations(), ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM(), PNS::SOLID::SOLID(), and ROUTER_PREVIEW_ITEM::Update().

◆ Collide() [1/4]

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

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 in SHAPE_RECT, SHAPE_SEGMENT, and SHAPE_COMPOUND.

Definition at line 1103 of file shape_collisions.cpp.

1104 {
1105  return collideShapes( this, aShape, aClearance, nullptr, nullptr, aMTV );
1106 }
static bool collideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)

References collideShapes().

◆ Collide() [2/4]

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

Reimplemented in SHAPE_POLY_SET, SHAPE_ARC, SHAPE_RECT, SHAPE_SEGMENT, and SHAPE_COMPOUND.

Definition at line 1109 of file shape_collisions.cpp.

1110 {
1111  return collideShapes( this, aShape, aClearance, aActual, aLocation, nullptr );
1112 }
static bool collideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)

References collideShapes().

◆ Collide() [3/4]

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

Check if point aP lies closer to us than aClearance.

Parameters
aPthe point to check for collisions with
aClearanceminimum distance that does not qualify as a collision.
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, when a collision has been found

Reimplemented from SHAPE.

Reimplemented in SHAPE_LINE_CHAIN.

Definition at line 302 of file shape_line_chain.cpp.

304 {
305  if( IsClosed() && PointInside( aP, aClearance ) )
306  {
307  if( aLocation )
308  *aLocation = aP;
309 
310  if( aActual )
311  *aActual = 0;
312 
313  return true;
314  }
315 
316  SEG::ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
317  SEG::ecoord clearance_sq = SEG::Square( aClearance );
318  VECTOR2I nearest;
319 
320  for( size_t i = 0; i < GetSegmentCount(); i++ )
321  {
322  const SEG& s = GetSegment( i );
323  VECTOR2I pn = s.NearestPoint( aP );
324  SEG::ecoord dist_sq = ( pn - aP ).SquaredEuclideanNorm();
325 
326  if( dist_sq < closest_dist_sq )
327  {
328  nearest = pn;
329  closest_dist_sq = dist_sq;
330 
331  if( closest_dist_sq == 0 )
332  break;
333 
334  // If we're not looking for aActual then any collision will do
335  if( closest_dist_sq < clearance_sq && !aActual )
336  break;
337  }
338  }
339 
340  if( closest_dist_sq == 0 || closest_dist_sq < clearance_sq )
341  {
342  if( aLocation )
343  *aLocation = nearest;
344 
345  if( aActual )
346  *aActual = sqrt( closest_dist_sq );
347 
348  return true;
349  }
350 
351  return false;
352 }
virtual bool IsClosed() const =0
VECTOR2I::extended_type ecoord
Definition: seg.h:43
Define a general 2D-vector/point.
Definition: vector2d.h:61
virtual size_t GetSegmentCount() const =0
static SEG::ecoord Square(int a)
Definition: seg.h:122
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:79
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
Check if point aP lies inside a polygon (any type) defined by the line chain.
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition: seg.cpp:227
Definition: seg.h:40
virtual const SEG GetSegment(int aIndex) const =0

References VECTOR2< T >::ECOORD_MAX, SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SEG::NearestPoint(), SHAPE_LINE_CHAIN_BASE::PointInside(), and SEG::Square().

Referenced by Collide().

◆ Collide() [4/4]

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

Check if segment aSeg lies closer to us than aClearance.

Parameters
aSegthe segment to check for collisions with
aClearanceminimum distance that does not qualify as a collision.
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, when a collision has been found

Implements SHAPE.

Reimplemented in SHAPE_LINE_CHAIN, and SHAPE_SIMPLE.

Definition at line 438 of file shape_line_chain.cpp.

440 {
441  if( IsClosed() && PointInside( aSeg.A ) )
442  {
443  if( aLocation )
444  *aLocation = aSeg.A;
445 
446  if( aActual )
447  *aActual = 0;
448 
449  return true;
450  }
451 
452  SEG::ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
453  SEG::ecoord clearance_sq = SEG::Square( aClearance );
454  VECTOR2I nearest;
455 
456  for( size_t i = 0; i < GetSegmentCount(); i++ )
457  {
458  const SEG& s = GetSegment( i );
459  SEG::ecoord dist_sq = s.SquaredDistance( aSeg );
460 
461  if( dist_sq < closest_dist_sq )
462  {
463  if( aLocation )
464  nearest = s.NearestPoint( aSeg );
465 
466  closest_dist_sq = dist_sq;
467 
468  if( closest_dist_sq == 0)
469  break;
470 
471  // If we're not looking for aActual then any collision will do
472  if( closest_dist_sq < clearance_sq && !aActual )
473  break;
474  }
475  }
476 
477  if( closest_dist_sq == 0 || closest_dist_sq < clearance_sq )
478  {
479  if( aLocation )
480  *aLocation = nearest;
481 
482  if( aActual )
483  *aActual = sqrt( closest_dist_sq );
484 
485  return true;
486  }
487 
488  return false;
489 }
virtual bool IsClosed() const =0
VECTOR2I::extended_type ecoord
Definition: seg.h:43
Define a general 2D-vector/point.
Definition: vector2d.h:61
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:39
virtual size_t GetSegmentCount() const =0
static SEG::ecoord Square(int a)
Definition: seg.h:122
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:79
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
Check if point aP lies inside a polygon (any type) defined by the line chain.
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition: seg.cpp:227
Definition: seg.h:40
virtual const SEG GetSegment(int aIndex) const =0
VECTOR2I A
Definition: seg.h:48

References SEG::A, VECTOR2< T >::ECOORD_MAX, SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SEG::NearestPoint(), SHAPE_LINE_CHAIN_BASE::PointInside(), SEG::Square(), and SEG::SquaredDistance().

◆ EdgeContainingPoint()

int SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint ( const VECTOR2I aP,
int  aAccuracy = 0 
) const
inherited

Check if point aP lies on an edge or vertex of the line chain.

Parameters
aPpoint to check
Returns
index of the first edge containing the point, otherwise negative

Definition at line 1595 of file shape_line_chain.cpp.

1596 {
1597  if( !GetPointCount() )
1598  {
1599  return -1;
1600  }
1601  else if( GetPointCount() == 1 )
1602  {
1603  VECTOR2I dist = GetPoint(0) - aPt;
1604  return ( hypot( dist.x, dist.y ) <= aAccuracy + 1 ) ? 0 : -1;
1605  }
1606 
1607  for( size_t i = 0; i < GetSegmentCount(); i++ )
1608  {
1609  const SEG s = GetSegment( i );
1610 
1611  if( s.A == aPt || s.B == aPt )
1612  return i;
1613 
1614  if( s.Distance( aPt ) <= aAccuracy + 1 )
1615  return i;
1616  }
1617 
1618  return -1;
1619 }
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition: seg.cpp:285
Define a general 2D-vector/point.
Definition: vector2d.h:61
virtual size_t GetPointCount() const =0
virtual size_t GetSegmentCount() const =0
Definition: seg.h:40
virtual const SEG GetSegment(int aIndex) const =0
VECTOR2I A
Definition: seg.h:48
virtual const VECTOR2I GetPoint(int aIndex) const =0
VECTOR2I B
Definition: seg.h:49

References SEG::A, SEG::B, SEG::Distance(), SHAPE_LINE_CHAIN_BASE::GetPoint(), SHAPE_LINE_CHAIN_BASE::GetPointCount(), SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SHAPE_LINE_CHAIN_BASE::PointOnEdge().

◆ Format()

const std::string SHAPE::Format ( ) const
virtualinherited

Reimplemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN, SHAPE_RECT, SHAPE_SEGMENT, and SHAPE_COMPOUND.

Definition at line 35 of file shape.cpp.

36 {
37  assert( false );
38  return std::string( "" );
39 }

Referenced by SHAPE_FILE_IO::Write().

◆ GetCachedBBox()

virtual BOX2I* SHAPE_LINE_CHAIN_BASE::GetCachedBBox ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_LINE_CHAIN.

Definition at line 312 of file shape.h.

312 { return nullptr; }

Referenced by SHAPE_LINE_CHAIN_BASE::PointInside().

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

◆ GetPoint()

virtual const VECTOR2I SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::GetPoint ( int  aIndex) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 96 of file shape_poly_set.h.

97  {
98  switch(aIndex)
99  {
100  case 0: return parent->m_vertices[a];
101  case 1: return parent->m_vertices[b];
102  case 2: return parent->m_vertices[c];
103  default: assert(false);
104  }
105  return VECTOR2I(0, 0);
106  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623

References a, b, c, SHAPE_POLY_SET::TRIANGULATED_POLYGON::m_vertices, and parent.

◆ GetPointCount()

virtual size_t SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::GetPointCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 120 of file shape_poly_set.h.

120 { return 3; }

◆ GetSegment()

virtual const SEG SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::GetSegment ( int  aIndex) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 108 of file shape_poly_set.h.

109  {
110  switch(aIndex)
111  {
112  case 0: return SEG( parent->m_vertices[a], parent->m_vertices[b] );
113  case 1: return SEG( parent->m_vertices[b], parent->m_vertices[c] );
114  case 2: return SEG( parent->m_vertices[c], parent->m_vertices[a] );
115  default: assert(false);
116  }
117  return SEG();
118  }
Definition: seg.h:40

References a, b, c, SHAPE_POLY_SET::TRIANGULATED_POLYGON::m_vertices, and parent.

◆ GetSegmentCount()

virtual size_t SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::GetSegmentCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 121 of file shape_poly_set.h.

121 { return 3; }

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

◆ IsClosed()

virtual bool SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::IsClosed ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 92 of file shape_poly_set.h.

92 { return true; }

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

virtual bool SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 90 of file shape_poly_set.h.

90 { return true; }

◆ Move()

virtual void SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 88 of file shape_poly_set.h.

88 {};

◆ NewFacet()

FACET * SHAPE::NewFacet ( )
inherited

Definition at line 695 of file wrlfacet.cpp.

696 {
697  FACET* fp = new FACET;
698  facets.push_back( fp );
699  return fp;
700 }
Definition: wrlfacet.h:42
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 }

◆ PointInside()

bool SHAPE_LINE_CHAIN_BASE::PointInside ( const VECTOR2I aPt,
int  aAccuracy = 0,
bool  aUseBBoxCache = false 
) const
inherited

Check if point aP lies inside a polygon (any type) defined by the line chain.

For closed shapes only.

Parameters
aPtpoint to check
aUseBBoxCachegives better performance if the bounding box caches have been generated.
Returns
true if the point is inside the shape (edge is not treated as being inside).

Definition at line 1537 of file shape_line_chain.cpp.

1539 {
1540  /*
1541  * Don't check the bounding box unless it's cached. Building it is about the same speed as
1542  * the rigorous test below and so just slows things down by doing potentially two tests.
1543  */
1544  if( aUseBBoxCache && GetCachedBBox() && !GetCachedBBox()->Contains( aPt ) )
1545  return false;
1546 
1547  if( !IsClosed() || GetPointCount() < 3 )
1548  return false;
1549 
1550  bool inside = false;
1551 
1552  /*
1553  * To check for interior points, we draw a line in the positive x direction from
1554  * the point. If it intersects an even number of segments, the point is outside the
1555  * line chain (it had to first enter and then exit). Otherwise, it is inside the chain.
1556  *
1557  * Note: slope might be denormal here in the case of a horizontal line but we require our
1558  * y to move from above to below the point (or vice versa)
1559  *
1560  * Note: we open-code CPoint() here so that we don't end up calculating the size of the
1561  * vector number-of-points times. This has a non-trivial impact on zone fill times.
1562  */
1563  int pointCount = GetPointCount();
1564 
1565  for( int i = 0; i < pointCount; )
1566  {
1567  const auto p1 = GetPoint( i++ );
1568  const auto p2 = GetPoint( i == pointCount ? 0 : i );
1569  const auto diff = p2 - p1;
1570 
1571  if( diff.y != 0 )
1572  {
1573  const int d = rescale( diff.x, ( aPt.y - p1.y ), diff.y );
1574 
1575  if( ( ( p1.y > aPt.y ) != ( p2.y > aPt.y ) ) && ( aPt.x - p1.x < d ) )
1576  inside = !inside;
1577  }
1578  }
1579 
1580  // If accuracy is <= 1 (nm) then we skip the accuracy test for performance. Otherwise
1581  // we use "OnEdge(accuracy)" as a proxy for "Inside(accuracy)".
1582  if( aAccuracy <= 1 )
1583  return inside;
1584  else
1585  return inside || PointOnEdge( aPt, aAccuracy );
1586 }
virtual BOX2I * GetCachedBBox() const
Definition: shape.h:312
virtual bool IsClosed() const =0
virtual size_t GetPointCount() const =0
bool PointOnEdge(const VECTOR2I &aP, int aAccuracy=0) const
Check if point aP lies on an edge or vertex of the line chain.
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).
Definition: util.h:98
virtual const VECTOR2I GetPoint(int aIndex) const =0

References SHAPE_LINE_CHAIN_BASE::GetCachedBBox(), SHAPE_LINE_CHAIN_BASE::GetPoint(), SHAPE_LINE_CHAIN_BASE::GetPointCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SHAPE_LINE_CHAIN_BASE::PointOnEdge(), rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Collide(), SHAPE_LINE_CHAIN::Collide(), SHAPE_LINE_CHAIN_BASE::Collide(), POLY_GRID_PARTITION::containsPoint(), SHAPE_POLY_SET::containsSingle(), ZONE::HitTestCutout(), MARKER_BASE::HitTestMarker(), SHAPE_LINE_CHAIN_BASE::SquaredDistance(), and PNS::LINE::Walkaround().

◆ PointOnEdge()

bool SHAPE_LINE_CHAIN_BASE::PointOnEdge ( const VECTOR2I aP,
int  aAccuracy = 0 
) const
inherited

Check if point aP lies on an edge or vertex of the line chain.

Parameters
aPpoint to check
Returns
true if the point lies on the edge.

Definition at line 1589 of file shape_line_chain.cpp.

1590 {
1591  return EdgeContainingPoint( aPt, aAccuracy ) >= 0;
1592 }
int EdgeContainingPoint(const VECTOR2I &aP, int aAccuracy=0) const
Check if point aP lies on an edge or vertex of the line chain.

References SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint().

Referenced by FABMASTER::loadZones(), SHAPE_LINE_CHAIN_BASE::PointInside(), and PNS::LINE::Walkaround().

◆ Rotate()

virtual void SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::Rotate ( double  aAngle,
const VECTOR2I aCenter = { 0, 0 } 
)
inlineoverridevirtual
Parameters
aCenteris the rotation center.
aAnglerotation angle in radians.

Implements SHAPE.

Definition at line 86 of file shape_poly_set.h.

86 { 0, 0 } ) override {};

◆ SquaredDistance()

SEG::ecoord SHAPE_LINE_CHAIN_BASE::SquaredDistance ( const VECTOR2I aP,
bool  aOutlineOnly = false 
) const
inherited

Definition at line 805 of file shape_line_chain.cpp.

806 {
808 
809  if( IsClosed() && PointInside( aP ) && !aOutlineOnly )
810  return 0;
811 
812  for( size_t s = 0; s < GetSegmentCount(); s++ )
813  d = std::min( d, GetSegment( s ).SquaredDistance( aP ) );
814 
815  return d;
816 }
virtual bool IsClosed() const =0
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:39
virtual size_t GetSegmentCount() const =0
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:79
VECTOR2I::extended_type ecoord
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
Check if point aP lies inside a polygon (any type) defined by the line chain.
virtual const SEG GetSegment(int aIndex) const =0

References VECTOR2< T >::ECOORD_MAX, SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SHAPE_LINE_CHAIN_BASE::PointInside(), and SEG::SquaredDistance().

Referenced by SHAPE_LINE_CHAIN::Distance().

◆ Type()

SHAPE_TYPE SHAPE_BASE::Type ( ) const
inlineinherited

Member Data Documentation

◆ a

int SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::a

Definition at line 124 of file shape_poly_set.h.

Referenced by GetPoint(), and GetSegment().

◆ b

int SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::b

Definition at line 124 of file shape_poly_set.h.

Referenced by GetPoint(), and GetSegment().

◆ c

int SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::c

Definition at line 124 of file shape_poly_set.h.

Referenced by GetPoint(), and GetSegment().

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

◆ 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(), CIRCLE::Contains(), EDIT_TOOL::FilletTracks(), and CIRCLE::IntersectLine().

◆ parent

TRIANGULATED_POLYGON* SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::parent

Definition at line 125 of file shape_poly_set.h.

Referenced by GetPoint(), and GetSegment().


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