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 VECTOR2I &aArcStart, const VECTOR2I &aArcMid, const VECTOR2I &aArcEnd, int aWidth)
 SHAPE_ARC ctor. More...
 
 SHAPE_ARC (const SHAPE_ARC &aOther)
 
virtual ~SHAPE_ARC ()
 
SHAPEClone () const override
 Function Clone() More...
 
const VECTOR2IGetP0 () const
 
const VECTOR2IGetP1 () const
 
const VECTOR2IGetArcMid () const
 
VECTOR2I GetCenter () const
 
const BOX2I BBox (int aClearance=0) const override
 Function BBox() More...
 
bool Collide (const SEG &aSeg, int aClearance=0, int *aActual=nullptr) const override
 Function Collide() More...
 
bool Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr) 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) 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 })
 
double 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, int *aActual=nullptr) 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_start
 
VECTOR2I m_mid
 
VECTOR2I m_end
 
int m_width
 
BOX2I m_bbox
 

Detailed Description

Definition at line 34 of file shape_arc.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 77 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_ARC() [1/4]

SHAPE_ARC::SHAPE_ARC ( )
inline

Definition at line 37 of file shape_arc.h.

37  :
38  SHAPE( SH_ARC ), m_width( 0 ) {};
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
compound shape, consisting of multiple simple shapes
Definition: shape.h:48
int m_width
Definition: shape_arc.h:144

Referenced by Clone().

◆ SHAPE_ARC() [2/4]

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

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 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)
Constructor.
Definition: shape.h:86
VECTOR2I m_end
Definition: shape_arc.h:142
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
VECTOR2I m_mid
Definition: shape_arc.h:141
compound shape, consisting of multiple simple shapes
Definition: shape.h:48
void update_bbox()
Definition: shape_arc.cpp:106
VECTOR2I m_start
Definition: shape_arc.h:140
int m_width
Definition: shape_arc.h:144

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

◆ SHAPE_ARC() [3/4]

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)
Constructor.
Definition: shape.h:86
VECTOR2I m_end
Definition: shape_arc.h:142
VECTOR2I m_mid
Definition: shape_arc.h:141
compound shape, consisting of multiple simple shapes
Definition: shape.h:48
void update_bbox()
Definition: shape_arc.cpp:106
VECTOR2I m_start
Definition: shape_arc.h:140
int m_width
Definition: shape_arc.h:144

References update_bbox().

◆ SHAPE_ARC() [4/4]

SHAPE_ARC::SHAPE_ARC ( const SHAPE_ARC aOther)

Definition at line 57 of file shape_arc.cpp.

58  : SHAPE( SH_ARC )
59 {
60  m_start = aOther.m_start;
61  m_end = aOther.m_end;
62  m_mid = aOther.m_mid;
63  m_width = aOther.m_width;
64  m_bbox = aOther.m_bbox;
65 }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
VECTOR2I m_end
Definition: shape_arc.h:142
VECTOR2I m_mid
Definition: shape_arc.h:141
compound shape, consisting of multiple simple shapes
Definition: shape.h:48
VECTOR2I m_start
Definition: shape_arc.h:140
int m_width
Definition: shape_arc.h:144
BOX2I m_bbox
Definition: shape_arc.h:145

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

◆ ~SHAPE_ARC()

virtual SHAPE_ARC::~SHAPE_ARC ( )
inlinevirtual

Definition at line 62 of file shape_arc.h.

62 {}

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

149 {
150  BOX2I bbox( m_bbox );
151 
152  if( aClearance != 0 )
153  bbox.Inflate( aClearance );
154 
155  return bbox;
156 }
BOX2I m_bbox
Definition: shape_arc.h:145

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

132  {
133  return (ecoord) ( aC.y - aA.y ) * ( aB.x - aA.x ) >
134  (ecoord) ( aB.y - aA.y ) * ( aC.x - aA.x );
135  }
VECTOR2I::extended_type ecoord
VECTOR2I::extended_type ecoord
Definition: shape.h:77

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

