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 <math/vector2d.h> // for VECTOR2I
31 
32 class SHAPE_LINE_CHAIN;
33 
34 class SHAPE_ARC : public SHAPE
35 {
36 public:
40  static const int MIN_PRECISION_IU = 4;
41 
43  SHAPE( SH_ARC ), m_width( 0 ) {};
44 
52  SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint,
53  double aCenterAngle, int aWidth = 0 );
54 
62  SHAPE_ARC( const VECTOR2I& aArcStart, const VECTOR2I& aArcMid,
63  const VECTOR2I& aArcEnd, 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 
84  const VECTOR2I& GetP0() const { return m_start; }
85  const VECTOR2I& GetP1() const { return m_end; }
86  const VECTOR2I& GetArcMid() const { return m_mid; }
87  VECTOR2I GetCenter() const;
88 
89  const BOX2I BBox( int aClearance = 0 ) const override;
90 
91  bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
92  VECTOR2I* aLocation = nullptr ) const override;
93  bool Collide( const VECTOR2I& aP, int aClearance = 0, int* aActual = nullptr,
94  VECTOR2I* aLocation = nullptr ) const override;
95 
96  void SetWidth( int aWidth )
97  {
98  m_width = aWidth;
99  }
100 
101  int GetWidth() const
102  {
103  return m_width;
104  }
105 
106  bool IsSolid() const override
107  {
108  return true;
109  }
110 
111  void Move( const VECTOR2I& aVector ) override;
112 
119  void Rotate( double aAngle, const VECTOR2I& aCenter ) override;
120 
121  void Mirror( bool aX = true, bool aY = false, const VECTOR2I& aVector = { 0, 0 } );
122 
123  double GetRadius() const;
124 
125  SEG GetChord() const
126  {
127  return SEG( m_start, m_end );
128  }
129 
130  double GetCentralAngle() const;
131  double GetStartAngle() const;
132  double GetEndAngle() const;
133 
144  const SHAPE_LINE_CHAIN ConvertToPolyline( double aAccuracy = 500.0 ) const;
145 
146 private:
147 
148  bool ccw( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC ) const
149  {
150  return ( ecoord{ aC.y } - aA.y ) * ( ecoord{ aB.x } - aA.x ) >
151  ( ecoord{ aB.y } - aA.y ) * ( ecoord{ aC.x } - aA.x );
152  }
153 
154  void update_bbox();
155 
156 
160 
161  int m_width;
163 };
164 
165 #endif
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aVector={ 0, 0 })
Definition: shape_arc.cpp:431
void Rotate(double aAngle, const VECTOR2I &aCenter) override
Function Rotate rotates the arc by a given angle about a point.
Definition: shape_arc.cpp:413
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Function Collide()
Definition: shape_arc.cpp:171
double GetRadius() const
Definition: shape_arc.cpp:362
VECTOR2I m_end
Definition: shape_arc.h:159
VECTOR2 defines 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:148
double GetStartAngle() const
Definition: shape_arc.cpp:323
VECTOR2I m_mid
Definition: shape_arc.h:158
const VECTOR2I & GetP0() const
Definition: shape_arc.h:84
virtual ~SHAPE_ARC()
Definition: shape_arc.h:77
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:86
static const int MIN_PRECISION_IU
This is the minimum precision for all the points in the arc shape.
Definition: shape_arc.h:40
SEG GetChord() const
Definition: shape_arc.h:125
compound shape, consisting of multiple simple shapes
Definition: shape.h:50
SHAPE.
Definition: shape.h:122
SHAPE * Clone() const override
Function Clone()
Definition: shape_arc.h:79
double GetEndAngle() const
Definition: shape_arc.cpp:333
void update_bbox()
Definition: shape_arc.cpp:240
Definition: seg.h:39
void Move(const VECTOR2I &aVector) override
Definition: shape_arc.cpp:404
int GetWidth() const
Definition: shape_arc.h:101
bool IsSolid() const override
Definition: shape_arc.h:106
VECTOR2I::extended_type ecoord
Definition: shape.h:125
SHAPE_LINE_CHAIN.
VECTOR2I m_start
Definition: shape_arc.h:157
double GetCentralAngle() const
Definition: shape_arc.cpp:349
SHAPE_ARC()
Definition: shape_arc.h:42
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_arc.cpp:282
void SetWidth(int aWidth)
Definition: shape_arc.h:96
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=500.0) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:368
int m_width
Definition: shape_arc.h:161
BOX2I m_bbox
Definition: shape_arc.h:162
const VECTOR2I & GetP1() const
Definition: shape_arc.h:85
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:343