KiCad PCB EDA Suite
SHAPE_SIMPLE Class Reference

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

#include <shape_simple.h>

Inheritance diagram for SHAPE_SIMPLE:
SHAPE_LINE_CHAIN_BASE SHAPE SHAPE_BASE

Public Member Functions

 SHAPE_SIMPLE ()
 Create 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 ()
 Remove 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
 Return the number of points (vertices) in this polygon. More...
 
const VECTOR2ICPoint (int aIndex) const
 Return a const reference to a given point in the polygon. More...
 
const VECTOR2D CDPoint (int aIndex) const
 Return a given point as a vector with elements of type double. More...
 
const SHAPE_LINE_CHAINVertices () const
 Return the list of vertices defining this simple polygon. More...
 
void Append (int aX, int aY)
 Append a new point at the end of the polygon. More...
 
void Append (const VECTOR2I &aP)
 Append a new point at the end of the polygon. 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 (const EDA_ANGLE &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...
 
virtual BOX2IGetCachedBBox () const
 
int GetClearance (const SHAPE *aOther) const
 Return the actual minimum distance between two shapes. 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 (bool aCplusPlus=true) 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...
 
wxString TypeName () const
 
virtual bool HasIndexableSubshapes () const
 
virtual size_t GetIndexableSubshapeCount () const
 
virtual void GetIndexableSubshapes (std::vector< const SHAPE * > &aSubshapes) const
 

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
 
std::list< FACET * > facets
 

Detailed Description

Represent 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 41 of file shape_simple.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 249 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_SIMPLE() [1/3]

SHAPE_SIMPLE::SHAPE_SIMPLE ( )
inline

Create an empty polygon.

Definition at line 47 of file shape_simple.h.

47 :
49 {
50 m_points.SetClosed( true );
51 }
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition: shape.h:256
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:185
@ SH_SIMPLE
simple polygon
Definition: shape.h:48

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 53 of file shape_simple.h.

53 :
55 m_points( aPoly )
56 {
57 m_points.SetClosed( true );
58 }

References m_points, and SHAPE_LINE_CHAIN::SetClosed().

◆ SHAPE_SIMPLE() [3/3]

SHAPE_SIMPLE::SHAPE_SIMPLE ( const SHAPE_SIMPLE aOther)
inline

Definition at line 60 of file shape_simple.h.

60 :
62 {}

Member Function Documentation

◆ Append() [1/2]

void SHAPE_SIMPLE::Append ( const VECTOR2I aP)
inline

Append a new point at the end of the polygon.

Parameters
aPis the new point.

Definition at line 146 of file shape_simple.h.

147 {
148 m_points.Append( aP );
149 }
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.

References SHAPE_LINE_CHAIN::Append(), and m_points.

◆ Append() [2/2]

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

Append 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 135 of file shape_simple.h.

136 {
137 VECTOR2I v( aX, aY );
138 Append( v );
139 }
void Append(int aX, int aY)
Append a new point at the end of the polygon.
Definition: shape_simple.h:135

References Append().

Referenced by Append(), EDA_TEXT::GetEffectiveTextShape(), and PNS_KICAD_IFACE_BASE::syncZone().

◆ 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 78 of file shape_simple.h.

79 {
80 return m_points.BBox( aClearance );
81 }
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.

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 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}
IFSG_COLORS is the wrapper for SGCOLORS.
Definition: ifsg_colors.h:42
IFSG_COORDINDEX is the wrapper for SGCOORDINDEX.
IFSG_COORDS is the wrapper for SGCOORDS.
Definition: ifsg_coords.h:41
IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:41
IFSG_NORMALS is the wrapper for the SGNORMALS class.
Definition: ifsg_normals.h:41
IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:41
double z
Definition: sg_base.h:72
double x
Definition: sg_base.h:70
double y
Definition: sg_base.h:71
std::list< FACET * > facets
Definition: wrlfacet.h:143
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:494

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

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

