KiCad PCB EDA Suite
SHAPE_ARC Class Reference

#include <shape_arc.h>

Inheritance diagram for SHAPE_ARC:
SHAPE SHAPE_BASE

Public Member Functions

 SHAPE_ARC ()
 
 SHAPE_ARC (const VECTOR2I &aArcCenter, const VECTOR2I &aArcStartPoint, double aCenterAngle, int aWidth=0)
 Construct and arc using center, start, angle. More...
 
 SHAPE_ARC (const VECTOR2I &aArcStart, const VECTOR2I &aArcMid, const VECTOR2I &aArcEnd, int aWidth)
 
 SHAPE_ARC (const SEG &aSegmentA, const SEG &aSegmentB, int aRadius, int aWidth=0)
 Build a SHAPE_ARC which is tangent to two segments and a given radius. More...
 
 SHAPE_ARC (const SHAPE_ARC &aOther)
 
virtual ~SHAPE_ARC ()
 
SHAPEClone () const override
 Return a dynamically allocated copy of the shape. More...
 
SHAPE_ARCConstructFromStartEndAngle (const VECTOR2I &aStart, const VECTOR2I &aEnd, double aAngle, double aWidth=0)
 Construct this arc from the given start, end and angle. More...
 
SHAPE_ARCConstructFromStartEndCenter (const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
 Constructs this arc from the given start, end and center. More...
 
const VECTOR2IGetP0 () const
 
const VECTOR2IGetP1 () const
 
const VECTOR2IGetArcMid () const
 
VECTOR2I GetCenter () const
 
const BOX2I BBox (int aClearance=0) const override
 Compute a bounding box of the shape, with a margin of aClearance a collision. More...
 
bool Collide (const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
 Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating a collision. More...
 
bool Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
 Check if the boundary of shape (this) lies closer to the point aP than aClearance, indicating a collision. More...
 
bool IsClockwise () const
 
void SetWidth (int aWidth)
 
int GetWidth () const
 
bool IsSolid () const override
 
void Move (const VECTOR2I &aVector) override
 
void Rotate (double aAngle, const VECTOR2I &aCenter) override
 Rotate the arc by a given angle about a point. More...
 
void Mirror (bool aX=true, bool aY=false, const VECTOR2I &aVector={ 0, 0 })
 
void Mirror (const SEG &axis)
 
void Reverse ()
 
SHAPE_ARC Reversed () const
 
double GetRadius () const
 
SEG GetChord () const
 
double GetCentralAngle () const
 
double GetStartAngle () const
 
double GetEndAngle () const
 
double GetLength () const
 
const SHAPE_LINE_CHAIN ConvertToPolyline (double aAccuracy=DefaultAccuracyForPCB(), double *aEffectiveAccuracy=nullptr) const
 Construct a SHAPE_LINE_CHAIN of segments from a given arc. More...
 
bool operator== (SHAPE_ARC const &aArc) const
 
bool IsNull () const
 Return true if the shape is a null shape. 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
 
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 Member Functions

static double DefaultAccuracyForPCB ()
 

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 Member Functions

bool ccw (const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
 
void update_bbox ()
 

Private Attributes

VECTOR2I m_start
 
VECTOR2I m_mid
 
VECTOR2I m_end
 
int m_width
 
BOX2I m_bbox
 

Detailed Description

Definition at line 35 of file shape_arc.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 236 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_ARC() [1/5]

SHAPE_ARC::SHAPE_ARC ( )
inline

Definition at line 39 of file shape_arc.h.

39  :
40  SHAPE( SH_ARC ),
41  m_width( 0 )
42  {};
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
circular arc
Definition: shape.h:50
int m_width
Definition: shape_arc.h:234

Referenced by Clone(), and Reversed().

◆ SHAPE_ARC() [2/5]

SHAPE_ARC::SHAPE_ARC ( const VECTOR2I aArcCenter,
const VECTOR2I aArcStartPoint,
double  aCenterAngle,
int  aWidth = 0 
)

Construct and arc using center, start, angle.

Center and angle are used to calculate the mid and end points of the arc, and are not stored.

Parameters
aArcCenteris the arc center.
aArcStartPointis the arc start point.
aCenterAngleis the arc angle in degrees.
aWidthis the arc line thickness.

Definition at line 41 of file shape_arc.cpp.

42  :
43  SHAPE( SH_ARC ), m_width( aWidth )
44 {
45  m_start = aArcStartPoint;
46  m_mid = aArcStartPoint;
47  m_end = aArcStartPoint;
48 
49  RotatePoint( m_mid, aArcCenter, -aCenterAngle * 10.0 / 2.0 );
50  RotatePoint( m_end, aArcCenter, -aCenterAngle * 10.0 );
51 
52  update_bbox();
53 }
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
VECTOR2I m_end
Definition: shape_arc.h:232
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
VECTOR2I m_mid
Definition: shape_arc.h:231
circular arc
Definition: shape.h:50
void update_bbox()
Definition: shape_arc.cpp:299
VECTOR2I m_start
Definition: shape_arc.h:230
int m_width
Definition: shape_arc.h:234

References m_end, m_mid, m_start, RotatePoint(), and update_bbox().

◆ SHAPE_ARC() [3/5]

SHAPE_ARC::SHAPE_ARC ( const VECTOR2I aArcStart,
const VECTOR2I aArcMid,
const VECTOR2I aArcEnd,
int  aWidth 
)
Parameters
aArcStartis the arc start point.
aArcEndis the arc end point.
aArcMidis the arc mid point.
aWidthis the arc line thickness.

Definition at line 56 of file shape_arc.cpp.

57  :
58  SHAPE( SH_ARC ), m_start( aArcStart ), m_mid( aArcMid ), m_end( aArcEnd ),
59  m_width( aWidth )
60 {
61  update_bbox();
62 }
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
VECTOR2I m_end
Definition: shape_arc.h:232
VECTOR2I m_mid
Definition: shape_arc.h:231
circular arc
Definition: shape.h:50
void update_bbox()
Definition: shape_arc.cpp:299
VECTOR2I m_start
Definition: shape_arc.h:230
int m_width
Definition: shape_arc.h:234

References update_bbox().

◆ SHAPE_ARC() [4/5]

SHAPE_ARC::SHAPE_ARC ( const SEG aSegmentA,
const SEG aSegmentB,
int  aRadius,
int  aWidth = 0 
)

Build a SHAPE_ARC which is tangent to two segments and a given radius.

Parameters
aSegmentAis the first segment
aSegmentBis the second segment
aRadiusis the arc radius
aWidthis the arc line thickness

Definition at line 65 of file shape_arc.cpp.

66  : SHAPE( SH_ARC )
67 {
68  m_width = aWidth;
69 
70  /*
71  * Construct an arc that is tangent to two segments with a given radius.
72  *
73  * p
74  * A
75  * A \
76  * / \
77  * / . . \ segB
78  * /. .\
79  * segA / c \
80  * / B
81  * /
82  * /
83  * B
84  *
85  *
86  * segA is the fist segment (with its points A and B)
87  * segB is the second segment (with its points A and B)
88  * p is the point at which segA and segB would intersect if they were projected
89  * c is the centre of the arc to be constructed
90  * rad is the radius of the arc to be constructed
91  *
92  * We can create two vectors, between point p and segA /segB
93  * pToA = p - segA.B //< note that segA.A would also be valid as it is colinear
94  * pToB = p - segB.B //< note that segB.A would also be valid as it is colinear
95  *
96  * Let the angle formed by segA and segB be called 'alpha':
97  * alpha = angle( pToA ) - angle( pToB )
98  *
99  * The distance PC can be computed as
100  * distPC = rad / abs( sin( alpha / 2 ) )
101  *
102  * The polar angle of the vector PC can be computed as:
103  * anglePC = angle( pToA ) + alpha / 2
104  *
105  * Therefore:
106  * C.x = P.x + distPC*cos( anglePC )
107  * C.y = P.y + distPC*sin( anglePC )
108  */
109 
110  OPT_VECTOR2I p = aSegmentA.Intersect( aSegmentB, true, true );
111 
112  if( !p || aSegmentA.Length() == 0 || aSegmentB.Length() == 0 )
113  {
114  // Catch bugs in debug
115  wxASSERT_MSG( false, "The input segments do not intersect or one is zero length." );
116 
117  // Make a 180 degree arc around aSegmentA in case we end up here in release
118  m_start = aSegmentA.A;
119  m_end = aSegmentA.B;
120  m_mid = m_start;
121 
122  VECTOR2I arcCenter = aSegmentA.Center();
123  RotatePoint( m_mid, arcCenter, 900.0 ); // mid point at 90 degrees
124  }
125  else
126  {
127  VECTOR2I pToA = aSegmentA.B - p.get();
128  VECTOR2I pToB = aSegmentB.B - p.get();
129 
130  if( pToA.EuclideanNorm() == 0 )
131  pToA = aSegmentA.A - p.get();
132 
133  if( pToB.EuclideanNorm() == 0 )
134  pToB = aSegmentB.A - p.get();
135 
136  double pToAangle = ArcTangente( pToA.y, pToA.x );
137  double pToBangle = ArcTangente( pToB.y, pToB.x );
138 
139  double alpha = NormalizeAngle180( pToAangle - pToBangle );
140 
141  double distPC = (double) aRadius / abs( sin( DECIDEG2RAD( alpha / 2 ) ) );
142  double angPC = pToAangle - alpha / 2;
143 
144  VECTOR2I arcCenter;
145 
146  arcCenter.x = p.get().x + KiROUND( distPC * cos( DECIDEG2RAD( angPC ) ) );
147  arcCenter.y = p.get().y + KiROUND( distPC * sin( DECIDEG2RAD( angPC ) ) );
148 
149  // The end points of the arc are the orthogonal projected lines from the line segments
150  // to the center of the arc
151  m_start = aSegmentA.LineProject( arcCenter );
152  m_end = aSegmentB.LineProject( arcCenter );
153 
154  //The mid point is rotated start point around center, half the angle of the arc.
155  VECTOR2I startVector = m_start - arcCenter;
156  VECTOR2I endVector = m_end - arcCenter;
157 
158  double startAngle = ArcTangente( startVector.y, startVector.x );
159  double endAngle = ArcTangente( endVector.y, endVector.x );
160 
161  double midPointRotAngle = NormalizeAngle180( startAngle - endAngle ) / 2;
162  m_mid = m_start;
163  RotatePoint( m_mid, arcCenter, midPointRotAngle );
164  }
165 
166  update_bbox();
167 }
int Length() const
Return the length (this).
Definition: seg.h:350
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
Definition: seg.cpp:154
VECTOR2I m_end
Definition: shape_arc.h:232
Define a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2I Center() const
Definition: seg.h:386
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
T NormalizeAngle180(T Angle)
Normalize angle to be in the -180.0 .. 180.0 range.
Definition: trigo.h:387
VECTOR2I m_mid
Definition: shape_arc.h:231
VECTOR2I LineProject(const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.
Definition: seg.cpp:268
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:38
circular arc
Definition: shape.h:50
void update_bbox()
Definition: shape_arc.cpp:299
VECTOR2I m_start
Definition: shape_arc.h:230
VECTOR2I A
Definition: seg.h:48
double DECIDEG2RAD(double deg)
Definition: trigo.h:233
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:183
int m_width
Definition: shape_arc.h:234
VECTOR2I B
Definition: seg.h:49

References SEG::A, ArcTangente(), SEG::B, SEG::Center(), DECIDEG2RAD(), VECTOR2< T >::EuclideanNorm(), SEG::Intersect(), KiROUND(), SEG::Length(), SEG::LineProject(), m_end, m_mid, m_start, m_width, NormalizeAngle180(), RotatePoint(), update_bbox(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ SHAPE_ARC() [5/5]

SHAPE_ARC::SHAPE_ARC ( const SHAPE_ARC aOther)

Definition at line 170 of file shape_arc.cpp.

171  : SHAPE( SH_ARC )
172 {
173  m_start = aOther.m_start;
174  m_end = aOther.m_end;
175  m_mid = aOther.m_mid;
176  m_width = aOther.m_width;
177  m_bbox = aOther.m_bbox;
178 }
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
VECTOR2I m_end
Definition: shape_arc.h:232
VECTOR2I m_mid
Definition: shape_arc.h:231
circular arc
Definition: shape.h:50
VECTOR2I m_start
Definition: shape_arc.h:230
int m_width
Definition: shape_arc.h:234
BOX2I m_bbox
Definition: shape_arc.h:235

References m_bbox, m_end, m_mid, m_start, and m_width.

◆ ~SHAPE_ARC()

virtual SHAPE_ARC::~SHAPE_ARC ( )
inlinevirtual

Definition at line 79 of file shape_arc.h.

79 {}

Member Function Documentation

◆ BBox()

const BOX2I SHAPE_ARC::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 341 of file shape_arc.cpp.

342 {
343  BOX2I bbox( m_bbox );
344 
345  if( aClearance != 0 )
346  bbox.Inflate( aClearance );
347 
348  return bbox;
349 }
A 2D bounding box built on top of an origin point and size vector.
Definition: box2.h:41
BOX2I m_bbox
Definition: shape_arc.h:235

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

Referenced by CheckArcGeom(), Collide(), and GERBER_DRAW_ITEM::GetBoundingBox().

◆ 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_FACESET::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COLORS::SetColorList(), IFSG_COORDS::SetCoordsList(), IFSG_NORMALS::SetNormalList(), SGPOINT::x, SGPOINT::y, and SGPOINT::z.

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

◆ ccw()

bool SHAPE_ARC::ccw ( const VECTOR2I aA,
const VECTOR2I aB,
const VECTOR2I aC 
) const
inlineprivate

Definition at line 221 of file shape_arc.h.

222  {
223  return ( ecoord{ aC.y } - aA.y ) * ( ecoord{ aB.x } - aA.x ) >
224  ( ecoord{ aB.y } - aA.y ) * ( ecoord{ aC.x } - aA.x );
225  }
VECTOR2I::extended_type ecoord

References VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Collide().

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

SHAPE* SHAPE_ARC::Clone ( ) const
inlineoverridevirtual

Return a dynamically allocated copy of the shape.

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 81 of file shape_arc.h.

82  {
83  return new SHAPE_ARC( *this );
84  }
SHAPE_ARC()
Definition: shape_arc.h:39

References SHAPE_ARC().

Referenced by CheckArc().

◆ Collide() [1/4]

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

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

Parameters
aActual[out] an optional pointer to an int to be updated with the actual distance int the event of a collision.
aLocation[out] an option pointer to a point to store a nearby location in the event of a collision.
Returns
true, if there is a collision.

Implements SHAPE.

Definition at line 227 of file shape_arc.cpp.

228 {
229  if( aSeg.A == aSeg.B )
230  return Collide( aSeg.A, aClearance, aActual, aLocation );
231 
232  int minDist = aClearance + m_width / 2;
233  VECTOR2I center = GetCenter();
234  ecoord dist_sq;
235  ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
236  VECTOR2I nearest;
237 
238  VECTOR2I ab = ( aSeg.B - aSeg.A );
239  VECTOR2I ac = ( center - aSeg.A );
240 
241  ecoord lenAbSq = ab.SquaredEuclideanNorm();
242  double lambda = (double) ac.Dot( ab ) / (double) lenAbSq;
243 
244  if( lambda >= 0.0 && lambda <= 1.0 )
245  {
246  VECTOR2I p;
247 
248  p.x = (double) aSeg.A.x * lambda + (double) aSeg.B.x * (1.0 - lambda);
249  p.y = (double) aSeg.A.y * lambda + (double) aSeg.B.y * (1.0 - lambda);
250 
251  dist_sq = ( m_start - p ).SquaredEuclideanNorm();
252 
253  if( dist_sq < closest_dist_sq )
254  {
255  closest_dist_sq = dist_sq;
256  nearest = p;
257  }
258 
259  dist_sq = ( m_end - p ).SquaredEuclideanNorm();
260 
261  if( dist_sq < closest_dist_sq )
262  {
263  closest_dist_sq = dist_sq;
264  nearest = p;
265  }
266  }
267 
268  dist_sq = aSeg.SquaredDistance( m_start );
269 
270  if( dist_sq < closest_dist_sq )
271  {
272  closest_dist_sq = dist_sq;
273  nearest = m_start;
274  }
275 
276  dist_sq = aSeg.SquaredDistance( m_end );
277 
278  if( dist_sq < closest_dist_sq )
279  {
280  closest_dist_sq = dist_sq;
281  nearest = m_end;
282  }
283 
284  if( closest_dist_sq == 0 || closest_dist_sq < SEG::Square( minDist ) )
285  {
286  if( aLocation )
287  *aLocation = nearest;
288 
289  if( aActual )
290  *aActual = std::max( 0, (int) sqrt( closest_dist_sq ) - m_width / 2 );
291 
292  return true;
293  }
294 
295  return false;
296 }
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
Definition: shape_arc.cpp:227
VECTOR2I m_end
Definition: shape_arc.h:232
Define a general 2D-vector/point.
Definition: vector2d.h:61
extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
Definition: vector2d.h:300
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:39
static SEG::ecoord Square(int a)
Definition: seg.h:122
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:79
VECTOR2I::extended_type ecoord
extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition: vector2d.h:521
VECTOR2I m_start
Definition: shape_arc.h:230
VECTOR2I A
Definition: seg.h:48
int m_width
Definition: shape_arc.h:234
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:425
VECTOR2I B
Definition: seg.h:49

References SEG::A, SEG::B, VECTOR2< T >::Dot(), VECTOR2< T >::ECOORD_MAX, GetCenter(), m_end, m_start, m_width, SEG::Square(), SEG::SquaredDistance(), VECTOR2< T >::SquaredEuclideanNorm(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE(), and GEOM_TEST::IsOutlineValid().

◆ Collide() [2/4]

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

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

Parameters
aActual[out] an optional pointer to an int to store the actual distance in the event of a collision.
aLocation[out] an option pointer to a point to store a nearby location in the event of a collision.
Returns
true, if there is a collision.

Reimplemented from SHAPE.

Definition at line 358 of file shape_arc.cpp.

360 {
361  int minDist = aClearance + m_width / 2;
362  auto bbox = BBox( minDist );
363 
364  // Fast check using bounding box:
365  if( !bbox.Contains( aP ) )
366  return false;
367 
368  VECTOR2I center = GetCenter();
369  VECTOR2I vec = aP - center;
370 
371  int dist = abs( vec.EuclideanNorm() - GetRadius() );
372 
373  // If not a 360 degree arc, need to use arc angles to decide if point collides
374  if( m_start != m_end )
375  {
376  bool ccw = GetCentralAngle() > 0.0;
377  double rotatedVecAngle = NormalizeAngleDegreesPos( NormalizeAngleDegreesPos( RAD2DEG( vec.Angle() ) )
378  - GetStartAngle() );
379  double rotatedEndAngle = NormalizeAngleDegreesPos( GetEndAngle() - GetStartAngle() );
380 
381  if( ( ccw && rotatedVecAngle > rotatedEndAngle )
382  || ( !ccw && rotatedVecAngle < rotatedEndAngle ) )
383  {
384  int distStartpt = ( aP - m_start ).EuclideanNorm();
385  int distEndpt = ( aP - m_end ).EuclideanNorm();
386  dist = std::min( distStartpt, distEndpt );
387  }
388  }
389 
390  if( dist <= minDist )
391  {
392  if( aLocation )
393  *aLocation = ( aP + GetCenter() ) / 2;
394 
395  if( aActual )
396  *aActual = std::max( 0, dist - m_width / 2 );
397 
398  return true;
399  }
400 
401  return false;
402 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:146
double GetRadius() const
Definition: shape_arc.cpp:453
VECTOR2I m_end
Definition: shape_arc.h:232
double RAD2DEG(double rad)
Definition: trigo.h:230
Define a general 2D-vector/point.
Definition: vector2d.h:61
bool ccw(const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
Definition: shape_arc.h:221
double GetStartAngle() const
Definition: shape_arc.cpp:405
double NormalizeAngleDegreesPos(double Angle)
Normalize angle to be in the 0.0 .. 360.0 range: angle is in degrees.
Definition: trigo.h:297
double Angle() const
Compute the angle of the vector.
Definition: vector2d.h:307
double GetEndAngle() const
Definition: shape_arc.cpp:415
VECTOR2I m_start
Definition: shape_arc.h:230
double GetCentralAngle() const
Definition: shape_arc.cpp:440
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Definition: shape_arc.cpp:341
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
int m_width
Definition: shape_arc.h:234
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:425

References VECTOR2< T >::Angle(), BBox(), ccw(), VECTOR2< T >::EuclideanNorm(), EuclideanNorm(), GetCenter(), GetCentralAngle(), GetEndAngle(), GetRadius(), GetStartAngle(), m_end, m_start, m_width, NormalizeAngleDegreesPos(), and RAD2DEG().

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

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

References collideShapes().

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

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

References collideShapes().

◆ ConstructFromStartEndAngle()

SHAPE_ARC & SHAPE_ARC::ConstructFromStartEndAngle ( const VECTOR2I aStart,
const VECTOR2I aEnd,
double  aAngle,
double  aWidth = 0 
)

Construct this arc from the given start, end and angle.

Parameters
aStartis the arc starting point
aEndis the arc endpoint
aAngleis the arc included angle
aWidthis the arc line thickness
Returns
this arc.

Definition at line 181 of file shape_arc.cpp.

183 {
184  m_start = aStart;
185  m_mid = aStart;
186  m_end = aEnd;
187  m_width = aWidth;
188 
189  VECTOR2I center( GetArcCenter( aStart, aEnd, aAngle ) );
190 
191  RotatePoint( m_mid, center, -aAngle * 10.0 / 2.0 );
192 
193  update_bbox();
194 
195  return *this;
196 }
VECTOR2I m_end
Definition: shape_arc.h:232
Define a general 2D-vector/point.
Definition: vector2d.h:61
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
VECTOR2I m_mid
Definition: shape_arc.h:231
void update_bbox()
Definition: shape_arc.cpp:299
VECTOR2I m_start
Definition: shape_arc.h:230
const VECTOR2I GetArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
Definition: trigo.cpp:454
int m_width
Definition: shape_arc.h:234

References GetArcCenter(), m_end, m_mid, m_start, m_width, RotatePoint(), and update_bbox().

Referenced by DIRECTION_45::BuildInitialTrace().

◆ ConstructFromStartEndCenter()

SHAPE_ARC & SHAPE_ARC::ConstructFromStartEndCenter ( const VECTOR2I aStart,
const VECTOR2I aEnd,
const VECTOR2I aCenter,
bool  aClockwise = false,
double  aWidth = 0 
)

Constructs this arc from the given start, end and center.

Parameters
aStartis the arc starting point
aEndis the arc endpoint
aCenteris the arc center
aClockwisedetermines which of the two solutions to construct
aWidthis the arc line thickness
Returns
*this

Definition at line 199 of file shape_arc.cpp.

202 {
203  VECTOR2I startLine = aStart - aCenter;
204  VECTOR2I endLine = aEnd - aCenter;
205 
206  double startangle = NormalizeAnglePos(RAD2DECIDEG( startLine.Angle() ));
207  double endangle = NormalizeAnglePos(RAD2DECIDEG( endLine.Angle() ));
208  double angle = endangle - startangle;
209 
210  if( aClockwise )
212  else
214 
215  m_start = aStart;
216  m_end = aEnd;
217  m_mid = aStart;
218 
219  RotatePoint( m_mid, aCenter, -angle / 2.0 );
220 
221  update_bbox();
222 
223  return *this;
224 }
T NormalizeAngleNeg(T Angle)
Normalize angle to be in the 0.0 .. -360.0 range: angle is in 1/10 degrees.
Definition: trigo.h:268
VECTOR2I m_end
Definition: shape_arc.h:232
Define a general 2D-vector/point.
Definition: vector2d.h:61
double RAD2DECIDEG(double rad)
Definition: trigo.h:234
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
VECTOR2I m_mid
Definition: shape_arc.h:231
double Angle() const
Compute the angle of the vector.
Definition: vector2d.h:307
void update_bbox()
Definition: shape_arc.cpp:299
VECTOR2I m_start
Definition: shape_arc.h:230
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.
Definition: trigo.h:281
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)

References PNS::angle(), VECTOR2< T >::Angle(), m_end, m_mid, m_start, NormalizeAngleNeg(), NormalizeAnglePos(), RAD2DECIDEG(), RotatePoint(), and update_bbox().

Referenced by SHAPE_LINE_CHAIN::amendArc(), BOOST_AUTO_TEST_CASE(), and SHAPE_LINE_CHAIN::splitArc().

◆ ConvertToPolyline()

const SHAPE_LINE_CHAIN SHAPE_ARC::ConvertToPolyline ( double  aAccuracy = DefaultAccuracyForPCB(),
double *  aEffectiveAccuracy = nullptr 
) const

Construct a SHAPE_LINE_CHAIN of segments from a given arc.

Note
The default is #ARC_HIGH_DEF in Pcbnew units. This is to allow common geometry collision functions. Other programs should call this using explicit accuracy values.
Todo:
Unify KiCad internal units.
Parameters
aAccuracymaximum divergence from true arc given in internal units.
aEffectiveAccuracyis the actual divergence from true arc given. the approximation error is between -aEffectiveAccuracy/2 and +aEffectiveAccuracy/2 in internal units
Returns
a SHAPE_LINE_CHAIN.

Definition at line 459 of file shape_arc.cpp.

461 {
462  SHAPE_LINE_CHAIN rv;
463  double r = GetRadius();
464  double sa = GetStartAngle();
465  VECTOR2I c = GetCenter();
466  double ca = GetCentralAngle();
467 
468  int n;
469 
470  // To calculate the arc to segment count, use the external radius instead of the radius.
471  // for a arc with small radius and large width, the difference can be significant
472  double external_radius = r+(m_width/2);
473  double effectiveAccuracy;
474 
475  if( external_radius < aAccuracy/2 ) // Should be a very rare case
476  {
477  // In this case, the arc is approximated by one segment, with a effective error
478  // between -aAccuracy/2 and +aAccuracy/2, as expected.
479  n = 0;
480  effectiveAccuracy = external_radius;
481  }
482  else
483  {
484  double arc_angle = std::abs( ca );
485  n = GetArcToSegmentCount( external_radius, aAccuracy, arc_angle );
486 
487  // Recalculate the effective error of approximation, that can be < aAccuracy
488  int seg360 = n * 360.0 / arc_angle;
489  effectiveAccuracy = CircleToEndSegmentDeltaRadius( external_radius, seg360 );
490  }
491 
492  // Split the error on either side of the arc. Since we want the start and end points
493  // to be exactly on the arc, the first and last segments need to be shorter to stay within
494  // the error band (since segments normally start 1/2 the error band outside the arc).
495  r += effectiveAccuracy / 2;
496  n = n * 2;
497 
498  rv.Append( m_start );
499 
500  for( int i = 1; i < n ; i += 2 )
501  {
502  double a = sa;
503 
504  if( n != 0 )
505  a += ( ca * i ) / n;
506 
507  double x = c.x + r * cos( a * M_PI / 180.0 );
508  double y = c.y + r * sin( a * M_PI / 180.0 );
509 
510  rv.Append( KiROUND( x ), KiROUND( y ) );
511  }
512 
513  rv.Append( m_end );
514 
515  if( aEffectiveAccuracy )
516  *aEffectiveAccuracy = effectiveAccuracy;
517 
518  return rv;
519 }
int CircleToEndSegmentDeltaRadius(int aInnerCircleRadius, int aSegCount)
double GetRadius() const
Definition: shape_arc.cpp:453
VECTOR2I m_end
Definition: shape_arc.h:232
Define a general 2D-vector/point.
Definition: vector2d.h:61
double GetStartAngle() const
Definition: shape_arc.cpp:405
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Represent a polyline (an zero-thickness chain of connected line segments).
VECTOR2I m_start
Definition: shape_arc.h:230
double GetCentralAngle() const
Definition: shape_arc.cpp:440
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
int m_width
Definition: shape_arc.h:234
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:425

References SHAPE_LINE_CHAIN::Append(), CircleToEndSegmentDeltaRadius(), GetArcToSegmentCount(), GetCenter(), GetCentralAngle(), GetRadius(), GetStartAngle(), KiROUND(), m_end, m_start, m_width, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SHAPE_LINE_CHAIN::Append(), PNS::ArcHull(), Collide(), BOARD_ADAPTER::createPadWithClearance(), SHAPE_LINE_CHAIN::Insert(), CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices(), PCB_SHAPE::MakeEffectiveShapes(), SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN(), and TransformArcToPolygon().

◆ DefaultAccuracyForPCB()

static double SHAPE_ARC::DefaultAccuracyForPCB ( )
inlinestatic
Note
The default is #ARC_HIGH_DEF in Pcbnew units. This is to allow common geometry collision functions. Other programs should call this using explicit accuracy values.
Todo:
Unify KiCad internal units.
Returns
a default accuracy value for ConvertToPolyline() to build the polyline.

Definition at line 194 of file shape_arc.h.

194 { return 0.005 * PCB_IU_PER_MM; }
constexpr double PCB_IU_PER_MM

References PCB_IU_PER_MM.

Referenced by ZONE_FILLER::buildCopperItemClearances(), and TransformArcToPolygon().

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

◆ GetArcMid()

const VECTOR2I& SHAPE_ARC::GetArcMid ( ) const
inline

◆ GetCenter()

VECTOR2I SHAPE_ARC::GetCenter ( ) const

Definition at line 425 of file shape_arc.cpp.

426 {
427  return GetArcCenter( m_start, m_mid, m_end );
428 }
VECTOR2I m_end
Definition: shape_arc.h:232
VECTOR2I m_mid
Definition: shape_arc.h:231
VECTOR2I m_start
Definition: shape_arc.h:230
const VECTOR2I GetArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
Definition: trigo.cpp:454

References GetArcCenter(), m_end, m_mid, and m_start.

Referenced by PLOTTER::Arc(), CheckArcGeom(), Collide(), ConvertToPolyline(), ROUTER_PREVIEW_ITEM::drawLineChain(), ROUTER_PREVIEW_ITEM::drawShape(), GetCentralAngle(), GetEndAngle(), GetRadius(), GetStartAngle(), GERBER_PLOTTER::plotArc(), SHAPE_LINE_CHAIN::splitArc(), TransformArcToPolygon(), and update_bbox().

◆ GetCentralAngle()

double SHAPE_ARC::GetCentralAngle ( ) const
Returns
the central angle of the arc shape in degrees, normalized between 0.0, 360.0 deg.

Definition at line 440 of file shape_arc.cpp.

441 {
442  VECTOR2I center = GetCenter();
443  VECTOR2I p0 = m_start - center;
444  VECTOR2I p1 = m_mid - center;
445  VECTOR2I p2 = m_end - center;
446  double angle1 = ArcTangente( p1.y, p1.x ) - ArcTangente( p0.y, p0.x );
447  double angle2 = ArcTangente( p2.y, p2.x ) - ArcTangente( p1.y, p1.x );
448 
449  return ( NormalizeAngle180( angle1 ) + NormalizeAngle180( angle2 ) ) / 10.0;
450 }
VECTOR2I m_end
Definition: shape_arc.h:232
Define a general 2D-vector/point.
Definition: vector2d.h:61
T NormalizeAngle180(T Angle)
Normalize angle to be in the -180.0 .. 180.0 range.
Definition: trigo.h:387
VECTOR2I m_mid
Definition: shape_arc.h:231
VECTOR2I m_start
Definition: shape_arc.h:230
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:183
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:425

References ArcTangente(), GetCenter(), m_end, m_mid, m_start, NormalizeAngle180(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by CheckArcGeom(), Collide(), ConvertToPolyline(), ROUTER_PREVIEW_ITEM::drawLineChain(), ROUTER_PREVIEW_ITEM::drawShape(), GetLength(), IsClockwise(), FABMASTER::loadFootprints(), FABMASTER::loadGraphics(), FABMASTER::loadOutline(), TransformArcToPolygon(), and update_bbox().

◆ GetChord()

SEG SHAPE_ARC::GetChord ( ) const
inline

Definition at line 160 of file shape_arc.h.

161  {
162  return SEG( m_start, m_end );
163  }
VECTOR2I m_end
Definition: shape_arc.h:232
Definition: seg.h:40
VECTOR2I m_start
Definition: shape_arc.h:230

References m_end, and m_start.

Referenced by CheckArcGeom().

◆ GetEndAngle()

double SHAPE_ARC::GetEndAngle ( ) const
Returns
the end angle of the arc shape in degrees, normalized between 0.0, 360.0 deg.

Definition at line 415 of file shape_arc.cpp.

416 {
417  VECTOR2D d( m_end - GetCenter() );
418 
419  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
420 
421  return NormalizeAngleDegrees( ang, 0.0, 360.0 );
422 }
VECTOR2I m_end
Definition: shape_arc.h:232
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:327
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:425

References GetCenter(), m_end, NormalizeAngleDegrees(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PLOTTER::Arc(), CheckArcGeom(), Collide(), GERBER_PLOTTER::plotArc(), and TransformArcToPolygon().

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

◆ GetLength()

double SHAPE_ARC::GetLength ( ) const
Returns
the length of the arc shape.

Definition at line 431 of file shape_arc.cpp.

432 {
433  double radius = GetRadius();
434  double includedAngle = std::abs( GetCentralAngle() );
435 
436  return radius * M_PI * includedAngle / 180.0;
437 }
double GetRadius() const
Definition: shape_arc.cpp:453
double GetCentralAngle() const
Definition: shape_arc.cpp:440

References GetCentralAngle(), and GetRadius().

◆ GetP0()

◆ GetP1()

◆ GetRadius()

double SHAPE_ARC::GetRadius ( ) const

Definition at line 453 of file shape_arc.cpp.

454 {
455  return ( m_start - GetCenter() ).EuclideanNorm();
456 }
VECTOR2I m_start
Definition: shape_arc.h:230
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:425

References GetCenter(), and m_start.

Referenced by PLOTTER::Arc(), CheckArcGeom(), Collide(), ConvertToPolyline(), ROUTER_PREVIEW_ITEM::drawLineChain(), ROUTER_PREVIEW_ITEM::drawShape(), GetLength(), TransformArcToPolygon(), and update_bbox().

◆ GetStartAngle()

double SHAPE_ARC::GetStartAngle ( ) const
Returns
the start angle of the arc shape in degrees, normalized between 0.0, 360.0 deg.

Definition at line 405 of file shape_arc.cpp.

406 {
407  VECTOR2D d( m_start - GetCenter() );
408 
409  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
410 
411  return NormalizeAngleDegrees( ang, 0.0, 360.0 );
412 }
VECTOR2I m_start
Definition: shape_arc.h:230
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:327
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:425

References GetCenter(), m_start, NormalizeAngleDegrees(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PLOTTER::Arc(), CheckArcGeom(), Collide(), ConvertToPolyline(), ROUTER_PREVIEW_ITEM::drawLineChain(), ROUTER_PREVIEW_ITEM::drawShape(), GERBER_PLOTTER::plotArc(), TransformArcToPolygon(), and update_bbox().

◆ GetWidth()

int SHAPE_ARC::GetWidth ( ) const
inline

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

◆ IsClockwise()

bool SHAPE_ARC::IsClockwise ( ) const

Definition at line 352 of file shape_arc.cpp.

353 {
354  return GetCentralAngle() < 0;
355 }
double GetCentralAngle() const
Definition: shape_arc.cpp:440

References GetCentralAngle().

Referenced by SHAPE_LINE_CHAIN::splitArc().

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

Implements SHAPE.

Definition at line 135 of file shape_arc.h.

136  {
137  return true;
138  }

Referenced by CheckArcGeom().

◆ Mirror() [1/2]

void SHAPE_ARC::Mirror ( bool  aX = true,
bool  aY = false,
const VECTOR2I aVector = { 0, 0 } 
)

Definition at line 549 of file shape_arc.cpp.

550 {
551  if( aX )
552  {
553  m_start.x = -m_start.x + 2 * aVector.x;
554  m_end.x = -m_end.x + 2 * aVector.x;
555  m_mid.x = -m_mid.x + 2 * aVector.x;
556  }
557 
558  if( aY )
559  {
560  m_start.y = -m_start.y + 2 * aVector.y;
561  m_end.y = -m_end.y + 2 * aVector.y;
562  m_mid.y = -m_mid.y + 2 * aVector.y;
563  }
564 
565  update_bbox();
566 }
VECTOR2I m_end
Definition: shape_arc.h:232
VECTOR2I m_mid
Definition: shape_arc.h:231
void update_bbox()
Definition: shape_arc.cpp:299
VECTOR2I m_start
Definition: shape_arc.h:230

References m_end, m_mid, m_start, update_bbox(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Mirror() [2/2]

void SHAPE_ARC::Mirror ( const SEG axis)

Definition at line 569 of file shape_arc.cpp.

570 {
571  m_start = axis.ReflectPoint( m_start );
572  m_end = axis.ReflectPoint( m_end );
573  m_mid = axis.ReflectPoint( m_mid );
574 
575  update_bbox();
576 }
VECTOR2I m_end
Definition: shape_arc.h:232
const VECTOR2I ReflectPoint(const VECTOR2I &aP) const
Reflect a point using this segment as axis.
Definition: seg.cpp:249
VECTOR2I m_mid
Definition: shape_arc.h:231
void update_bbox()
Definition: shape_arc.cpp:299
VECTOR2I m_start
Definition: shape_arc.h:230

References m_end, m_mid, m_start, SEG::ReflectPoint(), and update_bbox().

◆ Move()

void SHAPE_ARC::Move ( const VECTOR2I aVector)
overridevirtual

Implements SHAPE.

Definition at line 522 of file shape_arc.cpp.

523 {
524  m_start += aVector;
525  m_end += aVector;
526  m_mid += aVector;
527  update_bbox();
528 }
VECTOR2I m_end
Definition: shape_arc.h:232
VECTOR2I m_mid
Definition: shape_arc.h:231
void update_bbox()
Definition: shape_arc.cpp:299
VECTOR2I m_start
Definition: shape_arc.h:230

References m_end, m_mid, m_start, and update_bbox().

Referenced by PNS::COMPONENT_DRAGGER::Drag().

◆ 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(), WRL2FACESET::TranslateToSG(), and X3DIFACESET::TranslateToSG().

◆ operator==()

bool SHAPE_ARC::operator== ( SHAPE_ARC const &  aArc) const
inline

Definition at line 214 of file shape_arc.h.

215  {
216  return ( aArc.m_start == m_start ) && ( aArc.m_end == m_end ) && ( aArc.m_mid == m_mid )
217  && ( aArc.m_width == m_width );
218  }
VECTOR2I m_end
Definition: shape_arc.h:232
VECTOR2I m_mid
Definition: shape_arc.h:231
VECTOR2I m_start
Definition: shape_arc.h:230
int m_width
Definition: shape_arc.h:234

References m_end, m_mid, m_start, and m_width.

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

◆ Reverse()

void SHAPE_ARC::Reverse ( )

Definition at line 579 of file shape_arc.cpp.

580 {
581  std::swap( m_start, m_end );
582 }
VECTOR2I m_end
Definition: shape_arc.h:232
VECTOR2I m_start
Definition: shape_arc.h:230

References m_end, and m_start.

Referenced by SHAPE_LINE_CHAIN::Reverse().

◆ Reversed()

SHAPE_ARC SHAPE_ARC::Reversed ( ) const

Definition at line 585 of file shape_arc.cpp.

586 {
587  return SHAPE_ARC( m_end, m_mid, m_start, m_width );
588 }
VECTOR2I m_end
Definition: shape_arc.h:232
VECTOR2I m_mid
Definition: shape_arc.h:231
VECTOR2I m_start
Definition: shape_arc.h:230
SHAPE_ARC()
Definition: shape_arc.h:39
int m_width
Definition: shape_arc.h:234

References m_end, m_mid, m_start, m_width, and SHAPE_ARC().

Referenced by PNS::NODE::AssembleLine(), BOOST_AUTO_TEST_CASE(), and CONVERT_TOOL::makePolysFromSegs().

◆ Rotate()

void SHAPE_ARC::Rotate ( double  aAngle,
const VECTOR2I aCenter 
)
overridevirtual

Rotate the arc by a given angle about a point.

Parameters
aCenteris the rotation center.
aAnglerotation angle in radians.

Implements SHAPE.

Definition at line 531 of file shape_arc.cpp.

532 {
533  m_start -= aCenter;
534  m_end -= aCenter;
535  m_mid -= aCenter;
536 
537  m_start = m_start.Rotate( aAngle );
538  m_end = m_end.Rotate( aAngle );
539  m_mid = m_mid.Rotate( aAngle );
540 
541  m_start += aCenter;
542  m_end += aCenter;
543  m_mid += aCenter;
544 
545  update_bbox();
546 }
VECTOR2I m_end
Definition: shape_arc.h:232
VECTOR2I m_mid
Definition: shape_arc.h:231
void update_bbox()
Definition: shape_arc.cpp:299
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371
VECTOR2I m_start
Definition: shape_arc.h:230

References m_end, m_mid, m_start, VECTOR2< T >::Rotate(), and update_bbox().

◆ SetWidth()

void SHAPE_ARC::SetWidth ( int  aWidth)
inline

Definition at line 125 of file shape_arc.h.

126  {
127  m_width = aWidth;
128  }
int m_width
Definition: shape_arc.h:234

References m_width.

Referenced by BOOST_AUTO_TEST_CASE(), and PNS::ARC::SetWidth().

◆ Type()

SHAPE_TYPE SHAPE_BASE::Type ( ) const
inlineinherited

◆ update_bbox()

void SHAPE_ARC::update_bbox ( )
private

Definition at line 299 of file shape_arc.cpp.

300 {
301  std::vector<VECTOR2I> points;
302  // Put start and end points in the point list
303  points.push_back( m_start );
304  points.push_back( m_end );
305 
306  double start_angle = GetStartAngle();
307  double end_angle = start_angle + GetCentralAngle();
308 
309  // we always count quadrants clockwise (increasing angle)
310  if( start_angle > end_angle )
311  std::swap( start_angle, end_angle );
312 
313  int quad_angle_start = std::ceil( start_angle / 90.0 );
314  int quad_angle_end = std::floor( end_angle / 90.0 );
315 
316  // count through quadrants included in arc
317  for( int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle )
318  {
319  const int radius = KiROUND( GetRadius() );
320  VECTOR2I quad_pt = GetCenter();
321 
322  switch( quad_angle % 4 )
323  {
324  case 0: quad_pt += { radius, 0 }; break;
325  case 1:
326  case -3: quad_pt += { 0, radius }; break;
327  case 2:
328  case -2: quad_pt += { -radius, 0 }; break;
329  case 3:
330  case -1: quad_pt += { 0, -radius }; break;
331  default: assert( false );
332  }
333 
334  points.push_back( quad_pt );
335  }
336 
337  m_bbox.Compute( points );
338 }
double GetRadius() const
Definition: shape_arc.cpp:453
VECTOR2I m_end
Definition: shape_arc.h:232
Define a general 2D-vector/point.
Definition: vector2d.h:61
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:75
double GetStartAngle() const
Definition: shape_arc.cpp:405
VECTOR2I m_start
Definition: shape_arc.h:230
double GetCentralAngle() const
Definition: shape_arc.cpp:440
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
BOX2I m_bbox
Definition: shape_arc.h:235
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:425

References BOX2< Vec >::Compute(), GetCenter(), GetCentralAngle(), GetRadius(), GetStartAngle(), KiROUND(), m_bbox, m_end, and m_start.

Referenced by ConstructFromStartEndAngle(), ConstructFromStartEndCenter(), Mirror(), Move(), Rotate(), and SHAPE_ARC().

Member Data Documentation

◆ m_bbox

BOX2I SHAPE_ARC::m_bbox
private

Definition at line 235 of file shape_arc.h.

Referenced by BBox(), SHAPE_ARC(), and update_bbox().

◆ m_end

◆ m_mid

◆ m_start

◆ m_type

SHAPE_TYPE SHAPE_BASE::m_type
protectedinherited

< type of our shape

Definition at line 110 of file shape.h.

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

◆ m_width

int SHAPE_ARC::m_width
private

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


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