174  {
175  return BBox( 0 ).Centre(); // if nothing better is available....
176  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:79

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

65  {
66  return new SHAPE_ARC( *this );
67  }
SHAPE_ARC()
Definition: shape_arc.h:37

References SHAPE_ARC().

Referenced by CheckArc().

◆ Collide() [1/4]

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

Function Collide()

Checks if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating a collision. @aActual an optional pointer to an int to be updated with the actual distance in the case of collision.

Returns
true, if there is a collision.

Implements SHAPE.

Definition at line 68 of file shape_arc.cpp.

69 {
70  int minDist = aClearance + m_width / 2;
71  VECTOR2I center = GetCenter();
72  ecoord dist_sq = VECTOR2I::ECOORD_MAX;
73 
74  VECTOR2I ab = ( aSeg.B - aSeg.A );
75  VECTOR2I ac = ( center - aSeg.A );
76 
77  ecoord lenAbSq = ab.SquaredEuclideanNorm();
78  double lambda = (double) ac.Dot( ab ) / (double) lenAbSq;
79 
80  if( lambda >= 0.0 && lambda <= 1.0 )
81  {
82  VECTOR2I p;
83 
84  p.x = (double) aSeg.A.x * lambda + (double) aSeg.B.x * (1.0 - lambda);
85  p.y = (double) aSeg.A.y * lambda + (double) aSeg.B.y * (1.0 - lambda);
86 
87  dist_sq = std::min( dist_sq, ( m_start - p ).SquaredEuclideanNorm() );
88  dist_sq = std::min( dist_sq, ( m_end - p ).SquaredEuclideanNorm() );
89  }
90 
91  dist_sq = std::min( dist_sq, aSeg.SquaredDistance( m_start ) );
92  dist_sq = std::min( dist_sq, aSeg.SquaredDistance( m_end ) );
93 
94  if( dist_sq == 0 || dist_sq < (ecoord) minDist * minDist )
95  {
96  if( aActual )
97  *aActual = std::max( 0, (int) sqrt( dist_sq ) - m_width / 2 );
98 
99  return true;
100  }
101 
102  return false;
103 }
VECTOR2I m_end
Definition: shape_arc.h:142
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
extended_type SquaredEuclideanNorm() const
Function Squared Euclidean Norm computes the squared euclidean norm of the vector,...
Definition: vector2d.h:306
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:37
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:80
VECTOR2I::extended_type ecoord
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:492
VECTOR2I m_start
Definition: shape_arc.h:140
VECTOR2I A
Definition: seg.h:47
int m_width
Definition: shape_arc.h:144
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:206
VECTOR2I B
Definition: seg.h:48

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

◆ Collide() [2/4]

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

Function Collide()

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

Parameters
aActualan optional pointer to an int to store the actual distance in the event of a collision.
Returns
true, if there is a collision.

Reimplemented from SHAPE.

Definition at line 159 of file shape_arc.cpp.

160 {
161  int minDist = aClearance + m_width / 2;
162  auto bbox = BBox( minDist );
163 
164  if( !bbox.Contains( aP ) )
165  return false;
166 
167  ecoord min_dist_sq = (ecoord) minDist * minDist;
168  ecoord r = GetRadius();
169  ecoord r_sq = r * r;
170 
171  ecoord dist_sq = ( aP - GetCenter() ).SquaredEuclideanNorm();
172  ecoord dist_to_edge_sq = abs( dist_sq - r_sq );
173 
174  if( dist_to_edge_sq < min_dist_sq )
175  {
176  if( aActual )
177  *aActual = std::max( 0, (int) sqrt( dist_to_edge_sq ) - m_width / 2 );
178 
179  return true;
180  }
181 
182  return false;
183 }
double GetRadius() const
Definition: shape_arc.cpp:225
VECTOR2I::extended_type ecoord
VECTOR2I::extended_type ecoord
Definition: shape.h:77
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_arc.cpp:148
int m_width
Definition: shape_arc.h:144
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:206

References BBox(), 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
aActualan optional pointer to an int to store the actual distance 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 718 of file shape_collisions.cpp.

719 {
720  return collideShapes( this, aShape, aClearance, nullptr, aMTV );
721 }
static bool collideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References collideShapes().

◆ Collide() [4/4]

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

Reimplemented in SHAPE_RECT, SHAPE_SEGMENT, and SHAPE_COMPOUND.

Definition at line 724 of file shape_collisions.cpp.

725 {
726  return collideShapes( this, aShape, aClearance, aActual, nullptr );
727 }
static bool collideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aMTV)

