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)
 SHAPE_ARC ctor using center, start, angle. More...
 
 SHAPE_ARC (const VECTOR2I &aArcStart, const VECTOR2I &aArcMid, const VECTOR2I &aArcEnd, int aWidth)
 SHAPE_ARC ctor. More...
 
 SHAPE_ARC (const SEG &aSegmentA, const SEG &aSegmentB, int aRadius, int aWidth=0)
 SHAPE_ARC ctor. 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)
 Constructs this arc from the given start, end and angle. 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...
 
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
 Function Rotate rotates 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
 
const SHAPE_LINE_CHAIN ConvertToPolyline (double aAccuracy=0.005 *PCB_IU_PER_MM) const
 Constructs a SHAPE_LINE_CHAIN of segments from a given arc. More...
 
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 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:177

Referenced by Clone(), and Reversed().

◆ SHAPE_ARC() [2/5]

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

SHAPE_ARC ctor 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 33 of file shape_arc.cpp.

34  :
35  SHAPE( SH_ARC ), m_width( aWidth )
36 {
37  m_start = aArcStartPoint;
38  m_mid = aArcStartPoint;
39  m_end = aArcStartPoint;
40 
41  RotatePoint( m_mid, aArcCenter, -aCenterAngle * 10.0 / 2.0 );
42  RotatePoint( m_end, aArcCenter, -aCenterAngle * 10.0 );
43 
44  update_bbox();
45 }
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
VECTOR2I m_end
Definition: shape_arc.h:175
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
VECTOR2I m_mid
Definition: shape_arc.h:174
circular arc
Definition: shape.h:50
void update_bbox()
Definition: shape_arc.cpp:263
VECTOR2I m_start
Definition: shape_arc.h:173
int m_width
Definition: shape_arc.h:177

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 
)

SHAPE_ARC ctor.

Parameters
aArcStartis the arc start point
aArcEndis the arc end point
aArcMidis the arc mid point
aWidthis the arc line thickness

Definition at line 48 of file shape_arc.cpp.

49  :
50  SHAPE( SH_ARC ), m_start( aArcStart ), m_mid( aArcMid ), m_end( aArcEnd ),
51  m_width( aWidth )
52 {
53  update_bbox();
54 }
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
VECTOR2I m_end
Definition: shape_arc.h:175
VECTOR2I m_mid
Definition: shape_arc.h:174
circular arc
Definition: shape.h:50
void update_bbox()
Definition: shape_arc.cpp:263
VECTOR2I m_start
Definition: shape_arc.h:173
int m_width
Definition: shape_arc.h:177

References update_bbox().

◆ SHAPE_ARC() [4/5]

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

SHAPE_ARC ctor.

Builds 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 57 of file shape_arc.cpp.

