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 ctor. More...
 
 SHAPE_ARC (const SHAPE_ARC &aOther)
 
 ~SHAPE_ARC ()
 
SHAPEClone () const override
 Function Clone() More...
 
const VECTOR2IGetP0 () const
 
const VECTOR2I GetP1 () const
 
const VECTOR2I GetArcMid () 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
 
void Rotate (double aAngle, const VECTOR2I &aCenter)
 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 })
 
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
 
FACETNewFacet ()
 
SGNODECalcShape (SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
 

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_p0
 
VECTOR2I m_pc
 
double m_centralAngle
 
int m_width
 
BOX2I m_bbox
 

Detailed Description

Definition at line 36 of file shape_arc.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 63 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_ARC() [1/3]

SHAPE_ARC::SHAPE_ARC ( )
inline

Definition at line 39 of file shape_arc.h.

39  :
40  SHAPE( SH_ARC ), m_centralAngle( 0.0 ), m_width( 0 ) {};
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:72
compound shape, consisting of multiple simple shapes
Definition: shape.h:52
int m_width
Definition: shape_arc.h:193
double m_centralAngle
Definition: shape_arc.h:191

Referenced by Clone().

◆ SHAPE_ARC() [2/3]

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

SHAPE_ARC ctor.

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

Definition at line 49 of file shape_arc.h.

50  :
51  SHAPE( SH_ARC ), m_p0( aArcStartPoint ), m_pc( aArcCenter ), m_centralAngle( aCenterAngle ),
52  m_width( aWidth )
53  {
54  update_bbox();
55  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:72
VECTOR2I m_p0
Definition: shape_arc.h:190
compound shape, consisting of multiple simple shapes
Definition: shape.h:52
void update_bbox()
Definition: shape_arc.cpp:175
VECTOR2I m_pc
Definition: shape_arc.h:190
int m_width
Definition: shape_arc.h:193
double m_centralAngle
Definition: shape_arc.h:191

References update_bbox().

◆ SHAPE_ARC() [3/3]

SHAPE_ARC::SHAPE_ARC ( const SHAPE_ARC aOther)
inline

Definition at line 57 of file shape_arc.h.

58  : SHAPE( SH_ARC )
59  {
60  m_p0 = aOther.m_p0;
61  m_pc = aOther.m_pc;
63  m_width = aOther.m_width;
64  m_bbox = aOther.m_bbox;
65  }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:72
VECTOR2I m_p0
Definition: shape_arc.h:190
compound shape, consisting of multiple simple shapes
Definition: shape.h:52
VECTOR2I m_pc
Definition: shape_arc.h:190
int m_width
Definition: shape_arc.h:193
BOX2I m_bbox
Definition: shape_arc.h:194
double m_centralAngle
Definition: shape_arc.h:191

References m_bbox, m_centralAngle, m_p0, m_pc, and m_width.

◆ ~SHAPE_ARC()

SHAPE_ARC::~SHAPE_ARC ( )
inline

Definition at line 67 of file shape_arc.h.

67 {}

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

219 {
220  BOX2I bbox( m_bbox );
221 
222  if( aClearance != 0 )
223  bbox.Inflate( aClearance );
224 
225  return bbox;
226 }
BOX2I m_bbox
Definition: shape_arc.h:194

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( 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:636
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
static VRML_COLOR colors[VRML_COLOR_LAST]
IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40

References IFSG_NODE::AddChildNode(), IFSG_INDEX::AddIndex(), IFSG_NODE::AddRefNode(), colors, SHAPE::facets, IFSG_NODE::GetRawPtr(), S3D::GetSGNodeParent(), IFSG_FACESET::NewNode(), IFSG_SHAPE::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 181 of file shape_arc.h.

182  {
183  return (ecoord) ( aC.y - aA.y ) * ( aB.x - aA.x ) >
184  (ecoord) ( aB.y - aA.y ) * ( aC.x - aA.x );
185  }
VECTOR2I::extended_type ecoord
VECTOR2I::extended_type ecoord
Definition: shape.h:63

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

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

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

70  {
71  return new SHAPE_ARC( *this );
72  }
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 
) 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 40 of file shape_arc.cpp.

41 {
42  int minDist = aClearance + m_width / 2;
43  auto centerDist = aSeg.Distance( m_pc );
44  auto p1 = GetP1();
45 
46  if( centerDist < minDist )
47  return true;
48 
49  auto ab = (aSeg.B - aSeg.A );
50  auto ac = ( m_pc - aSeg.A );
51 
52  auto lenAbSq = ab.SquaredEuclideanNorm();
53 
54  auto lambda = (double) ac.Dot( ab ) / (double) lenAbSq;
55 
56 
57  if( lambda >= 0.0 && lambda <= 1.0 )
58  {
59  VECTOR2I p;
60 
61  p.x = (double) aSeg.A.x * lambda + (double) aSeg.B.x * (1.0 - lambda);
62  p.y = (double) aSeg.A.y * lambda + (double) aSeg.B.y * (1.0 - lambda);
63 
64  auto p0pdist = ( m_p0 - p ).EuclideanNorm();
65 
66  if( p0pdist < minDist )
67  return true;
68 
69  auto p1pdist = ( p1 - p ).EuclideanNorm();
70 
71  if( p1pdist < minDist )
72  return true;
73  }
74 
75  auto p0dist = aSeg.Distance( m_p0 );
76 
77  if( p0dist > minDist )
78  return true;
79 
80  auto p1dist = aSeg.Distance( p1 );
81 
82  if( p1dist > minDist )
83  return false;
84 
85 
86  return true;
87 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:128
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:202
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2I m_p0
Definition: shape_arc.h:190
const VECTOR2I GetP1() const
Definition: shape_arc.cpp:149
VECTOR2I A
Definition: seg.h:47
VECTOR2I m_pc
Definition: shape_arc.h:190
int m_width
Definition: shape_arc.h:193
VECTOR2I B
Definition: seg.h:48

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

230 {
231  int minDist = aClearance + m_width / 2;
232  auto bbox = BBox( minDist );
233 
234  if( !bbox.Contains( aP ) )
235  return false;
236 
237  auto dist = ( aP - GetCenter() ).SquaredEuclideanNorm();
238 
239  return dist <= ( GetRadius() + minDist ) && dist >= ( GetRadius() - minDist );
240 }
static const int dist[10][10]
Definition: ar_matrix.cpp:326
int GetRadius() const
Definition: shape_arc.cpp:269
const VECTOR2I & GetCenter() const
Definition: shape_arc.h:77
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_arc.cpp:218
int m_width
Definition: shape_arc.h:193

References BBox(), dist, GetCenter(), GetRadius(), and m_width.

◆ 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 549 of file shape_collisions.cpp.

550 {
551  return CollideShapes( this, aShape, aClearance, true, aMTV );
552 }
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 555 of file shape_collisions.cpp.

556 {
557  VECTOR2I dummy;
558 
559  return CollideShapes( this, aShape, aClearance, false, dummy );
560 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
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 274 of file shape_arc.cpp.

275 {
276  SHAPE_LINE_CHAIN rv;
277  double r = GetRadius();
278  double sa = GetStartAngle();
279  auto c = GetCenter();
280  int n;
281 
282  if( r == 0.0 )
283  {
284  n = 0;
285  }
286  else
287  {
288  n = GetArcToSegmentCount( r, aAccuracy, m_centralAngle );
289  }
290 
291  for( int i = 0; i <= n ; i++ )
292  {
293  double a = sa;
294 
295  if( n != 0 )
296  a += m_centralAngle * (double) i / (double) n;
297 
298  double x = c.x + r * cos( a * M_PI / 180.0 );
299  double y = c.y + r * sin( a * M_PI / 180.0 );
300 
301  rv.Append( (int) x, (int) y );
302  }
303 
304  return rv;
305 }
double GetStartAngle() const
Definition: shape_arc.cpp:243
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
int GetRadius() const
Definition: shape_arc.cpp:269
const VECTOR2I & GetCenter() const
Definition: shape_arc.h:77
SHAPE_LINE_CHAIN.
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
double m_centralAngle
Definition: shape_arc.h:191

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

Referenced by GRID_HELPER::AlignToArc(), SHAPE_LINE_CHAIN::Append(), PNS::ArcHull(), Collide(), SHAPE_LINE_CHAIN::Insert(), SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN(), PNS_KICAD_IFACE_BASE::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().

◆ GetArcMid()

const VECTOR2I SHAPE_ARC::GetArcMid ( ) const

Definition at line 162 of file shape_arc.cpp.

163 {
164  VECTOR2D rvec = m_p0 - m_pc;
165  auto ca = m_centralAngle / 2.0 * M_PI / 180.0;
166  VECTOR2I p1;
167 
168  p1.x = KiROUND( m_pc.x + rvec.x * cos( ca ) - rvec.y * sin( ca ) );
169  p1.y = KiROUND( m_pc.y + rvec.x * sin( ca ) + rvec.y * cos( ca ) );
170 
171  return p1;
172 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2I m_p0
Definition: shape_arc.h:190
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:61
VECTOR2I m_pc
Definition: shape_arc.h:190
double m_centralAngle
Definition: shape_arc.h:191

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

Referenced by ARC::ARC().

◆ GetCenter()

const VECTOR2I& SHAPE_ARC::GetCenter ( ) const
inline

Definition at line 77 of file shape_arc.h.

77 { return m_pc; }
VECTOR2I m_pc
Definition: shape_arc.h:190

References m_pc.

Referenced by CheckArcGeom(), Collide(), and ConvertToPolyline().

◆ GetCentralAngle()

double SHAPE_ARC::GetCentralAngle ( ) const

Definition at line 264 of file shape_arc.cpp.

265 {
266  return m_centralAngle;
267 }
double m_centralAngle
Definition: shape_arc.h:191

References m_centralAngle.

Referenced by CheckArcGeom(), and update_bbox().

◆ GetChord()

SEG SHAPE_ARC::GetChord ( ) const
inline

Definition at line 146 of file shape_arc.h.

147  {
148  return SEG( m_p0, GetP1() );
149  }
VECTOR2I m_p0
Definition: shape_arc.h:190
const VECTOR2I GetP1() const
Definition: shape_arc.cpp:149
Definition: seg.h:39

References GetP1(), and m_p0.

Referenced by CheckArcGeom().

◆ GetEndAngle()

double SHAPE_ARC::GetEndAngle ( ) const

Definition at line 252 of file shape_arc.cpp.

253 {
254  double a = GetStartAngle() + m_centralAngle;
255 
256  if( a < 0.0 )
257  a += 360.0;
258  else if ( a >= 360.0 )
259  a -= 360.0;
260 
261  return a;
262 }
double GetStartAngle() const
Definition: shape_arc.cpp:243
double m_centralAngle
Definition: shape_arc.h:191

References GetStartAngle(), and m_centralAngle.

Referenced by CheckArcGeom().

◆ GetP0()

const VECTOR2I& SHAPE_ARC::GetP0 ( ) const
inline

Definition at line 74 of file shape_arc.h.

74 { return m_p0; }
VECTOR2I m_p0
Definition: shape_arc.h:190

References m_p0.

Referenced by PNS::ARC::Anchor(), and ARC::ARC().

◆ GetP1()

const VECTOR2I SHAPE_ARC::GetP1 ( ) const

Definition at line 149 of file shape_arc.cpp.

150 {
151  VECTOR2D rvec = m_p0 - m_pc;
152  auto ca = m_centralAngle * M_PI / 180.0;
153  VECTOR2I p1;
154 
155  p1.x = KiROUND( m_pc.x + rvec.x * cos( ca ) - rvec.y * sin( ca ) );
156  p1.y = KiROUND( m_pc.y + rvec.x * sin( ca ) + rvec.y * cos( ca ) );
157 
158  return p1;
159 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2I m_p0
Definition: shape_arc.h:190
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:61
VECTOR2I m_pc
Definition: shape_arc.h:190
double m_centralAngle
Definition: shape_arc.h:191

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

Referenced by PNS::ARC::Anchor(), ARC::ARC(), CheckArcGeom(), Collide(), GetChord(), and update_bbox().

◆ GetRadius()

int SHAPE_ARC::GetRadius ( ) const

Definition at line 269 of file shape_arc.cpp.

270 {
271  return (m_p0 - m_pc).EuclideanNorm();
272 }
VECTOR2I m_p0
Definition: shape_arc.h:190
VECTOR2I m_pc
Definition: shape_arc.h:190

References m_p0, and m_pc.

Referenced by CheckArcGeom(), Collide(), ConvertToPolyline(), and update_bbox().

◆ GetStartAngle()

double SHAPE_ARC::GetStartAngle ( ) const

Definition at line 243 of file shape_arc.cpp.

244 {
245  VECTOR2D d( m_p0 - m_pc );
246 
247  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
248 
249  return ang;
250 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2I m_p0
Definition: shape_arc.h:190
VECTOR2I m_pc
Definition: shape_arc.h:190

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

Referenced by CheckArcGeom(), ConvertToPolyline(), GetEndAngle(), and update_bbox().

◆ GetWidth()

int SHAPE_ARC::GetWidth ( ) const
inline

Definition at line 89 of file shape_arc.h.

90  {
91  return m_width;
92  }
int m_width
Definition: shape_arc.h:193

References m_width.

Referenced by PNS::ArcHull(), and PNS::ARC::Width().

◆ IsSolid()

bool SHAPE_ARC::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 94 of file shape_arc.h.

95  {
96  return true;
97  }

Referenced by CheckArcGeom().

◆ Mirror()

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

Definition at line 125 of file shape_arc.h.

125  { 0, 0 } )
126  {
127  if( aX )
128  {
129  m_p0.x = -m_p0.x + 2 * aVector.x;
130  m_pc.x = -m_pc.x + 2 * aVector.x;
132  }
133 
134  if( aY )
135  {
136  m_p0.y = -m_p0.y + 2 * aVector.y;
137  m_pc.y = -m_pc.y + 2 * aVector.y;
139  }
140 
141  update_bbox();
142  }
VECTOR2I m_p0
Definition: shape_arc.h:190
void update_bbox()
Definition: shape_arc.cpp:175
VECTOR2I m_pc
Definition: shape_arc.h:190
double m_centralAngle
Definition: shape_arc.h:191

◆ Move()

void SHAPE_ARC::Move ( const VECTOR2I aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 99 of file shape_arc.h.

100  {
101  m_p0 += aVector;
102  m_pc += aVector;
103  update_bbox();
104  }
VECTOR2I m_p0
Definition: shape_arc.h:190
void update_bbox()
Definition: shape_arc.cpp:175
VECTOR2I m_pc
Definition: shape_arc.h:190

References m_p0, m_pc, 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 }

◆ Rotate()

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

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

Parameters
aCenteris the rotation center
aAnglerotation angle in radians

Definition at line 112 of file shape_arc.h.

113  {
114  m_p0 -= aCenter;
115  m_pc -= aCenter;
116 
117  m_p0.Rotate( aAngle );
118  m_pc.Rotate( aAngle );
119 
120  m_pc += aCenter;
121  m_p0 += aCenter;
122  update_bbox();
123  }
VECTOR2I m_p0
Definition: shape_arc.h:190
void update_bbox()
Definition: shape_arc.cpp:175
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:377
VECTOR2I m_pc
Definition: shape_arc.h:190

References m_p0, m_pc, VECTOR2< T >::Rotate(), and update_bbox().

◆ SetWidth()

void SHAPE_ARC::SetWidth ( int  aWidth)
inline

Definition at line 84 of file shape_arc.h.

85  {
86  m_width = aWidth;
87  }
int m_width
Definition: shape_arc.h:193

References m_width.

Referenced by PNS::ARC::SetWidth().

◆ Type()

SHAPE_TYPE SHAPE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 85 of file shape.h.

86  {
87  return m_type;
88  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:168

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

◆ update_bbox()

void SHAPE_ARC::update_bbox ( )
private

Definition at line 175 of file shape_arc.cpp.

176 {
177  std::vector<VECTOR2I> points;
178  // Put start and end points in the point list
179  points.push_back( m_p0 );
180  points.push_back( GetP1() );
181  // points.push_back( m_pc ); the center point is not necessary in the BBox
182 
183  double start_angle = GetStartAngle();
184  double end_angle = start_angle + GetCentralAngle();
185 
186  // we always count quadrants clockwise (increasing angle)
187  if( start_angle > end_angle )
188  std::swap( start_angle, end_angle );
189 
190  int quad_angle_start = std::ceil( start_angle / 90.0 );
191  int quad_angle_end = std::floor( end_angle / 90.0 );
192 
193  // count through quadrants included in arc
194  for( int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle )
195  {
196  const int radius = GetRadius();
197  VECTOR2I quad_pt = m_pc;
198 
199  switch( quad_angle % 4 )
200  {
201  case 0: quad_pt += { radius, 0 }; break;
202  case 1:
203  case -3: quad_pt += { 0, radius }; break;
204  case 2:
205  case -2: quad_pt += { -radius, 0 }; break;
206  case 3:
207  case -1: quad_pt += { 0, -radius }; break;
208  default: assert( false );
209  }
210 
211  points.push_back( quad_pt );
212  }
213 
214  m_bbox.Compute( points );
215 }
VECTOR2 defines 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:90
double GetStartAngle() const
Definition: shape_arc.cpp:243
int GetRadius() const
Definition: shape_arc.cpp:269
VECTOR2I m_p0
Definition: shape_arc.h:190
const VECTOR2I GetP1() const
Definition: shape_arc.cpp:149
double GetCentralAngle() const
Definition: shape_arc.cpp:264
VECTOR2I m_pc
Definition: shape_arc.h:190
BOX2I m_bbox
Definition: shape_arc.h:194

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

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

Member Data Documentation

◆ m_bbox

BOX2I SHAPE_ARC::m_bbox
private

Definition at line 194 of file shape_arc.h.

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

◆ m_centralAngle

double SHAPE_ARC::m_centralAngle
private

◆ m_p0

VECTOR2I SHAPE_ARC::m_p0
private

◆ m_pc

VECTOR2I SHAPE_ARC::m_pc
private

◆ m_type

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 168 of file shape.h.

Referenced by SHAPE::Type().

◆ m_width

int SHAPE_ARC::m_width
private

Definition at line 193 of file shape_arc.h.

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


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