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:
38  SHAPE( SH_ARC ), m_width( 0 ) {};
39 
47  SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint,
48  double aCenterAngle, int aWidth = 0 );
49 
57  SHAPE_ARC( const VECTOR2I& aArcStart, const VECTOR2I& aArcMid,
58  const VECTOR2I& aArcEnd, int aWidth );
59 
60  SHAPE_ARC( const SHAPE_ARC& aOther );
61 
62  virtual ~SHAPE_ARC() {}
63 
64  SHAPE* Clone() const override
65  {
66  return new SHAPE_ARC( *this );
67  }
68 
69  const VECTOR2I& GetP0() const { return m_start; }
70  const VECTOR2I& GetP1() const { return m_end; }
71  const VECTOR2I& GetArcMid() const { return m_mid; }
72  VECTOR2I GetCenter() const;
73 
74  const BOX2I BBox( int aClearance = 0 ) const override;
75 
76  bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr ) const override;
77  bool Collide( const VECTOR2I& aP, int aClearance = 0, int* aActual = nullptr ) const override;
78 
79  void SetWidth( int aWidth )
80  {
81  m_width = aWidth;
82  }
83 
84  int GetWidth() const
85  {
86  return m_width;
87  }
88 
89  bool IsSolid() const override
90  {
91  return true;
92  }
93 
94  void Move( const VECTOR2I& aVector ) override;
95 
102  void Rotate( double aAngle, const VECTOR2I& aCenter ) override;
103 
104  void Mirror( bool aX = true, bool aY = false, const VECTOR2I& aVector = { 0, 0 } );
105 
106  double GetRadius() const;
107 
108  SEG GetChord() const
109  {
110  return SEG( m_start, m_end );
111  }
112 
113  double GetCentralAngle() const;
114  double GetStartAngle() const;
115  double GetEndAngle() const;
116 
127  const SHAPE_LINE_CHAIN ConvertToPolyline( double aAccuracy = 500.0 ) const;
128 
129 private:
130 
131  bool ccw( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC ) const
132  {
133  return (ecoord) ( aC.y - aA.y ) * ( aB.x - aA.x ) >
134  (ecoord) ( aB.y - aA.y ) * ( aC.x - aA.x );
135  }
136 
137  void update_bbox();
138 
139 
143 
144  int m_width;
146 };
147 
148 #endif
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aVector={ 0, 0 })
Definition: shape_arc.cpp:294
void Rotate(double aAngle, const VECTOR2I &aCenter) override
Function Rotate rotates the arc by a given angle about a point.
Definition: shape_arc.cpp:276
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
bool ccw(const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
Definition: shape_arc.h:131
double GetStartAngle() const
Definition: shape_arc.cpp:186
VECTOR2I m_mid
Definition: shape_arc.h:141
const VECTOR2I & GetP0() const
Definition: shape_arc.h:69
virtual ~SHAPE_ARC()
Definition: shape_arc.h:62
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:71
SEG GetChord() const
Definition: shape_arc.h:108
compound shape, consisting of multiple simple shapes
Definition: shape.h:48
SHAPE.
Definition: shape.h:74
SHAPE * Clone() const override
Function Clone()
Definition: shape_arc.h:64
double GetEndAngle() const
Definition: shape_arc.cpp:196
void update_bbox()
Definition: shape_arc.cpp:106
Definition: seg.h:39
void Move(const VECTOR2I &aVector) override
Definition: shape_arc.cpp:267
int GetWidth() const
Definition: shape_arc.h:84
bool IsSolid() const override
Definition: shape_arc.h:89
VECTOR2I::extended_type ecoord
Definition: shape.h:77
SHAPE_LINE_CHAIN.
VECTOR2I m_start
Definition: shape_arc.h:140
double GetCentralAngle() const
Definition: shape_arc.cpp:212
SHAPE_ARC()
Definition: shape_arc.h:37
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_arc.cpp:148
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr) const override
Function Collide()
Definition: shape_arc.cpp:68
void SetWidth(int aWidth)
Definition: shape_arc.h:79
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:231
int m_width
Definition: shape_arc.h:144
BOX2I m_bbox
Definition: shape_arc.h:145
const VECTOR2I & GetP1() const
Definition: shape_arc.h:70
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:206