◆ CDPoint()

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

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

Parameters
aIndexis the index of the point.
Returns
the point with elements of type double.

Definition at line 113 of file shape_simple.h.

114 {
115 const VECTOR2I& v = CPoint( aIndex );
116 return VECTOR2D( v.x, v.y );
117 }
const VECTOR2I & CPoint(int aIndex) const
Return a const reference to a given point in the polygon.
Definition: shape_simple.h:102
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617

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

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

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

Referenced by Collide().

◆ Clear()

void SHAPE_SIMPLE::Clear ( )
inline

Remove all points from the polygon.

Definition at line 72 of file shape_simple.h.

73 {
75 }
void Clear()
Remove 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 64 of file shape_simple.h.

65 {
66 return new SHAPE_SIMPLE( *this );
67 }
SHAPE_SIMPLE()
Create an empty polygon.
Definition: shape_simple.h:47

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 152 of file shape_simple.h.

154 {
155 return m_points.Collide( aSeg, aClearance, aActual, aLocation );
156 }
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.

References SHAPE_LINE_CHAIN::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_COMPOUND, SHAPE_RECT, and SHAPE_SEGMENT.

Definition at line 1109 of file shape_collisions.cpp.

1110{
1111 return collideShapes( this, aShape, aClearance, nullptr, nullptr, aMTV );
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::Collide ( const SHAPE aShape,
int  aClearance = 0,
int *  aActual = nullptr,
VECTOR2I aLocation = nullptr 
) const
virtualinherited

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

Definition at line 1115 of file shape_collisions.cpp.

1116{
1117 return collideShapes( this, aShape, aClearance, aActual, aLocation, nullptr );
1118}

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.

Reimplemented in SHAPE_LINE_CHAIN.

Definition at line 385 of file shape_line_chain.cpp.

387{
388 if( IsClosed() && PointInside( aP, aClearance ) )
389 {
390 if( aLocation )
391 *aLocation = aP;
392
393 if( aActual )
394 *aActual = 0;
395
396 return true;
397 }
398
399 SEG::ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
400 SEG::ecoord clearance_sq = SEG::Square( aClearance );
401 VECTOR2I nearest;
402
403 for( size_t i = 0; i < GetSegmentCount(); i++ )
404 {
405 const SEG& s = GetSegment( i );
406 VECTOR2I pn = s.NearestPoint( aP );
407 SEG::ecoord dist_sq = ( pn - aP ).SquaredEuclideanNorm();
408
409 if( dist_sq < closest_dist_sq )
410 {
411 nearest = pn;
412 closest_dist_sq = dist_sq;
413
414 if( closest_dist_sq == 0 )
415 break;
416
417 // If we're not looking for aActual then any collision will do
418 if( closest_dist_sq < clearance_sq && !aActual )
419 break;
420 }
421 }
422
423 if( closest_dist_sq == 0 || closest_dist_sq < clearance_sq )
424 {
425 if( aLocation )
426 *aLocation = nearest;
427
428 if( aActual )
429 *aActual = sqrt( closest_dist_sq );
430
431 return true;
432 }
433
434 return false;
435}
Definition: seg.h:42
VECTOR2I::extended_type ecoord
Definition: seg.h:44
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition: seg.cpp:261
static SEG::ecoord Square(int a)
Definition: seg.h:123
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 size_t GetSegmentCount() const =0
virtual bool IsClosed() const =0
virtual const SEG GetSegment(int aIndex) const =0
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:79

References VECTOR2< int >::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().

◆ CPoint()

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

Return 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
aIndexis the index of the point.
Returns
the const reference to the point.

Definition at line 102 of file shape_simple.h.

103 {
104 return m_points.CPoint( aIndex );
105 }
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.

References SHAPE_LINE_CHAIN::CPoint(), and m_points.

Referenced by CDPoint(), and KIGFX::PCB_PAINTER::draw().

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

1674{
1675 if( !GetPointCount() )
1676 {
1677 return -1;
1678 }
1679 else if( GetPointCount() == 1 )
1680 {
1681 VECTOR2I dist = GetPoint(0) - aPt;
1682 return ( hypot( dist.x, dist.y ) <= aAccuracy + 1 ) ? 0 : -1;
1683 }
1684
1685 for( size_t i = 0; i < GetSegmentCount(); i++ )
1686 {
1687 const SEG s = GetSegment( i );
1688
1689 if( s.A == aPt || s.B == aPt )
1690 return i;
1691
1692 if( s.Distance( aPt ) <= aAccuracy + 1 )
1693 return i;
1694 }
1695
1696 return -1;
1697}
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition: seg.cpp:319
virtual size_t GetPointCount() const =0
virtual const VECTOR2I GetPoint(int aIndex) const =0

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 ( bool  aCplusPlus = true) const
virtualinherited

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

Definition at line 41 of file shape.cpp.

42{
43 std::stringstream ss;
44 ss << "shape " << m_type;
45 return ss.str();
46}
SHAPE_TYPE m_type
< type of our shape
Definition: shape.h:116

References SHAPE_BASE::m_type.

Referenced by SHAPE_CIRCLE::Format(), SHAPE_SEGMENT::Format(), and SHAPE_FILE_IO::Write().

◆ GetCachedBBox()

virtual BOX2I * SHAPE_LINE_CHAIN_BASE::GetCachedBBox ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_LINE_CHAIN.

Definition at line 325 of file shape.h.

325{ return nullptr; }

Referenced by SHAPE_LINE_CHAIN_BASE::PointInside().

◆ GetClearance()

int SHAPE::GetClearance ( const SHAPE aOther) const
inherited

Return the actual minimum distance between two shapes.

Return values
distancein IU

Definition at line 49 of file shape.cpp.

50{
51 int actual_clearance = std::numeric_limits<int>::max();
52 std::vector<const SHAPE*> a_shapes;
53 std::vector<const SHAPE*> b_shapes;
54
55 GetIndexableSubshapes( a_shapes );
56 aOther->GetIndexableSubshapes( b_shapes );
57
58 if( GetIndexableSubshapeCount() == 0 )
59 a_shapes.push_back( this );
60
61 if( aOther->GetIndexableSubshapeCount() == 0 )
62 b_shapes.push_back( aOther );
63
64 for( const SHAPE* a : a_shapes )
65 {
66 for( const SHAPE* b : b_shapes )
67 {
68 int temp_dist = 0;
69 a->Collide( b, std::numeric_limits<int>::max() / 2, &temp_dist );
70
71 if( temp_dist < actual_clearance )
72 actual_clearance = temp_dist;
73 }
74 }
75
76 return actual_clearance;
77}
virtual size_t GetIndexableSubshapeCount() const
Definition: shape.h:110
virtual void GetIndexableSubshapes(std::vector< const SHAPE * > &aSubshapes) const
Definition: shape.h:112
An abstract shape on 2D plane.
Definition: shape.h:123

References SHAPE_BASE::GetIndexableSubshapeCount(), and SHAPE_BASE::GetIndexableSubshapes().

◆ GetIndexableSubshapeCount()

virtual size_t SHAPE_BASE::GetIndexableSubshapeCount ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_COMPOUND, and SHAPE_POLY_SET.

Definition at line 110 of file shape.h.

110{ return 0; }

Referenced by SHAPE::GetClearance().

◆ GetIndexableSubshapes()

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

Reimplemented in SHAPE_COMPOUND, and SHAPE_POLY_SET.

Definition at line 112 of file shape.h.

112{ }

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

◆ GetPoint()

virtual const VECTOR2I SHAPE_SIMPLE::GetPoint ( int  aIndex) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 173 of file shape_simple.h.

173{ return m_points.CPoint(aIndex); }

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 175 of file shape_simple.h.

175{ return m_points.PointCount(); }
int PointCount() const
Return the number of points (vertices) in this line chain.

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 174 of file shape_simple.h.

174{ return m_points.CSegment(aIndex); }
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.

References SHAPE_LINE_CHAIN::CSegment(), and m_points.

Referenced by KIGFX::PCB_PAINTER::draw(), and STROKE_PARAMS::Stroke().

◆ GetSegmentCount()

virtual size_t SHAPE_SIMPLE::GetSegmentCount ( ) const
inlineoverridevirtual

Implements SHAPE_LINE_CHAIN_BASE.

Definition at line 176 of file shape_simple.h.

176{ return m_points.SegmentCount(); }
int SegmentCount() const
Return the number of segments in this line chain.

References m_points, and SHAPE_LINE_CHAIN::SegmentCount().

Referenced by KIGFX::PCB_PAINTER::draw(), and STROKE_PARAMS::Stroke().

◆ HasIndexableSubshapes()

virtual bool SHAPE_BASE::HasIndexableSubshapes ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_COMPOUND, and SHAPE_POLY_SET.

Definition at line 105 of file shape.h.

106 {
107 return false;
108 }

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 178 of file shape_simple.h.

179 {
180 return true;
181 }

◆ IsNull()

bool SHAPE::IsNull ( ) const
inlineinherited

Return true if the shape is a null shape.

Return values
trueif null :-)

