KiCad PCB EDA Suite
SHAPE_ARC Class Reference

#include <shape_arc.h>

Inheritance diagram for SHAPE_ARC:
SHAPE

Public Member Functions

 SHAPE_ARC ()
 
 SHAPE_ARC (const VECTOR2I &aArcCenter, const VECTOR2I &aArcStartPoint, double aCenterAngle, int aWidth=0)
 
 SHAPE_ARC (const SHAPE_ARC &aOther)
 
 ~SHAPE_ARC ()
 
SHAPEClone () const override
 Function Clone() More...
 
const VECTOR2IGetP0 () const
 
const VECTOR2I GetP1 () const
 
const VECTOR2IGetCenter () const
 
const BOX2I BBox (int aClearance=0) const override
 Function BBox() More...
 
bool Collide (const SEG &aSeg, int aClearance=0) const override
 Function Collide() More...
 
bool Collide (const VECTOR2I &aP, int aClearance=0) const override
 Function Collide() More...
 
void SetWidth (int aWidth)
 
int GetWidth () const
 
bool IsSolid () const override
 
void Move (const VECTOR2I &aVector) override
 
int GetRadius () const
 
SEG GetChord () const
 
double GetCentralAngle () const
 
double GetStartAngle () const
 
double GetEndAngle () const
 
const SHAPE_LINE_CHAIN ConvertToPolyline (double aAccuracy=500.0) const
 Constructs a SHAPE_LINE_CHAIN of segments from a given arc. More...
 
SHAPE_TYPE Type () const
 Function Type() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I &aMTV) const
 Function Collide() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance=0) const
 
virtual VECTOR2I Centre () const
 Function Centre() More...
 
virtual bool Parse (std::stringstream &aStream)
 
virtual const std::string Format () const
 

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
 

Private Attributes

VECTOR2I m_p0
 
VECTOR2I m_pc
 
double m_centralAngle
 
int m_width
 

Detailed Description

Definition at line 33 of file shape_arc.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 61 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_ARC() [1/3]

SHAPE_ARC::SHAPE_ARC ( )
inline

Definition at line 36 of file shape_arc.h.

36  :
37  SHAPE( SH_ARC ), m_centralAngle( 0.0 ), m_width( 0 ) {};
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
compound shape, consisting of multiple simple shapes
Definition: shape.h:50
int m_width
Definition: shape_arc.h:139
double m_centralAngle
Definition: shape_arc.h:137

Referenced by Clone().

◆ SHAPE_ARC() [2/3]

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

Definition at line 39 of file shape_arc.h.