References collideShapes().

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

232 {
233  SHAPE_LINE_CHAIN rv;
234  double r = GetRadius();
235  double sa = GetStartAngle();
236  auto c = GetCenter();
237  double ca = GetCentralAngle();
238 
239  int n;
240 
241  if( r == 0.0 )
242  {
243  n = 0;
244  }
245  else
246  {
247  n = GetArcToSegmentCount( r, aAccuracy, ca );
248  }
249 
250  for( int i = 0; i <= n ; i++ )
251  {
252  double a = sa;
253 
254  if( n != 0 )
255  a += ( ca * i ) / n;
256 
257  double x = c.x + r * cos( a * M_PI / 180.0 );
258  double y = c.y + r * sin( a * M_PI / 180.0 );
259 
260  rv.Append( KiROUND( x ), KiROUND( y ) );
261  }
262 
263  return rv;
264 }
double GetRadius() const
Definition: shape_arc.cpp:225
double GetStartAngle() const
Definition: shape_arc.cpp:186
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN.
double GetCentralAngle() const
Definition: shape_arc.cpp:212
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:206

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

Referenced by SHAPE_LINE_CHAIN::Append(), PNS::ArcHull(), Collide(), SHAPE_LINE_CHAIN::Insert(), DRAWSEGMENT::MakeEffectiveShapes(), and SHAPE_LINE_CHAIN::SHAPE_LINE_CHAIN().

◆ Format()

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

Reimplemented in SHAPE_POLY_SET, SHAPE_LINE_CHAIN, 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 71 of file shape_arc.h.

71 { return m_mid; }
VECTOR2I m_mid
Definition: shape_arc.h:141

References m_mid.

Referenced by ARC::ARC().

◆ GetCenter()

VECTOR2I SHAPE_ARC::GetCenter ( ) const

Definition at line 206 of file shape_arc.cpp.

207 {
208  return GetArcCenter( m_start, m_mid, m_end );
209 }
VECTOR2I m_end
Definition: shape_arc.h:142
VECTOR2I m_mid
Definition: shape_arc.h:141
VECTOR2I m_start
Definition: shape_arc.h:140
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:405

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

Referenced by CheckArcGeom(), Collide(), ConvertToPolyline(), GetCentralAngle(), GetEndAngle(), GetRadius(), GetStartAngle(), and update_bbox().

◆ GetCentralAngle()

double SHAPE_ARC::GetCentralAngle ( ) const

Definition at line 212 of file shape_arc.cpp.

213 {
214  VECTOR2I center = GetCenter();
215  VECTOR2I p0 = m_start - center;
216  VECTOR2I p1 = m_mid - center;
217  VECTOR2I p2 = m_end - center;
218  double angle1 = ArcTangente( p1.y, p1.x ) - ArcTangente( p0.y, p0.x );
219  double angle2 = ArcTangente( p2.y, p2.x ) - ArcTangente( p1.y, p1.x );
220 
221  return ( NormalizeAngle180( angle1 ) + NormalizeAngle180( angle2 ) ) / 10.0;
222 }
VECTOR2I m_end
Definition: shape_arc.h:142
VECTOR2 defines 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:345
VECTOR2I m_mid
Definition: shape_arc.h:141
VECTOR2I m_start
Definition: shape_arc.h:140
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:162
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:206

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

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

◆ GetChord()