Definition at line 163 of file shape.h.

164 {
165 return m_type == SH_NULL;
166 }
@ SH_NULL
empty shape (no shape...),
Definition: shape.h:52

References SHAPE_BASE::m_type, and SH_NULL.

◆ IsSolid()

bool SHAPE_SIMPLE::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 168 of file shape_simple.h.

169 {
170 return true;
171 }

◆ Move()

void SHAPE_SIMPLE::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 163 of file shape_simple.h.

164 {
165 m_points.Move( aVector );
166 }
void Move(const VECTOR2I &aVector) override

References m_points, and SHAPE_LINE_CHAIN::Move().

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

References SHAPE::facets.

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

◆ Parse()

bool SHAPE::Parse ( std::stringstream &  aStream)
virtualinherited

Reimplemented in SHAPE_LINE_CHAIN, and SHAPE_POLY_SET.

Definition at line 34 of file shape.cpp.

35{
36 assert( false );
37 return false;
38}

◆ PointCount()

int SHAPE_SIMPLE::PointCount ( ) const
inline

Return the number of points (vertices) in this polygon.

Returns
number of points.

Definition at line 88 of file shape_simple.h.

89 {
90 return m_points.PointCount();
91 }

References m_points, and SHAPE_LINE_CHAIN::PointCount().