40  :
41  SHAPE( SH_ARC ), m_p0( aArcStartPoint ), m_pc( aArcCenter ), m_centralAngle( aCenterAngle ),
42  m_width( aWidth )
43  {
44  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
VECTOR2I m_p0
Definition: shape_arc.h:136
compound shape, consisting of multiple simple shapes
Definition: shape.h:50
VECTOR2I m_pc
Definition: shape_arc.h:136
int m_width
Definition: shape_arc.h:139
double m_centralAngle
Definition: shape_arc.h:137

◆ SHAPE_ARC() [3/3]

SHAPE_ARC::SHAPE_ARC ( const SHAPE_ARC aOther)
inline

Definition at line 46 of file shape_arc.h.

47  : SHAPE( SH_ARC )
48  {
49  m_p0 = aOther.m_p0;
50  m_pc = aOther.m_pc;
52  m_width = aOther.m_width;
53  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70
VECTOR2I m_p0
Definition: shape_arc.h:136
compound shape, consisting of multiple simple shapes
Definition: shape.h:50
VECTOR2I m_pc
Definition: shape_arc.h:136
int m_width
Definition: shape_arc.h:139
double m_centralAngle
Definition: shape_arc.h:137

References m_centralAngle, m_p0, m_pc, and m_width.

◆ ~SHAPE_ARC()

SHAPE_ARC::~SHAPE_ARC ( )
inline

Definition at line 55 of file shape_arc.h.

55 {}

Member Function Documentation

◆ BBox()

const BOX2I SHAPE_ARC::BBox ( int  aClearance = 0) const
overridevirtual

Function BBox()

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

155 {
156  BOX2I bbox;
157  std::vector<VECTOR2I> points;
158  points.push_back( m_pc );
159  points.push_back( m_p0 );
160  points.push_back( GetP1() );
161 
162  double start_angle = GetStartAngle();
163  double end_angle = start_angle + GetCentralAngle();
164 
165  // we always count quadrants clockwise (increasing angle)
166  if( start_angle > end_angle )
167  std::swap( start_angle, end_angle );
168 
169  int quad_angle_start = std::ceil( start_angle / 90.0 );
170  int quad_angle_end = std::floor( end_angle / 90.0 );
171 
172  // count through quadrants included in arc
173  for( int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle )
174  {
175  const int radius = GetRadius();
176  VECTOR2I quad_pt = m_pc;
177 
178  switch( quad_angle % 4 )
179  {
180  case 0: quad_pt += { radius, 0 }; break;
181  case 1:
182  case -3: quad_pt += { 0, radius }; break;
183  case 2:
184  case -2: quad_pt += { -radius, 0 }; break;
185  case 3:
186  case -1: quad_pt += { 0, -radius }; break;
187  default: assert( false );
188  }
189 
190  points.push_back( quad_pt );
191  }
192 
193  bbox.Compute( points );
194 
195  if( aClearance != 0 )
196  bbox.Inflate( aClearance );
197 
198  return bbox;
199 }
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:89
double GetStartAngle() const
Definition: shape_arc.cpp:209
int GetRadius() const
Definition: shape_arc.cpp:235
VECTOR2I m_p0
Definition: shape_arc.h:136
const VECTOR2I GetP1() const
Definition: shape_arc.cpp:141
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:300
double GetCentralAngle() const
Definition: shape_arc.cpp:230
VECTOR2I m_pc
Definition: shape_arc.h:136

References BOX2< Vec >::Compute(), GetCentralAngle(), GetP1(), GetRadius(), GetStartAngle(), BOX2< Vec >::Inflate(), m_p0, and m_pc.

◆ ccw()

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

Definition at line 129 of file shape_arc.h.

130  {
131  return (ecoord) ( aC.y - aA.y ) * ( aB.x - aA.x ) >
132  (ecoord) ( aB.y - aA.y ) * ( aC.x - aA.x );
133  }
VECTOR2I::extended_type ecoord
Definition: pns_item.cpp:26
VECTOR2I::extended_type ecoord
Definition: shape.h:61

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

◆ Centre()

virtual VECTOR2I SHAPE::Centre ( ) const
inlinevirtualinherited

Function Centre()

Computes a center-of-mass of the shape

Returns
the center-of-mass point

Definition at line 151 of file shape.h.

152  {
153  return BBox( 0 ).Centre(); // if nothing better is available....
154  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:77

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

Referenced by PNS_PCBNEW_RULE_RESOLVER::CollideHoles().

◆ Clone()

SHAPE* SHAPE_ARC::Clone ( ) const
inlineoverridevirtual

Function Clone()

Returns a dynamically allocated copy of the shape

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 57 of file shape_arc.h.

58  {
59  return new SHAPE_ARC( *this );
60  }
SHAPE_ARC()
Definition: shape_arc.h:36

References SHAPE_ARC().

◆ Collide() [1/4]

bool SHAPE_ARC::Collide ( const SEG aSeg,
int  aClearance = 0 
) const
overridevirtual

Function Collide()

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

Returns
true, if there is a collision.

Implements SHAPE.

Definition at line 32 of file shape_arc.cpp.

33 {
34  int minDist = aClearance + m_width / 2;
35  auto centerDist = aSeg.Distance( m_pc );
36  auto p1 = GetP1();
37 
38  if( centerDist < minDist )
39  return true;
40 
41  auto ab = (aSeg.B - aSeg.A );
42  auto ac = ( m_pc - aSeg.A );
43 
44  auto lenAbSq = ab.SquaredEuclideanNorm();
45 
46  auto lambda = (double) ac.Dot( ab ) / (double) lenAbSq;
47 
48 
49  if( lambda >= 0.0 && lambda <= 1.0 )
50  {
51  VECTOR2I p;
52 
53  p.x = (double) aSeg.A.x * lambda + (double) aSeg.B.x * (1.0 - lambda);
54  p.y = (double) aSeg.A.y * lambda + (double) aSeg.B.y * (1.0 - lambda);
55 
56  auto p0pdist = ( m_p0 - p ).EuclideanNorm();
57 
58  if( p0pdist < minDist )
59  return true;
60 
61  auto p1pdist = ( p1 - p ).EuclideanNorm();
62 
63  if( p1pdist < minDist )
64  return true;
65  }
66 
67  auto p0dist = aSeg.Distance( m_p0 );
68 
69  if( p0dist > minDist )
70  return true;
71 
72  auto p1dist = aSeg.Distance( p1 );
73 
74  if( p1dist > minDist )
75  return false;
76 
77 
78  return true;
79 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:123
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
VECTOR2I m_p0
Definition: shape_arc.h:136
const VECTOR2I GetP1() const
Definition: shape_arc.cpp:141
VECTOR2I A
Definition: seg.h:44
VECTOR2I m_pc
Definition: shape_arc.h:136
int m_width
Definition: shape_arc.h:139
VECTOR2I B
Definition: seg.h:45

References SEG::A, SEG::B, SEG::Distance(), EuclideanNorm(), GetP1(), m_p0, m_pc, m_width, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Collide() [2/4]

bool SHAPE_ARC::Collide ( const VECTOR2I aP,
int  aClearance = 0 
) const
overridevirtual

Function Collide()

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

Returns
true, if there is a collision.

Reimplemented from SHAPE.

Definition at line 202 of file shape_arc.cpp.

203 {
204  assert( false );
205  return false;
206 }

◆ Collide() [3/4]

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

Function Collide()

Checks 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
Returns
true, if there is a collision.

Definition at line 545 of file shape_collisions.cpp.

546 {
547  return CollideShapes( this, aShape, aClearance, true, aMTV );
548 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

References CollideShapes().

◆ Collide() [4/4]

bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance = 0 
) const
virtualinherited

Definition at line 551 of file shape_collisions.cpp.

552 {
553  VECTOR2I dummy;
554 
555  return CollideShapes( this, aShape, aClearance, false, dummy );
556 }
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

References CollideShapes(), and dummy().

◆ ConvertToPolyline()

const SHAPE_LINE_CHAIN SHAPE_ARC::ConvertToPolyline ( double  aAccuracy = 500.0) 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 of 500.0 here is given using ARC_DEF_HIGH_ACCURACY for 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 240 of file shape_arc.cpp.

241 {
242  SHAPE_LINE_CHAIN rv;
243  double r = GetRadius();
244  double sa = GetStartAngle();
245  auto c = GetCenter();
246  int n;
247 
248  if( r == 0.0 )
249  {
250  n = 0;
251  }
252  else
253  {
254  n = GetArcToSegmentCount( r, aAccuracy, m_centralAngle );
255  }
256 
257  for( int i = 0; i <= n ; i++ )
258  {
259  double a = sa;
260 
261  if( n != 0 )
262  a += m_centralAngle * (double) i / (double) n;
263 
264  double x = c.x + r * cos( a * M_PI / 180.0 );
265  double y = c.y + r * sin( a * M_PI / 180.0 );
266 
267  rv.Append( (int) x, (int) y );
268  }
269 
270  return rv;
271 }
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
double GetStartAngle() const
Definition: shape_arc.cpp:209
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
int GetRadius() const
Definition: shape_arc.cpp:235
const VECTOR2I & GetCenter() const
Definition: shape_arc.h:64
Class SHAPE_LINE_CHAIN.
size_t i
Definition: json11.cpp:597
double m_centralAngle
Definition: shape_arc.h:137

References SHAPE_LINE_CHAIN::Append(), GetArcToSegmentCount(), GetCenter(), GetRadius(), GetStartAngle(), i, and m_centralAngle.

Referenced by Collide(), PNS_KICAD_IFACE::syncGraphicalItem(), and DRC::testCopperDrawItem().

◆ Format()

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

Reimplemented in SHAPE_POLY_SET, and SHAPE_LINE_CHAIN.

Definition at line 35 of file shape.cpp.

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

Referenced by SHAPE_FILE_IO::Write().

◆ GetCenter()

const VECTOR2I& SHAPE_ARC::GetCenter ( ) const
inline

Definition at line 64 of file shape_arc.h.

64 { return m_pc; }
VECTOR2I m_pc
Definition: shape_arc.h:136

References m_pc.

Referenced by ConvertToPolyline().

◆ GetCentralAngle()

double SHAPE_ARC::GetCentralAngle ( ) const

Definition at line 230 of file shape_arc.cpp.

231 {
232  return m_centralAngle;
233 }
double m_centralAngle
Definition: shape_arc.h:137

References m_centralAngle.

Referenced by BBox().

◆ GetChord()

SEG SHAPE_ARC::GetChord ( ) const
inline

Definition at line 94 of file shape_arc.h.

95  {
96  return SEG( m_p0, GetP1() );
97  }
VECTOR2I m_p0
Definition: shape_arc.h:136
const VECTOR2I GetP1() const
Definition: shape_arc.cpp:141
Definition: seg.h:36

References GetP1(), and m_p0.

◆ GetEndAngle()

double SHAPE_ARC::GetEndAngle ( ) const

Definition at line 218 of file shape_arc.cpp.

219 {
220  double a = GetStartAngle() + m_centralAngle;
221 
222  if( a < 0.0 )
223  a += 360.0;
224  else if ( a >= 360.0 )
225  a -= 360.0;
226 
227  return a;
228 }
double GetStartAngle() const
Definition: shape_arc.cpp:209
double m_centralAngle
Definition: shape_arc.h:137

References GetStartAngle(), and m_centralAngle.

◆ GetP0()

const VECTOR2I& SHAPE_ARC::GetP0 ( ) const
inline

Definition at line 62 of file shape_arc.h.

62 { return m_p0; }
VECTOR2I m_p0
Definition: shape_arc.h:136

References m_p0.

◆ GetP1()

const VECTOR2I SHAPE_ARC::GetP1 ( ) const

Definition at line 141 of file shape_arc.cpp.

142 {
143  VECTOR2D rvec = m_p0 - m_pc;
144  auto ca = m_centralAngle * M_PI / 180.0;
145  VECTOR2I p1;
146 
147  p1.x = (int) ( m_pc.x + rvec.x * cos( ca ) - rvec.y * sin( ca ) );
148  p1.y = (int) ( m_pc.y + rvec.x * sin( ca ) + rvec.y * cos( ca ) );
149 
150  return p1;
151 }
VECTOR2I m_p0
Definition: shape_arc.h:136
VECTOR2I m_pc
Definition: shape_arc.h:136
double m_centralAngle
Definition: shape_arc.h:137

References m_centralAngle, m_p0, m_pc, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BBox(), Collide(), and GetChord().

◆ GetRadius()

int SHAPE_ARC::GetRadius ( ) const

Definition at line 235 of file shape_arc.cpp.

236 {
237  return (m_p0 - m_pc).EuclideanNorm();
238 }
VECTOR2I m_p0
Definition: shape_arc.h:136
VECTOR2I m_pc
Definition: shape_arc.h:136

References m_p0, and m_pc.

Referenced by BBox(), and ConvertToPolyline().

◆ GetStartAngle()

double SHAPE_ARC::GetStartAngle ( ) const

Definition at line 209 of file shape_arc.cpp.

210 {
211  VECTOR2D d( m_p0 - m_pc );
212 
213  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
214 
215  return ang;
216 }
VECTOR2I m_p0
Definition: shape_arc.h:136
VECTOR2I m_pc
Definition: shape_arc.h:136

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

Referenced by BBox(), ConvertToPolyline(), and GetEndAngle().

◆ GetWidth()

int SHAPE_ARC::GetWidth ( ) const
inline

Definition at line 76 of file shape_arc.h.

77  {
78  return m_width;
79  }
int m_width
Definition: shape_arc.h:139

References m_width.

◆ IsSolid()

bool SHAPE_ARC::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 81 of file shape_arc.h.

82  {
83  return true;
84  }

◆ Move()

void SHAPE_ARC::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 86 of file shape_arc.h.

87  {
88  m_p0 += aVector;
89  m_pc += aVector;
90  }
VECTOR2I m_p0
Definition: shape_arc.h:136
VECTOR2I m_pc
Definition: shape_arc.h:136

References m_p0, and m_pc.

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

◆ SetWidth()

void SHAPE_ARC::SetWidth ( int  aWidth)
inline

Definition at line 71 of file shape_arc.h.

72  {
73  m_width = aWidth;
74  }
int m_width
Definition: shape_arc.h:139

References m_width.

◆ Type()

SHAPE_TYPE SHAPE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 83 of file shape.h.

84  {
85  return m_type;
86  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:166

References SHAPE::m_type.

Referenced by PNS::DP_GATEWAYS::BuildFromPrimitivePair(), CollideShapes(), PNS::OPTIMIZER::computeBreakouts(), PNS::LOGGER::dumpShape(), PNS::SOLID::Hull(), ROUTER_PREVIEW_ITEM::ViewDraw(), and SHAPE_FILE_IO::Write().

Member Data Documentation

◆ m_centralAngle

double SHAPE_ARC::m_centralAngle
private

Definition at line 137 of file shape_arc.h.

Referenced by ConvertToPolyline(), GetCentralAngle(), GetEndAngle(), GetP1(), and SHAPE_ARC().

◆ m_p0

VECTOR2I SHAPE_ARC::m_p0
private

Definition at line 136 of file shape_arc.h.

Referenced by BBox(), Collide(), GetChord(), GetP0(), GetP1(), GetRadius(), GetStartAngle(), Move(), and SHAPE_ARC().

◆ m_pc

VECTOR2I SHAPE_ARC::m_pc
private

Definition at line 136 of file shape_arc.h.

Referenced by BBox(), Collide(), GetCenter(), GetP1(), GetRadius(), GetStartAngle(), Move(), and SHAPE_ARC().

◆ m_type

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 166 of file shape.h.

Referenced by SHAPE::Type().

◆ m_width

int SHAPE_ARC::m_width
private

Definition at line 139 of file shape_arc.h.

Referenced by Collide(), GetWidth(), SetWidth(), and SHAPE_ARC().


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