SEG SHAPE_ARC::GetChord ( ) const
inline

Definition at line 108 of file shape_arc.h.

109  {
110  return SEG( m_start, m_end );
111  }
VECTOR2I m_end
Definition: shape_arc.h:142
Definition: seg.h:39
VECTOR2I m_start
Definition: shape_arc.h:140

References m_end, and m_start.

Referenced by CheckArcGeom().

◆ GetEndAngle()

double SHAPE_ARC::GetEndAngle ( ) const

Definition at line 196 of file shape_arc.cpp.

197 {
198  VECTOR2D d( m_end - GetCenter() );
199 
200  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
201 
202  return NormalizeAngleDegrees( ang, 0.0, 360.0 );
203 }
VECTOR2I m_end
Definition: shape_arc.h:142
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:292
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:206

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

Referenced by CheckArcGeom().

◆ GetP0()

const VECTOR2I& SHAPE_ARC::GetP0 ( ) const
inline

Definition at line 69 of file shape_arc.h.

69 { return m_start; }
VECTOR2I m_start
Definition: shape_arc.h:140

References m_start.

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

◆ GetP1()

const VECTOR2I& SHAPE_ARC::GetP1 ( ) const
inline

Definition at line 70 of file shape_arc.h.

70 { return m_end; }
VECTOR2I m_end
Definition: shape_arc.h:142

References m_end.

Referenced by GRID_HELPER::AlignToArc(), PNS::ARC::Anchor(), ARC::ARC(), and CheckArcGeom().

◆ GetRadius()

double SHAPE_ARC::GetRadius ( ) const

Definition at line 225 of file shape_arc.cpp.

226 {
227  return ( m_start - GetCenter() ).EuclideanNorm();
228 }
VECTOR2I m_start
Definition: shape_arc.h:140
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:206

References GetCenter(), and m_start.

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

◆ GetStartAngle()

double SHAPE_ARC::GetStartAngle ( ) const

Definition at line 186 of file shape_arc.cpp.

187 {
188  VECTOR2D d( m_start - GetCenter() );
189 
190  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
191 
192  return NormalizeAngleDegrees( ang, 0.0, 360.0 );
193 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2I m_start
Definition: shape_arc.h:140
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:292
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:206

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

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

◆ GetWidth()

int SHAPE_ARC::GetWidth ( ) const
inline

Definition at line 84 of file shape_arc.h.

85  {
86  return m_width;
87  }
int m_width
Definition: shape_arc.h:144

References m_width.

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

◆ IsSolid()

bool SHAPE_ARC::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 89 of file shape_arc.h.

90  {
91  return true;
92  }

Referenced by CheckArcGeom().

◆ Mirror()

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

Definition at line 294 of file shape_arc.cpp.

295 {
296  if( aX )
297  {
298  m_start.x = -m_start.x + 2 * aVector.x;
299  m_end.x = -m_end.x + 2 * aVector.x;
300  m_mid.x = -m_mid.x + 2 * aVector.x;
301  }
302 
303  if( aY )
304  {
305  m_start.y = -m_start.y + 2 * aVector.y;
306  m_end.y = -m_end.y + 2 * aVector.y;
307  m_mid.y = -m_mid.y + 2 * aVector.y;
308  }
309 
310  update_bbox();
311 }
VECTOR2I m_end
Definition: shape_arc.h:142
VECTOR2I m_mid
Definition: shape_arc.h:141
void update_bbox()
Definition: shape_arc.cpp:106
VECTOR2I m_start
Definition: shape_arc.h:140

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

◆ Move()

void SHAPE_ARC::Move ( const VECTOR2I aVector)
overridevirtual

Implements SHAPE.

Definition at line 267 of file shape_arc.cpp.

268 {
269  m_start += aVector;
270  m_end += aVector;
271  m_mid += aVector;
272  update_bbox();
273 }
VECTOR2I m_end
Definition: shape_arc.h:142
VECTOR2I m_mid
Definition: shape_arc.h:141
void update_bbox()
Definition: shape_arc.cpp:106
VECTOR2I m_start
Definition: shape_arc.h:140

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 }

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

