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  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef __SHAPE_ARC_H
26 #define __SHAPE_ARC_H
27 
28 #include <geometry/seg.h>
29 #include <geometry/shape.h>
30 #include <math/box2.h> // for BOX2I
31 #include <math/vector2d.h> // for VECTOR2I
32 
33 class SHAPE_LINE_CHAIN;
34 
35 class SHAPE_ARC : public SHAPE
36 {
37 public:
39  SHAPE( SH_ARC ), m_centralAngle( 0.0 ), m_width( 0 ) {};
40 
48  SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint,
49  double aCenterAngle, int aWidth = 0 ) :
50  SHAPE( SH_ARC ), m_p0( aArcStartPoint ), m_pc( aArcCenter ), m_centralAngle( aCenterAngle ),
51  m_width( aWidth )
52  {
53  }
54 
55  SHAPE_ARC( const SHAPE_ARC& aOther )
56  : SHAPE( SH_ARC )
57  {
58  m_p0 = aOther.m_p0;
59  m_pc = aOther.m_pc;
61  m_width = aOther.m_width;
62  }
63 
65 
66  SHAPE* Clone() const override
67  {
68  return new SHAPE_ARC( *this );
69  }
70 
71  const VECTOR2I& GetP0() const { return m_p0; }
72  const VECTOR2I GetP1() const;
73  const VECTOR2I& GetCenter() const { return m_pc; }
74 
75  const BOX2I BBox( int aClearance = 0 ) const override;
76 
77  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override;
78  bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override;
79 
80  void SetWidth( int aWidth )
81  {
82  m_width = aWidth;
83  }
84 
85  int GetWidth() const
86  {
87  return m_width;
88  }
89 
90  bool IsSolid() const override
91  {
92  return true;
93  }
94 
95  void Move( const VECTOR2I& aVector ) override
96  {
97  m_p0 += aVector;
98  m_pc += aVector;
99  }
100 
101  int GetRadius() const;
102 
103  SEG GetChord() const
104  {
105  return SEG( m_p0, GetP1() );
106  }
107 
108  double GetCentralAngle() const;
109  double GetStartAngle() const;
110  double GetEndAngle() const;
111 
112 /*
113  bool ConstructFromCorners( VECTOR2I aP0, VECTOR2I aP1, double aCenterAngle );
114  bool ConstructFromCircle( VECTOR2I aP0, double aRadius );
115 
116  bool ConstructFromCenterAndAngles( VECTOR2I aCenter, double aRadius, double aStartAngle, double aCenterAngle );
117 
118  bool ConstructFromCornerAndAngles( VECTOR2I aP0,
119  double aStartAngle,
120  double aCenterAngle,
121  double aRadius );
122 */
123 
134  const SHAPE_LINE_CHAIN ConvertToPolyline( double aAccuracy = 500.0 ) const;
135 
136 private:
137 
138  bool ccw( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC ) const
139  {
140  return (ecoord) ( aC.y - aA.y ) * ( aB.x - aA.x ) >
141  (ecoord) ( aB.y - aA.y ) * ( aC.x - aA.x );
142  }
143 
144 
147 
148  int m_width;
149 };
150 
151 #endif
bool ccw(const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
Definition: shape_arc.h:138
double GetStartAngle() const
Definition: shape_arc.cpp:216
int GetRadius() const
Definition: shape_arc.cpp:242
SHAPE_ARC(const VECTOR2I &aArcCenter, const VECTOR2I &aArcStartPoint, double aCenterAngle, int aWidth=0)
SHAPE_ARC ctor.
Definition: shape_arc.h:48
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_arc.cpp:38
const VECTOR2I & GetP0() const
Definition: shape_arc.h:71
VECTOR2I m_p0
Definition: shape_arc.h:145
const VECTOR2I & GetCenter() const
Definition: shape_arc.h:73
SEG GetChord() const
Definition: shape_arc.h:103
compound shape, consisting of multiple simple shapes
Definition: shape.h:52
const VECTOR2I GetP1() const
Definition: shape_arc.cpp:147
SHAPE.
Definition: shape.h:60
SHAPE * Clone() const override
Function Clone()
Definition: shape_arc.h:66
double GetEndAngle() const
Definition: shape_arc.cpp:225
Definition: seg.h:39
void Move(const VECTOR2I &aVector) override
Definition: shape_arc.h:95
int GetWidth() const
Definition: shape_arc.h:85
bool IsSolid() const override
Definition: shape_arc.h:90
SHAPE_ARC(const SHAPE_ARC &aOther)
Definition: shape_arc.h:55
VECTOR2I::extended_type ecoord
Definition: shape.h:63
SHAPE_LINE_CHAIN.
~SHAPE_ARC()
Definition: shape_arc.h:64
double GetCentralAngle() const
Definition: shape_arc.cpp:237
SHAPE_ARC()
Definition: shape_arc.h:38
VECTOR2I m_pc
Definition: shape_arc.h:145
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_arc.cpp:160
void SetWidth(int aWidth)
Definition: shape_arc.h:80
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:247
int m_width
Definition: shape_arc.h:148
double m_centralAngle
Definition: shape_arc.h:146