KiCad PCB EDA Suite
SHAPE_SIMPLE Class Reference

SHAPE_SIMPLE. More...

#include <shape_simple.h>

Inheritance diagram for SHAPE_SIMPLE:
SHAPE_LINE_CHAIN_BASE SHAPE SHAPE_BASE

Public Member Functions

 SHAPE_SIMPLE ()
 Constructor Creates an empty polygon. More...
 
 SHAPE_SIMPLE (const SHAPE_LINE_CHAIN &aPoly)
 
 SHAPE_SIMPLE (const SHAPE_SIMPLE &aOther)
 
SHAPEClone () const override
 Return a dynamically allocated copy of the shape. More...
 
void Clear ()
 Function Clear() Removes all points from the polygon. 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 PointCount () const
 Function PointCount() More...
 
const VECTOR2ICPoint (int aIndex) const
 Function Point() More...
 
const VECTOR2D CDPoint (int aIndex) const
 Function CDPoint() More...
 
const SHAPE_LINE_CHAINVertices () const
 Function Vertices() More...
 
void Append (int aX, int aY)
 Function Append() More...
 
void Append (const VECTOR2I &aP)
 Function Append() More...
 
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...
 
void Rotate (double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
 
void Move (const VECTOR2I &aVector) override
 
bool IsSolid () const override
 
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
 
bool IsClosed () 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 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...
 
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)
 

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

SHAPE_LINE_CHAIN m_points
 

Detailed Description

SHAPE_SIMPLE.

Represents a simple polygon consisting of a zero-thickness closed chain of connected line segments.

Internally the vertices are held in a SHAPE_LINE_CHAIN, please note that there is a "virtual" line segment between the last and first vertex.

Definition at line 43 of file shape_simple.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 236 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_SIMPLE() [1/3]

SHAPE_SIMPLE::SHAPE_SIMPLE ( )
inline

Constructor Creates an empty polygon.

Definition at line 50 of file shape_simple.h.

50  :
52  {
53  m_points.SetClosed( true );
54  }
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:243
void SetClosed(bool aClosed)
Function SetClosed()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196
simple polygon
Definition: shape.h:47

References m_points, and SHAPE_LINE_CHAIN::SetClosed().

Referenced by Clone().

◆ SHAPE_SIMPLE() [2/3]

SHAPE_SIMPLE::SHAPE_SIMPLE ( const SHAPE_LINE_CHAIN aPoly)
inline

Definition at line 56 of file shape_simple.h.

56  :
58  m_points( aPoly )
59  {
60  m_points.SetClosed( true );
61  }
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:243
void SetClosed(bool aClosed)
Function SetClosed()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196
simple polygon
Definition: shape.h:47

References m_points, and SHAPE_LINE_CHAIN::SetClosed().

◆ SHAPE_SIMPLE() [3/3]

SHAPE_SIMPLE::SHAPE_SIMPLE ( const SHAPE_SIMPLE aOther)
inline

Definition at line 63 of file shape_simple.h.

63  :
65  {}
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:243
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196
simple polygon
Definition: shape.h:47

Member Function Documentation

◆ Append() [1/2]

void SHAPE_SIMPLE::Append ( int  aX,
int  aY 
)
inline

Function Append()

Appends a new point at the end of the polygon.

Parameters
aXis X coordinate of the new point
aYis Y coordinate of the new point

Definition at line 145 of file shape_simple.h.

146  {
147  VECTOR2I v( aX, aY );
148  Append( v );
149  }
Define a general 2D-vector/point.
Definition: vector2d.h:61
void Append(int aX, int aY)
Function Append()
Definition: shape_simple.h:145

Referenced by PNS_KICAD_IFACE_BASE::syncPad(), and PNS_KICAD_IFACE_BASE::syncZone().

◆ Append() [2/2]

void SHAPE_SIMPLE::Append ( const VECTOR2I aP)
inline

Function Append()

Appends a new point at the end of the polygon.

Parameters
aPthe new point

Definition at line 157 of file shape_simple.h.

158  {
159  m_points.Append( aP );
160  }
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References SHAPE_LINE_CHAIN::Append(), and m_points.

◆ BBox()