Referenced by KIGFX::PCB_PAINTER::draw(), and 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 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 1615 of file shape_line_chain.cpp.

1617{
1618 /*
1619 * Don't check the bounding box unless it's cached. Building it is about the same speed as
1620 * the rigorous test below and so just slows things down by doing potentially two tests.
1621 */
1622 if( aUseBBoxCache && GetCachedBBox() && !GetCachedBBox()->Contains( aPt ) )
1623 return false;
1624
1625 if( !IsClosed() || GetPointCount() < 3 )
1626 return false;
1627
1628 bool inside = false;
1629
1630 /*
1631 * To check for interior points, we draw a line in the positive x direction from
1632 * the point. If it intersects an even number of segments, the point is outside the
1633 * line chain (it had to first enter and then exit). Otherwise, it is inside the chain.
1634 *
1635 * Note: slope might be denormal here in the case of a horizontal line but we require our
1636 * y to move from above to below the point (or vice versa)
1637 *
1638 * Note: we open-code CPoint() here so that we don't end up calculating the size of the
1639 * vector number-of-points times. This has a non-trivial impact on zone fill times.
1640 */
1641 int pointCount = GetPointCount();
1642
1643 for( int i = 0; i < pointCount; )
1644 {
1645 const auto p1 = GetPoint( i++ );
1646 const auto p2 = GetPoint( i == pointCount ? 0 : i );
1647 const auto diff = p2 - p1;
1648
1649 if( diff.y != 0 )
1650 {
1651 const int d = rescale( diff.x, ( aPt.y - p1.y ), diff.y );
1652
1653 if( ( ( p1.y > aPt.y ) != ( p2.y > aPt.y ) ) && ( aPt.x - p1.x < d ) )
1654 inside = !inside;
1655 }
1656 }
1657
1658 // If accuracy is <= 1 (nm) then we skip the accuracy test for performance. Otherwise
1659 // we use "OnEdge(accuracy)" as a proxy for "Inside(accuracy)".
1660 if( aAccuracy <= 1 )
1661 return inside;
1662 else
1663 return inside || PointOnEdge( aPt, aAccuracy );
1664}
bool PointOnEdge(const VECTOR2I &aP, int aAccuracy=0) const
Check if point aP lies on an edge or vertex of the line chain.
virtual BOX2I * GetCachedBBox() const
Definition: shape.h:325
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).
Definition: util.h:118

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_BASE::Collide(), SHAPE_LINE_CHAIN::Collide(), SHAPE_POLY_SET::containsSingle(), ConvertOutlineToPolygon(), ZONE::HitTestCutout(), MARKER_BASE::HitTestMarker(), CONNECTIVITY_DATA::IsConnectedOnLayer(), DRC_RTREE::QueryColliding(), SHAPE_LINE_CHAIN_BASE::SquaredDistance(), DRC_TEST_PROVIDER_ZONE_CONNECTIONS::testZoneLayer(), 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 1667 of file shape_line_chain.cpp.

