KiCad PCB EDA Suite
shape_arc.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018 CERN
5  * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef __SHAPE_ARC_H
27 #define __SHAPE_ARC_H
28 
29 #include <geometry/shape.h>
30 #include <convert_to_biu.h>
31 #include <math/vector2d.h> // for VECTOR2I
32 
33 class SHAPE_LINE_CHAIN;
34 
35 class SHAPE_ARC : public SHAPE
36 {
37 public:
38 
40  SHAPE( SH_ARC ),
41  m_width( 0 )
42  {};
43 
52  SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint, double aCenterAngle,
53  int aWidth = 0 );
54 
62  SHAPE_ARC( const VECTOR2I& aArcStart, const VECTOR2I& aArcMid, const VECTOR2I& aArcEnd,
63  int aWidth );
64 
73  SHAPE_ARC( const SEG& aSegmentA, const SEG& aSegmentB, int aRadius, int aWidth = 0 );
74 
75  SHAPE_ARC( const SHAPE_ARC& aOther );
76 
77  virtual ~SHAPE_ARC() {}
78 
79  SHAPE* Clone() const override
80  {
81  return new SHAPE_ARC( *this );
82  }
83 
92  SHAPE_ARC& ConstructFromStartEndAngle( const VECTOR2I& aStart, const VECTOR2I& aEnd,
93  double aAngle, double aWidth = 0 );
94 
95  const VECTOR2I& GetP0() const { return m_start; }
96  const VECTOR2I& GetP1() const { return m_end; }
97  const VECTOR2I& GetArcMid() const { return m_mid; }
98  VECTOR2I GetCenter() const;
99 
100  const BOX2I BBox( int aClearance = 0 ) const override;
101 
102  bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
103  VECTOR2I* aLocation = nullptr ) const override;
104  bool Collide( const VECTOR2I& aP, int aClearance = 0, int* aActual = nullptr,
105  VECTOR2I* aLocation = nullptr ) const override;
106 
107  void SetWidth( int aWidth )
108  {
109  m_width = aWidth;
110  }
111 
112  int GetWidth() const
113  {
114  return m_width;
115  }
116 
117  bool IsSolid() const override
118  {
119  return true;
120  }
121 
122  void Move( const VECTOR2I& aVector ) override;
123 
130  void Rotate( double aAngle, const VECTOR2I& aCenter ) override;
131 
132  void Mirror( bool aX = true, bool aY = false, const VECTOR2I& aVector = { 0, 0 } );
133 
134  void Mirror( const SEG& axis );
135 
136  void Reverse();
137 
138  SHAPE_ARC Reversed() const;
139 
140  double GetRadius() const;
141 
142  SEG GetChord() const
143  {
144  return SEG( m_start, m_end );
145  }
146 
147  double GetCentralAngle() const;
148  double GetStartAngle() const;
149  double GetEndAngle() const;
150 
154  double GetLength() const;
155 
166  const SHAPE_LINE_CHAIN ConvertToPolyline( double aAccuracy = 0.005 * PCB_IU_PER_MM ) const;
167 
168 private:
169  bool ccw( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC ) const
170  {
171  return ( ecoord{ aC.y } - aA.y ) * ( ecoord{ aB.x } - aA.x ) >
172  ( ecoord{ aB.y } - aA.y ) * ( ecoord{ aC.x } - aA.x );
173  }
174 
175  void update_bbox();
176 
177 private:
181 
182  int m_width;
184 };
185 
186 #endif
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aVector={ 0, 0 })
Definition: shape_arc.cpp:486
void Rotate(double aAngle, const VECTOR2I &aCenter) override
Function Rotate rotates the arc by a given angle about a point.
Definition: shape_arc.cpp:468
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
double GetRadius() const
Definition: shape_arc.cpp:411
VECTOR2I m_end
Definition: shape_arc.h:180
Define a general 2D-vector/point.
Definition: vector2d.h:61
SHAPE_ARC & ConstructFromStartEndAngle(const VECTOR2I &aStart, const VECTOR2I &aEnd, double aAngle, double aWidth=0)
Constructs this arc from the given start, end and angle.
Definition: shape_arc.cpp:173
bool ccw(const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
Definition: shape_arc.h:169
double GetStartAngle() const
Definition: shape_arc.cpp:363
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
VECTOR2I m_mid
Definition: shape_arc.h:179
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.
Definition: shape_arc.cpp:417
constexpr double PCB_IU_PER_MM
const VECTOR2I & GetP0() const
Definition: shape_arc.h:95
virtual ~SHAPE_ARC()
Definition: shape_arc.h:77
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:97
SEG GetChord() const
Definition: shape_arc.h:142
circular arc
Definition: shape.h:50
An abstract shape on 2D plane.
Definition: shape.h:116
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
Definition: shape_arc.h:79
double GetEndAngle() const
Definition: shape_arc.cpp:373
void update_bbox()
Definition: shape_arc.cpp:263
void Reverse()
Definition: shape_arc.cpp:516
Definition: seg.h:41
void Move(const VECTOR2I &aVector) override
Definition: shape_arc.cpp:459
int GetWidth() const
Definition: shape_arc.h:112
bool IsSolid() const override
Definition: shape_arc.h:117
VECTOR2I::extended_type ecoord
Definition: shape.h:236
SHAPE_LINE_CHAIN.
VECTOR2I m_start
Definition: shape_arc.h:178
double GetCentralAngle() const
Definition: shape_arc.cpp:398
SHAPE_ARC()
Definition: shape_arc.h:39
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
SHAPE_ARC Reversed() const
Definition: shape_arc.cpp:522
void SetWidth(int aWidth)
Definition: shape_arc.h:107
double GetLength() const
Definition: shape_arc.cpp:389
int m_width
Definition: shape_arc.h:182
BOX2I m_bbox
Definition: shape_arc.h:183
const VECTOR2I & GetP1() const
Definition: shape_arc.h:96
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:383