const BOX2I SHAPE_SIMPLE::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 82 of file shape_simple.h.

83  {
84  return m_points.BBox( aClearance );
85  }
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References SHAPE_LINE_CHAIN::BBox(), and m_points.

Referenced by PNS::ConvexHull(), and PNS::OPTIMIZER::customBreakouts().

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

◆ CDPoint()

const VECTOR2D SHAPE_SIMPLE::CDPoint ( int  aIndex) const
inline

Function CDPoint()

Returns a given point as a vector with elements of type double.

Parameters
aIndexindex of the point
Returns
the point with elements of type double

Definition at line 120 of file shape_simple.h.

121  {
122  const VECTOR2I& v = CPoint( aIndex );
123  return VECTOR2D( v.x, v.y );
124  }
const VECTOR2I & CPoint(int aIndex) const
Function Point()
Definition: shape_simple.h:107
Define a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622

References CPoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by ROUTER_PREVIEW_ITEM::drawShape().

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

◆ Clear()

void SHAPE_SIMPLE::Clear ( )
inline

Function Clear() Removes all points from the polygon.

Definition at line 76 of file shape_simple.h.

77  {
78  m_points.Clear();
79  }
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196
void Clear()
Function Clear() Removes all points from the line chain.

References SHAPE_LINE_CHAIN::Clear(), and m_points.

◆ Clone()

SHAPE* SHAPE_SIMPLE::Clone ( ) const
inlineoverridevirtual

Return a dynamically allocated copy of the shape.

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 67 of file shape_simple.h.

68  {
69  return new SHAPE_SIMPLE( *this );
70  }
SHAPE_SIMPLE()
Constructor Creates an empty polygon.
Definition: shape_simple.h:50

References SHAPE_SIMPLE().

◆ Collide() [1/4]

bool SHAPE_SIMPLE::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 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_LINE_CHAIN_BASE.

Definition at line 163 of file shape_simple.h.

165  {
166  return m_points.Collide( aSeg, aClearance, aActual, aLocation );
167  }
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.
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References SHAPE_LINE_CHAIN_BASE::Collide(), and m_points.

◆ Collide() [2/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 881 of file shape_collisions.cpp.

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

References collideShapes().

◆ Collide() [3/4]

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

Reimplemented in SHAPE_POLY_SET, SHAPE_RECT, SHAPE_SEGMENT, and SHAPE_COMPOUND.

Definition at line 887 of file shape_collisions.cpp.

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

References collideShapes().

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

Definition at line 88 of file shape_line_chain.cpp.

90 {
91  if( IsClosed() && PointInside( aP, aClearance ) )
92  {
93  if( aLocation )
94  *aLocation = aP;
95 
96  if( aActual )
97  *aActual = 0;
98 
99  return true;
100  }
101 
102  SEG::ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
103  SEG::ecoord clearance_sq = SEG::Square( aClearance );
104  VECTOR2I nearest;
105 
106  for( size_t i = 0; i < GetSegmentCount(); i++ )
107  {
108  const SEG& s = GetSegment( i );
109  VECTOR2I pn = s.NearestPoint( aP );
110  SEG::ecoord dist_sq = ( pn - aP ).SquaredEuclideanNorm();
111 
112  if( dist_sq < closest_dist_sq )
113  {
114  nearest = pn;
115  closest_dist_sq = dist_sq;
116 
117  if( closest_dist_sq == 0 )
118  break;
119 
120  // If we're not looking for aActual then any collision will do
121  if( closest_dist_sq < clearance_sq && !aActual )
122  break;
123  }
124  }
125 
126  if( closest_dist_sq == 0 || closest_dist_sq < clearance_sq )
127  {
128  if( aLocation )
129  *aLocation = nearest;
130 
131  if( aActual )
132  *aActual = sqrt( closest_dist_sq );
133 
134  return true;
135  }
136 
137  return false;
138 }
virtual bool IsClosed() const =0
VECTOR2I::extended_type ecoord
Definition: seg.h:44
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:123
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.h:437
Definition: seg.h:41
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 PNS::MEANDERED_LINE::CheckSelfIntersections(), Collide(), Collide(), and PCB_SELECTION_TOOL::hitTestDistance().

◆ CPoint()

const VECTOR2I& SHAPE_SIMPLE::CPoint ( int  aIndex) const
inline

Function Point()

Returns a const reference to a given point in the polygon. Negative indices count from the end of the point list, e.g. -1 means "last point", -2 means "second to last point" and so on.

Parameters
aIndexindex of the point
Returns
const reference to the point

Definition at line 107 of file shape_simple.h.

108  {
109  return m_points.CPoint( aIndex );
110  }
const VECTOR2I & CPoint(int aIndex) const
Function Point()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References SHAPE_LINE_CHAIN::CPoint(), and m_points.

Referenced by CDPoint().

◆ 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 901 of file shape_line_chain.cpp.

902 {
903  if( !GetPointCount() )
904  return -1;
905 
906  else if( GetPointCount() == 1 )
907  {
908  VECTOR2I dist = GetPoint(0) - aPt;
909  return ( hypot( dist.x, dist.y ) <= aAccuracy + 1 ) ? 0 : -1;
910  }
911 
912  for( size_t i = 0; i < GetSegmentCount(); i++ )
913  {
914  const SEG s = GetSegment( i );
915 
916  if( s.A == aPt || s.B == aPt )
917  return i;
918 
919  if( s.Distance( aPt ) <= aAccuracy + 1 )
920  return i;
921  }
922 
923  return -1;
924 }
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition: seg.h:239
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:41
virtual const SEG GetSegment(int aIndex) const =0
VECTOR2I A
Definition: seg.h:49
virtual const VECTOR2I GetPoint(int aIndex) const =0
VECTOR2I B
Definition: seg.h:50

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

◆ 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_SIMPLE::GetPoint ( int  aIndex) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 184 of file shape_simple.h.

184 { return m_points.CPoint(aIndex); }
const VECTOR2I & CPoint(int aIndex) const
Function Point()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References SHAPE_LINE_CHAIN::CPoint(), and m_points.

◆ GetPointCount()

virtual size_t SHAPE_SIMPLE::GetPointCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 186 of file shape_simple.h.

186 { return m_points.PointCount(); }
int PointCount() const
Function PointCount()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References m_points, and SHAPE_LINE_CHAIN::PointCount().

◆ GetSegment()

virtual const SEG SHAPE_SIMPLE::GetSegment ( int  aIndex) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 185 of file shape_simple.h.

185 { return m_points.CSegment(aIndex); }
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196
const SEG CSegment(int aIndex) const
Function CSegment()

References SHAPE_LINE_CHAIN::CSegment(), and m_points.

Referenced by PCB_GRID_HELPER::computeAnchors(), and KIGFX::PCB_PAINTER::draw().

◆ GetSegmentCount()

virtual size_t SHAPE_SIMPLE::GetSegmentCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 187 of file shape_simple.h.

187 { return m_points.SegmentCount(); }
int SegmentCount() const
Function SegmentCount()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References m_points, and SHAPE_LINE_CHAIN::SegmentCount().

Referenced by PCB_GRID_HELPER::computeAnchors(), and 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().

◆ IsClosed()

bool SHAPE_SIMPLE::IsClosed ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 189 of file shape_simple.h.

190  {
191  return true;
192  }

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

Implements SHAPE.

Definition at line 179 of file shape_simple.h.

180  {
181  return true;
182  }

◆ Move()

void SHAPE_SIMPLE::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 174 of file shape_simple.h.

175  {
176  m_points.Move( aVector );
177  }
void Move(const VECTOR2I &aVector) override
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References m_points, and SHAPE_LINE_CHAIN::Move().

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

◆ PointCount()

int SHAPE_SIMPLE::PointCount ( ) const
inline

Function PointCount()

Returns the number of points (vertices) in this polygon

Returns
number of points

Definition at line 93 of file shape_simple.h.

94  {
95  return m_points.PointCount();
96  }
int PointCount() const
Function PointCount()
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References m_points, and SHAPE_LINE_CHAIN::PointCount().

Referenced by ROUTER_PREVIEW_ITEM::drawShape().

◆ 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 peformance if the bounding box caches have been generated.
Returns
true if the point is inside the shape (edge is not treated as being inside).

To check for interior points, we draw a line in the positive x direction from the point. If it intersects an even number of segments, the point is outside the line chain (it had to first enter and then exit). Otherwise, it is inside the chain.

Note: slope might be denormal here in the case of a horizontal line but we require our y to move from above to below the point (or vice versa)

Note: we open-code CPoint() here so that we don't end up calculating the size of the vector number-of-points times. This has a non-trivial impact on zone fill times.

Definition at line 842 of file shape_line_chain.cpp.

844 {
845  /*
846  * Don't check the bounding box unless it's cached. Building it is about the same speed as
847  * the rigorous test below and so just slows things down by doing potentially two tests.
848  */
849  //if( aUseBBoxCache && !m_bbox.Contains( aPt ) )
850  //return false;
851 
852  // fixme: bbox cache...
853 
854  if( !IsClosed() || GetPointCount() < 3 )
855  return false;
856 
857  bool inside = false;
858 
870  int pointCount = GetPointCount();
871 
872  for( int i = 0; i < pointCount; )
873  {
874  const auto p1 = GetPoint( i++ );
875  const auto p2 = GetPoint( i == pointCount ? 0 : i );
876  const auto diff = p2 - p1;
877 
878  if( diff.y != 0 )
879  {
880  const int d = rescale( diff.x, ( aPt.y - p1.y ), diff.y );
881 
882  if( ( ( p1.y > aPt.y ) != ( p2.y > aPt.y ) ) && ( aPt.x - p1.x < d ) )
883  inside = !inside;
884  }
885  }
886 
887  // If accuracy is <= 1 (nm) then we skip the accuracy test for performance. Otherwise
888  // we use "OnEdge(accuracy)" as a proxy for "Inside(accuracy)".
889  if( aAccuracy <= 1 )
890  return inside;
891  else
892  return inside || PointOnEdge( aPt, aAccuracy );
893 }
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)
Function rescale()
Definition: util.h:95
virtual const VECTOR2I GetPoint(int aIndex) const =0

References 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_BASE::Collide(), POLY_GRID_PARTITION::containsPoint(), SHAPE_POLY_SET::containsSingle(), LIB_POLYLINE::HitTest(), ZONE::HitTestCutout(), MARKER_BASE::HitTestMarker(), SHAPE_LINE_CHAIN_BASE::SquaredDistance(), PNS::LINE::Walkaround(), and walkaround2().

◆ 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 896 of file shape_line_chain.cpp.

897 {
898  return EdgeContainingPoint( aPt, aAccuracy ) >= 0;
899 }
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 LIB_POLYLINE::HitTest(), FABMASTER::loadZones(), SHAPE_LINE_CHAIN_BASE::PointInside(), PNS::LINE::Walkaround(), and walkaround2().

◆ Rotate()

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

Implements SHAPE.

Definition at line 169 of file shape_simple.h.

169  { 0, 0 } ) override
170  {
171  m_points.Rotate( aAngle, aCenter );
172  }
void Rotate(double aAngle, const VECTOR2I &aCenter=VECTOR2I(0, 0)) override
Function Rotate rotates all vertices by a given angle.
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

◆ SquaredDistance()

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

Definition at line 398 of file shape_line_chain.cpp.

399 {
401 
402  if( IsClosed() && PointInside( aP ) && !aOutlineOnly )
403  return 0;
404 
405  for( size_t s = 0; s < GetSegmentCount(); s++ )
406  d = std::min( d, GetSegment( s ).SquaredDistance( aP ) );
407 
408  return d;
409 }
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

◆ Vertices()

const SHAPE_LINE_CHAIN& SHAPE_SIMPLE::Vertices ( ) const
inline

Function Vertices()

Returns the list of vertices defining this simple polygon.

Returns
the list of vertices defining this simple polygon

Definition at line 133 of file shape_simple.h.

134  {
135  return m_points;
136  }
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196

References m_points.

Referenced by PNS::ConvexHull(), PNS::OPTIMIZER::customBreakouts(), and KIGFX::PCB_PAINTER::draw().

Member Data Documentation

◆ m_points

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


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