1668{
1669 return EdgeContainingPoint( aPt, aAccuracy ) >= 0;
1670}
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(), PNS::LINE_PLACER::splitHeadTail(), and PNS::LINE::Walkaround().

◆ Rotate()

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

Implements SHAPE.

Definition at line 158 of file shape_simple.h.

158 { 0, 0 } ) override
159 {
160 m_points.Rotate( aAngle, aCenter );
161 }
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.

◆ SquaredDistance()

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

Definition at line 884 of file shape_line_chain.cpp.

885{
887
888 if( IsClosed() && PointInside( aP ) && !aOutlineOnly )
889 return 0;
890
891 for( size_t s = 0; s < GetSegmentCount(); s++ )
892 d = std::min( d, GetSegment( s ).SquaredDistance( aP ) );
893
894 return d;
895}
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:75
VECTOR2I::extended_type ecoord

References VECTOR2< int >::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()

◆ TypeName()

wxString SHAPE_BASE::TypeName ( ) const
inlineinherited

Definition at line 100 of file shape.h.

101 {
102 return SHAPE_TYPE_asString( m_type );
103 }
static wxString SHAPE_TYPE_asString(SHAPE_TYPE a)
Definition: shape.h:56

References SHAPE_BASE::m_type, and SHAPE_TYPE_asString().

Referenced by Collide().

◆ Vertices()

const SHAPE_LINE_CHAIN & SHAPE_SIMPLE::Vertices ( ) const
inline

Return the list of vertices defining this simple polygon.

Returns
the list of vertices defining this simple polygon.

Definition at line 124 of file shape_simple.h.

125 {
126 return m_points;
127 }

References m_points.

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

Member Data Documentation

◆ facets

std::list< FACET* > SHAPE::facets
privateinherited

Definition at line 143 of file wrlfacet.h.

Referenced by SHAPE::CalcShape(), and SHAPE::NewFacet().

◆ m_points

◆ m_type

SHAPE_TYPE SHAPE_BASE::m_type
protectedinherited

< type of our shape

Definition at line 116 of file shape.h.

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

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

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


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