58  : SHAPE( SH_ARC )
59 {
60  m_width = aWidth;
61 
62  /*
63  * Construct an arc that is tangent to two segments with a given radius.
64  *
65  * p
66  * A
67  * A \
68  * / \
69  * / . . \ segB
70  * /. .\
71  * segA / c \
72  * / B
73  * /
74  * /
75  * B
76  *
77  *
78  * segA is the fist segment (with its points A and B)
79  * segB is the second segment (with its points A and B)
80  * p is the point at which segA and segB would intersect if they were projected
81  * c is the centre of the arc to be constructed
82  * rad is the radius of the arc to be constructed
83  *
84  * We can create two vectors, betweeen point p and segA /segB
85  * pToA = p - segA.B //< note that segA.A would also be valid as it is colinear
86  * pToB = p - segB.B //< note that segB.A would also be valid as it is colinear
87  *
88  * Let the angle formed by segA and segB be called 'alpha':
89  * alpha = angle( pToA ) - angle( pToB )
90  *
91  * The distance PC can be computed as
92  * distPC = rad / abs( sin( alpha / 2 ) )
93  *
94  * The polar angle of the vector PC can be computed as:
95  * anglePC = angle( pToA ) + alpha / 2
96  *
97  * Therefore:
98  * C.x = P.x + distPC*cos( anglePC )
99  * C.y = P.y + distPC*sin( anglePC )
100  */
101 
102  OPT_VECTOR2I p = aSegmentA.Intersect( aSegmentB, true, true );
103 
104  if( !p || aSegmentA.Length() == 0 || aSegmentB.Length() == 0 )
105  {
106  // Catch bugs in debug
107  wxASSERT_MSG( false, "The input segments do not intersect or one is zero length." );
108 
109  // Make a 180 degree arc around aSegmentA in case we end up here in release
110  m_start = aSegmentA.A;
111  m_end = aSegmentA.B;
112  m_mid = m_start;
113 
114  VECTOR2I arcCenter = aSegmentA.Center();
115  RotatePoint( m_mid, arcCenter, 900.0 ); // mid point at 90 degrees
116  }
117  else
118  {
119  VECTOR2I pToA = aSegmentA.B - p.get();
120  VECTOR2I pToB = aSegmentB.B - p.get();
121 
122  if( pToA.EuclideanNorm() == 0 )
123  pToA = aSegmentA.A - p.get();
124 
125  if( pToB.EuclideanNorm() == 0 )
126  pToB = aSegmentB.A - p.get();
127 
128  double pToAangle = ArcTangente( pToA.y, pToA.x );
129  double pToBangle = ArcTangente( pToB.y, pToB.x );
130 
131  double alpha = NormalizeAngle180( pToAangle - pToBangle );
132 
133  double distPC = (double) aRadius / abs( sin( DECIDEG2RAD( alpha / 2 ) ) );
134  double angPC = pToAangle - alpha / 2;
135 
136  VECTOR2I arcCenter;
137 
138  arcCenter.x = p.get().x + KiROUND( distPC * cos( DECIDEG2RAD( angPC ) ) );
139  arcCenter.y = p.get().y + KiROUND( distPC * sin( DECIDEG2RAD( angPC ) ) );
140 
141  // The end points of the arc are the orthogonal projected lines from the line segments
142  // to the center of the arc
143  m_start = aSegmentA.LineProject( arcCenter );
144  m_end = aSegmentB.LineProject( arcCenter );
145 
146  //The mid point is rotated start point around center, half the angle of the arc.
147  VECTOR2I startVector = m_start - arcCenter;
148  VECTOR2I endVector = m_end - arcCenter;
149 
150  double startAngle = ArcTangente( startVector.y, startVector.x );
151  double endAngle = ArcTangente( endVector.y, endVector.x );
152 
153  double midPointRotAngle = NormalizeAngle180( startAngle - endAngle ) / 2;
154  m_mid = m_start;
155  RotatePoint( m_mid, arcCenter, midPointRotAngle );
156  }
157 
158  update_bbox();
159 }
int Length() const
Return the length (this).
Definition: seg.h:355
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:119
VECTOR2I m_end
Definition: shape_arc.h:175
Define a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2I Center() const
Definition: seg.h:391
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
T NormalizeAngle180(T Angle)
Normalize angle to be in the -180.0 .. 180.0 range.
Definition: trigo.h:376
VECTOR2I m_mid
Definition: shape_arc.h:174
VECTOR2I LineProject(const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.
Definition: seg.h:404
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:39
circular arc
Definition: shape.h:50
void update_bbox()
Definition: shape_arc.cpp:263
VECTOR2I m_start
Definition: shape_arc.h:173
VECTOR2I A
Definition: seg.h:49
double DECIDEG2RAD(double deg)
Definition: trigo.h:235
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:68
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:182
int m_width
Definition: shape_arc.h:177
VECTOR2I B
Definition: seg.h:50

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 162 of file shape_arc.cpp.

163  : SHAPE( SH_ARC )
164 {
165  m_start = aOther.m_start;
166  m_end = aOther.m_end;
167  m_mid = aOther.m_mid;
168  m_width = aOther.m_width;
169  m_bbox = aOther.m_bbox;
170 }
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition: shape.h:127
VECTOR2I m_end
Definition: shape_arc.h:175
VECTOR2I m_mid
Definition: shape_arc.h:174
circular arc
Definition: shape.h:50
VECTOR2I m_start
Definition: shape_arc.h:173
int m_width
Definition: shape_arc.h:177
BOX2I m_bbox
Definition: shape_arc.h:178

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

◆ ~SHAPE_ARC()

virtual SHAPE_ARC::~SHAPE_ARC ( )
inlinevirtual

Definition at line 77 of file shape_arc.h.

77 {}

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 305 of file shape_arc.cpp.

306 {
307  BOX2I bbox( m_bbox );
308 
309  if( aClearance != 0 )
310  bbox.Inflate( aClearance );
311 
312  return bbox;
313 }
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:43
BOX2I m_bbox
Definition: shape_arc.h:178

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

◆ ccw()

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

Definition at line 164 of file shape_arc.h.

165  {
166  return ( ecoord{ aC.y } - aA.y ) * ( ecoord{ aB.x } - aA.x ) >
167  ( ecoord{ aB.y } - aA.y ) * ( ecoord{ aC.x } - aA.x );
168  }
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:79

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 79 of file shape_arc.h.

80  {
81  return new SHAPE_ARC( *this );
82  }
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 191 of file shape_arc.cpp.

192 {
193  if( aSeg.A == aSeg.B )
194  return Collide( aSeg.A, aClearance, aActual, aLocation );
195 
196  int minDist = aClearance + m_width / 2;
197  VECTOR2I center = GetCenter();
198  ecoord dist_sq;
199  ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
200  VECTOR2I nearest;
201 
202  VECTOR2I ab = ( aSeg.B - aSeg.A );
203  VECTOR2I ac = ( center - aSeg.A );
204 
205  ecoord lenAbSq = ab.SquaredEuclideanNorm();
206  double lambda = (double) ac.Dot( ab ) / (double) lenAbSq;
207 
208  if( lambda >= 0.0 && lambda <= 1.0 )
209  {
210  VECTOR2I p;
211 
212  p.x = (double) aSeg.A.x * lambda + (double) aSeg.B.x * (1.0 - lambda);
213  p.y = (double) aSeg.A.y * lambda + (double) aSeg.B.y * (1.0 - lambda);
214 
215  dist_sq = ( m_start - p ).SquaredEuclideanNorm();
216 
217  if( dist_sq < closest_dist_sq )
218  {
219  closest_dist_sq = dist_sq;
220  nearest = p;
221  }
222 
223  dist_sq = ( m_end - p ).SquaredEuclideanNorm();
224 
225  if( dist_sq < closest_dist_sq )
226  {
227  closest_dist_sq = dist_sq;
228  nearest = p;
229  }
230  }
231 
232  dist_sq = aSeg.SquaredDistance( m_start );
233 
234  if( dist_sq < closest_dist_sq )
235  {
236  closest_dist_sq = dist_sq;
237  nearest = m_start;
238  }
239 
240  dist_sq = aSeg.SquaredDistance( m_end );
241 
242  if( dist_sq < closest_dist_sq )
243  {
244  closest_dist_sq = dist_sq;
245  nearest = m_end;
246  }
247 
248  if( closest_dist_sq == 0 || closest_dist_sq < SEG::Square( minDist ) )
249  {
250  if( aLocation )
251  *aLocation = nearest;
252 
253  if( aActual )
254  *aActual = std::max( 0, (int) sqrt( closest_dist_sq ) - m_width / 2 );
255 
256  return true;
257  }
258 
259  return false;
260 }
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:191
VECTOR2I m_end
Definition: shape_arc.h:175
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:123
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:173
VECTOR2I A
Definition: seg.h:49
int m_width
Definition: shape_arc.h:177
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:383
VECTOR2I B
Definition: seg.h:50

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

◆ 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 316 of file shape_arc.cpp.

318 {
319  int minDist = aClearance + m_width / 2;
320  auto bbox = BBox( minDist );
321 
322  // Fast check using bounding box:
323  if( !bbox.Contains( aP ) )
324  return false;
325 
326  VECTOR2I center = GetCenter();
327  VECTOR2I vec = aP - center;
328 
329  int dist = abs( vec.EuclideanNorm() - GetRadius() );
330 
331  // If not a 360 degree arc, need to use arc angles to decide if point collides
332  if( m_start != m_end )
333  {
334  bool ccw = GetCentralAngle() > 0.0;
335  double rotatedVecAngle = NormalizeAngleDegreesPos( NormalizeAngleDegreesPos( RAD2DEG( vec.Angle() ) )
336  - GetStartAngle() );
337  double rotatedEndAngle = NormalizeAngleDegreesPos( GetEndAngle() - GetStartAngle() );
338 
339  if( ( ccw && rotatedVecAngle > rotatedEndAngle )
340  || ( !ccw && rotatedVecAngle < rotatedEndAngle ) )
341  {
342  int distStartpt = ( aP - m_start ).EuclideanNorm();
343  int distEndpt = ( aP - m_end ).EuclideanNorm();
344  dist = std::min( distStartpt, distEndpt );
345  }
346  }
347 
348  if( dist <= minDist )
349  {
350  if( aLocation )
351  *aLocation = ( aP + GetCenter() ) / 2;
352 
353  if( aActual )
354  *aActual = std::max( 0, dist - m_width / 2 );
355 
356  return true;
357  }
358 
359  return false;
360 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:148
double GetRadius() const
Definition: shape_arc.cpp:402
VECTOR2I m_end
Definition: shape_arc.h:175
double RAD2DEG(double rad)
Definition: trigo.h:232
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:164
double GetStartAngle() const
Definition: shape_arc.cpp:363
double NormalizeAngleDegreesPos(double Angle)
Normalize angle to be in the 0.0 .
Definition: trigo.h:296
double Angle() const
Compute the angle of the vector.
Definition: vector2d.h:307
double GetEndAngle() const
Definition: shape_arc.cpp:373
VECTOR2I m_start
Definition: shape_arc.h:173
double GetCentralAngle() const
Definition: shape_arc.cpp:389
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:305
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:177
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:383

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

◆ ConstructFromStartEndAngle()

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

Constructs 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

Definition at line 173 of file shape_arc.cpp.

175 {
176  m_start = aStart;
177  m_mid = aStart;
178  m_end = aEnd;
179  m_width = aWidth;
180 
181  VECTOR2I center( GetArcCenter( aStart, aEnd, aAngle ) );
182 
183  RotatePoint( m_mid, center, -aAngle * 10.0 / 2.0 );
184 
185  update_bbox();
186 
187  return *this;
188 }
VECTOR2I m_end
Definition: shape_arc.h:175
Define a general 2D-vector/point.
Definition: vector2d.h:61
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
VECTOR2I m_mid
Definition: shape_arc.h:174
void update_bbox()
Definition: shape_arc.cpp:263
VECTOR2I m_start
Definition: shape_arc.h:173
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:450
int m_width
Definition: shape_arc.h:177

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

Referenced by DIRECTION_45::BuildInitialTrace().

◆ ConvertToPolyline()

const SHAPE_LINE_CHAIN SHAPE_ARC::ConvertToPolyline ( double  aAccuracy = 0.005 * PCB_IU_PER_MM) const

Constructs a SHAPE_LINE_CHAIN of segments from a given arc.

Parameters
aAccuracymaximum divergence from true arc given in internal units ** Note that 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 SHAPE_LINE_CHAIN

Definition at line 408 of file shape_arc.cpp.

409 {
410  SHAPE_LINE_CHAIN rv;
411  double r = GetRadius();
412  double sa = GetStartAngle();
413  auto c = GetCenter();
414  double ca = GetCentralAngle();
415 
416  int n;
417 
418  if( r < aAccuracy )
419  n = 0;
420  else
421  n = GetArcToSegmentCount( r, aAccuracy, ca );
422 
423  // Split the error on either side of the arc. Since we want the start and end points
424  // to be exactly on the arc, the first and last segments need to be shorter to stay within
425  // the error band (since segments normally start 1/2 the error band outside the arc).
426  r += aAccuracy / 2;
427  n = n * 2;
428 
429  rv.Append( m_start );
430 
431  for( int i = 1; i < n ; i += 2 )
432  {
433  double a = sa;
434 
435  if( n != 0 )
436  a += ( ca * i ) / n;
437 
438  double x = c.x + r * cos( a * M_PI / 180.0 );
439  double y = c.y + r * sin( a * M_PI / 180.0 );
440 
441  rv.Append( KiROUND( x ), KiROUND( y ) );
442  }
443 
444  rv.Append( m_end );
445 
446  return rv;
447 }
double GetRadius() const
Definition: shape_arc.cpp:402
VECTOR2I m_end
Definition: shape_arc.h:175
double GetStartAngle() const
Definition: shape_arc.cpp:363
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN.
VECTOR2I m_start
Definition: shape_arc.h:173
double GetCentralAngle() const
Definition: shape_arc.cpp:389
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:68
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:383

References SHAPE_LINE_CHAIN::Append(), GetArcToSegmentCount(), GetCenter(), GetCentralAngle(), GetRadius(), GetStartAngle(), KiROUND(), m_end, and m_start.

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

◆ 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

Definition at line 97 of file shape_arc.h.

97 { return m_mid; }
VECTOR2I m_mid
Definition: shape_arc.h:174

References m_mid.

Referenced by ARC::ARC(), PCB_GRID_HELPER::computeAnchors(), and PNS_KICAD_IFACE::UpdateItem().

◆ GetCenter()

VECTOR2I SHAPE_ARC::GetCenter ( ) const

Definition at line 383 of file shape_arc.cpp.

384 {
385  return GetArcCenter( m_start, m_mid, m_end );
386 }
VECTOR2I m_end
Definition: shape_arc.h:175
VECTOR2I m_mid
Definition: shape_arc.h:174
VECTOR2I m_start
Definition: shape_arc.h:173
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:450

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

Referenced by CheckArcGeom(), Collide(), ConvertToPolyline(), ROUTER_PREVIEW_ITEM::drawLineChain(), ROUTER_PREVIEW_ITEM::drawShape(), GetCentralAngle(), GetEndAngle(), GetRadius(), GetStartAngle(), and update_bbox().

◆ GetCentralAngle()

double SHAPE_ARC::GetCentralAngle ( ) const

Definition at line 389 of file shape_arc.cpp.

390 {
391  VECTOR2I center = GetCenter();
392  VECTOR2I p0 = m_start - center;
393  VECTOR2I p1 = m_mid - center;
394  VECTOR2I p2 = m_end - center;
395  double angle1 = ArcTangente( p1.y, p1.x ) - ArcTangente( p0.y, p0.x );
396  double angle2 = ArcTangente( p2.y, p2.x ) - ArcTangente( p1.y, p1.x );
397 
398  return ( NormalizeAngle180( angle1 ) + NormalizeAngle180( angle2 ) ) / 10.0;
399 }
VECTOR2I m_end
Definition: shape_arc.h:175
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:376
VECTOR2I m_mid
Definition: shape_arc.h:174
VECTOR2I m_start
Definition: shape_arc.h:173
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:182
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:383

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(), FABMASTER::loadFootprints(), FABMASTER::loadGraphics(), FABMASTER::loadOutline(), and update_bbox().

◆ GetChord()

SEG SHAPE_ARC::GetChord ( ) const
inline

Definition at line 142 of file shape_arc.h.

143  {
144  return SEG( m_start, m_end );
145  }
VECTOR2I m_end
Definition: shape_arc.h:175
Definition: seg.h:41
VECTOR2I m_start
Definition: shape_arc.h:173

References m_end, and m_start.

Referenced by CheckArcGeom().

◆ GetEndAngle()

double SHAPE_ARC::GetEndAngle ( ) const

Definition at line 373 of file shape_arc.cpp.

374 {
375  VECTOR2D d( m_end - GetCenter() );
376 
377  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
378 
379  return NormalizeAngleDegrees( ang, 0.0, 360.0 );
380 }
VECTOR2I m_end
Definition: shape_arc.h:175
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:323
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:383

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

Referenced by CheckArcGeom(), and Collide().

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

◆ GetP0()

◆ GetP1()

◆ GetRadius()

double SHAPE_ARC::GetRadius ( ) const

Definition at line 402 of file shape_arc.cpp.

403 {
404  return ( m_start - GetCenter() ).EuclideanNorm();
405 }
VECTOR2I m_start
Definition: shape_arc.h:173
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:383

References GetCenter(), and m_start.

Referenced by CheckArcGeom(), Collide(), ConvertToPolyline(), ROUTER_PREVIEW_ITEM::drawLineChain(), ROUTER_PREVIEW_ITEM::drawShape(), and update_bbox().

◆ GetStartAngle()

double SHAPE_ARC::GetStartAngle ( ) const

Definition at line 363 of file shape_arc.cpp.

364 {
365  VECTOR2D d( m_start - GetCenter() );
366 
367  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
368 
369  return NormalizeAngleDegrees( ang, 0.0, 360.0 );
370 }
VECTOR2I m_start
Definition: shape_arc.h:173
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:323
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:383

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

Referenced by CheckArcGeom(), Collide(), ConvertToPolyline(), ROUTER_PREVIEW_ITEM::drawLineChain(), ROUTER_PREVIEW_ITEM::drawShape(), and update_bbox().

◆ GetWidth()

int SHAPE_ARC::GetWidth ( ) const
inline

Definition at line 112 of file shape_arc.h.

113  {
114  return m_width;
115  }
int m_width
Definition: shape_arc.h:177

References m_width.

Referenced by PNS::ArcHull(), Collide(), BOARD_ADAPTER::createPadWithClearance(), ROUTER_PREVIEW_ITEM::drawShape(), and PNS::ARC::Width().

◆ HasIndexableSubshapes()

virtual bool SHAPE_BASE::HasIndexableSubshapes ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_POLY_SET, and SHAPE_COMPOUND.

Definition at line 99 of file shape.h.

100  {
101  return false;
102  }

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

◆ IsNull()

bool SHAPE::IsNull ( ) const
inlineinherited

Return true if the shape is a null shape.

Return values
trueif null :-)

Definition at line 150 of file shape.h.

151  {
152  return m_type == SH_NULL;
153  }
SHAPE_TYPE m_type
< type of our shape
Definition: shape.h:110
empty shape (no shape...),
Definition: shape.h:51

References SHAPE_BASE::m_type, and SH_NULL.

◆ IsSolid()

bool SHAPE_ARC::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 117 of file shape_arc.h.

118  {
119  return true;
120  }

Referenced by CheckArcGeom().

◆ Mirror() [1/2]

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

Definition at line 477 of file shape_arc.cpp.

478 {
479  if( aX )
480  {
481  m_start.x = -m_start.x + 2 * aVector.x;
482  m_end.x = -m_end.x + 2 * aVector.x;
483  m_mid.x = -m_mid.x + 2 * aVector.x;
484  }
485 
486  if( aY )
487  {
488  m_start.y = -m_start.y + 2 * aVector.y;
489  m_end.y = -m_end.y + 2 * aVector.y;
490  m_mid.y = -m_mid.y + 2 * aVector.y;
491  }
492 
493  update_bbox();
494 }
VECTOR2I m_end
Definition: shape_arc.h:175
VECTOR2I m_mid
Definition: shape_arc.h:174
void update_bbox()
Definition: shape_arc.cpp:263
VECTOR2I m_start
Definition: shape_arc.h:173

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 497 of file shape_arc.cpp.

498 {
499  m_start = axis.ReflectPoint( m_start );
500  m_end = axis.ReflectPoint( m_end );
501  m_mid = axis.ReflectPoint( m_mid );
502 
503  update_bbox();
504 }
VECTOR2I m_end
Definition: shape_arc.h:175
const VECTOR2I ReflectPoint(const VECTOR2I &aP) const
Reflect a point using this segment as axis.
Definition: seg.h:458
VECTOR2I m_mid
Definition: shape_arc.h:174
void update_bbox()
Definition: shape_arc.cpp:263
VECTOR2I m_start
Definition: shape_arc.h:173

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 450 of file shape_arc.cpp.

451 {
452  m_start += aVector;
453  m_end += aVector;
454  m_mid += aVector;
455  update_bbox();
456 }
VECTOR2I m_end
Definition: shape_arc.h:175
VECTOR2I m_mid
Definition: shape_arc.h:174
void update_bbox()
Definition: shape_arc.cpp:263
VECTOR2I m_start
Definition: shape_arc.h:173

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

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

◆ Reverse()

void SHAPE_ARC::Reverse ( )

Definition at line 507 of file shape_arc.cpp.

508 {
509  std::swap( m_start, m_end );
510 }
VECTOR2I m_end
Definition: shape_arc.h:175
VECTOR2I m_start
Definition: shape_arc.h:173

References m_end, and m_start.

Referenced by SHAPE_LINE_CHAIN::Reverse().

◆ Reversed()

SHAPE_ARC SHAPE_ARC::Reversed ( ) const

Definition at line 513 of file shape_arc.cpp.

514 {
515  return SHAPE_ARC( m_end, m_mid, m_start, m_width );
516 }
VECTOR2I m_end
Definition: shape_arc.h:175
VECTOR2I m_mid
Definition: shape_arc.h:174
VECTOR2I m_start
Definition: shape_arc.h:173
SHAPE_ARC()
Definition: shape_arc.h:39
int m_width
Definition: shape_arc.h:177

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

Referenced by PNS::NODE::AssembleLine().

◆ Rotate()

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

Function Rotate rotates the arc by a given angle about a point.

Parameters
aCenteris the rotation center
aAnglerotation angle in radians

Implements SHAPE.

Definition at line 459 of file shape_arc.cpp.

460 {
461  m_start -= aCenter;
462  m_end -= aCenter;
463  m_mid -= aCenter;
464 
465  m_start = m_start.Rotate( aAngle );
466  m_end = m_end.Rotate( aAngle );
467  m_mid = m_mid.Rotate( aAngle );
468 
469  m_start += aCenter;
470  m_end += aCenter;
471  m_mid += aCenter;
472 
473  update_bbox();
474 }
VECTOR2I m_end
Definition: shape_arc.h:175
VECTOR2I m_mid
Definition: shape_arc.h:174
void update_bbox()
Definition: shape_arc.cpp:263
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371
VECTOR2I m_start
Definition: shape_arc.h:173

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

◆ SetWidth()

void SHAPE_ARC::SetWidth ( int  aWidth)
inline

Definition at line 107 of file shape_arc.h.

108  {
109  m_width = aWidth;
110  }
int m_width
Definition: shape_arc.h:177

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 263 of file shape_arc.cpp.

264 {
265  std::vector<VECTOR2I> points;
266  // Put start and end points in the point list
267  points.push_back( m_start );
268  points.push_back( m_end );
269 
270  double start_angle = GetStartAngle();
271  double end_angle = start_angle + GetCentralAngle();
272 
273  // we always count quadrants clockwise (increasing angle)
274  if( start_angle > end_angle )
275  std::swap( start_angle, end_angle );
276 
277  int quad_angle_start = std::ceil( start_angle / 90.0 );
278  int quad_angle_end = std::floor( end_angle / 90.0 );
279 
280  // count through quadrants included in arc
281  for( int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle )
282  {
283  const int radius = KiROUND( GetRadius() );
284  VECTOR2I quad_pt = GetCenter();
285 
286  switch( quad_angle % 4 )
287  {
288  case 0: quad_pt += { radius, 0 }; break;
289  case 1:
290  case -3: quad_pt += { 0, radius }; break;
291  case 2:
292  case -2: quad_pt += { -radius, 0 }; break;
293  case 3:
294  case -1: quad_pt += { 0, -radius }; break;
295  default: assert( false );
296  }
297 
298  points.push_back( quad_pt );
299  }
300 
301  m_bbox.Compute( points );
302 }
double GetRadius() const
Definition: shape_arc.cpp:402
VECTOR2I m_end
Definition: shape_arc.h:175
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:91
double GetStartAngle() const
Definition: shape_arc.cpp:363
VECTOR2I m_start
Definition: shape_arc.h:173
double GetCentralAngle() const
Definition: shape_arc.cpp:389
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:68
BOX2I m_bbox
Definition: shape_arc.h:178
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:383

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

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

Member Data Documentation

◆ m_bbox

BOX2I SHAPE_ARC::m_bbox
private

Definition at line 178 of file shape_arc.h.

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

◆ m_end

◆ m_mid

VECTOR2I SHAPE_ARC::m_mid
private

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


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