277 {
278  m_start -= aCenter;
279  m_end -= aCenter;
280  m_mid -= aCenter;
281 
282  m_start = m_start.Rotate( aAngle );
283  m_end = m_end.Rotate( aAngle );
284  m_mid = m_mid.Rotate( aAngle );
285 
286  m_start += aCenter;
287  m_end += aCenter;
288  m_mid += aCenter;
289 
290  update_bbox();
291 }
VECTOR2I m_end
Definition: shape_arc.h:142
VECTOR2I m_mid
Definition: shape_arc.h:141
void update_bbox()
Definition: shape_arc.cpp:106
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:377
VECTOR2I m_start
Definition: shape_arc.h:140

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

◆ SetWidth()

void SHAPE_ARC::SetWidth ( int  aWidth)
inline

Definition at line 79 of file shape_arc.h.

80  {
81  m_width = aWidth;
82  }
int m_width
Definition: shape_arc.h:144

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

100  {
101  return m_type;
102  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:195

References SHAPE::m_type.

Referenced by PNS::DP_GATEWAYS::BuildFromPrimitivePair(), collideShapes(), collideSingleShapes(), PNS::OPTIMIZER::computeBreakouts(), PNS::SOLID::Hull(), ROUTER_PREVIEW_ITEM::ViewDraw(), and SHAPE_FILE_IO::Write().

◆ update_bbox()

void SHAPE_ARC::update_bbox ( )
private

Definition at line 106 of file shape_arc.cpp.

107 {
108  std::vector<VECTOR2I> points;
109  // Put start and end points in the point list
110  points.push_back( m_start );
111  points.push_back( m_end );
112 
113  double start_angle = GetStartAngle();
114  double end_angle = start_angle + GetCentralAngle();
115 
116  // we always count quadrants clockwise (increasing angle)
117  if( start_angle > end_angle )
118  std::swap( start_angle, end_angle );
119 
120  int quad_angle_start = std::ceil( start_angle / 90.0 );
121  int quad_angle_end = std::floor( end_angle / 90.0 );
122 
123  // count through quadrants included in arc
124  for( int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle )
125  {
126  const int radius = KiROUND( GetRadius() );
127  VECTOR2I quad_pt = GetCenter();
128 
129  switch( quad_angle % 4 )
130  {
131  case 0: quad_pt += { radius, 0 }; break;
132  case 1:
133  case -3: quad_pt += { 0, radius }; break;
134  case 2:
135  case -2: quad_pt += { -radius, 0 }; break;
136  case 3:
137  case -1: quad_pt += { 0, -radius }; break;
138  default: assert( false );
139  }
140 
141  points.push_back( quad_pt );
142  }
143 
144  m_bbox.Compute( points );
145 }
double GetRadius() const
Definition: shape_arc.cpp:225
VECTOR2I m_end
Definition: shape_arc.h:142
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:91
double GetStartAngle() const
Definition: shape_arc.cpp:186
VECTOR2I m_start
Definition: shape_arc.h:140
double GetCentralAngle() const
Definition: shape_arc.cpp:212
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:145
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:206

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

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

Member Data Documentation

◆ m_bbox

BOX2I SHAPE_ARC::m_bbox
private

Definition at line 145 of file shape_arc.h.

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

◆ m_end

VECTOR2I SHAPE_ARC::m_end
private

◆ m_mid

VECTOR2I SHAPE_ARC::m_mid
private

Definition at line 141 of file shape_arc.h.

Referenced by GetArcMid(), GetCenter(), GetCentralAngle(), Mirror(), Move(), Rotate(), and SHAPE_ARC().

◆ m_start

VECTOR2I SHAPE_ARC::m_start
private

◆ m_type

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 195 of file shape.h.

Referenced by SHAPE::Type().

◆ m_width

int SHAPE_ARC::m_width
private

Definition at line 144 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: