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-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
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 <base_units.h>
31#include <math/vector2d.h> // for VECTOR2I
32#include <geometry/eda_angle.h>
33
35
36class SHAPE_ARC : public SHAPE
37{
38public:
39
41 SHAPE( SH_ARC ),
42 m_width( 0 )
43 {};
44
56 SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint,
57 const EDA_ANGLE& aCenterAngle, int aWidth = 0 );
58
65 SHAPE_ARC( const VECTOR2I& aArcStart, const VECTOR2I& aArcMid, const VECTOR2I& aArcEnd,
66 int aWidth );
67
76 SHAPE_ARC( const SEG& aSegmentA, const SEG& aSegmentB, int aRadius, int aWidth = 0 );
77
78 SHAPE_ARC( const SHAPE_ARC& aOther );
79
80 virtual ~SHAPE_ARC() {}
81
82 SHAPE* Clone() const override
83 {
84 return new SHAPE_ARC( *this );
85 }
86
96 SHAPE_ARC& ConstructFromStartEndAngle( const VECTOR2I& aStart, const VECTOR2I& aEnd,
97 const EDA_ANGLE& aAngle, double aWidth = 0 );
98
108 SHAPE_ARC& ConstructFromStartEndCenter( const VECTOR2I& aStart, const VECTOR2I& aEnd,
109 const VECTOR2I& aCenter, bool aClockwise = false,
110 double aWidth = 0 );
111
112 const VECTOR2I& GetP0() const { return m_start; }
113 const VECTOR2I& GetP1() const { return m_end; }
114 const VECTOR2I& GetArcMid() const { return m_mid; }
115 VECTOR2I GetCenter() const;
116
117 const BOX2I BBox( int aClearance = 0 ) const override;
118
119 bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
120 VECTOR2I* aLocation = nullptr ) const override;
121 bool Collide( const VECTOR2I& aP, int aClearance = 0, int* aActual = nullptr,
122 VECTOR2I* aLocation = nullptr ) const override;
123
124
125 bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr,
126 VECTOR2I* aLocation = nullptr ) const override
127 {
128 return SHAPE::Collide( aShape, aClearance, aActual, aLocation );
129 }
130
139 int IntersectLine( const SEG& aSeg, std::vector<VECTOR2I>* aIpsBuffer ) const;
140
148 int Intersect( const SHAPE_ARC& aArc, std::vector<VECTOR2I>* aIpsBuffer ) const;
149
150 bool IsClockwise() const;
151
152 void SetWidth( int aWidth )
153 {
154 m_width = aWidth;
155 }
156
157 int GetWidth() const
158 {
159 return m_width;
160 }
161
162 bool IsSolid() const override
163 {
164 return true;
165 }
166
167 void Move( const VECTOR2I& aVector ) override;
168
175 void Rotate( const EDA_ANGLE& aAngle, const VECTOR2I& aCenter ) override;
176
177 void Mirror( bool aX = true, bool aY = false, const VECTOR2I& aVector = { 0, 0 } );
178
179 void Mirror( const SEG& axis );
180
181 void Reverse();
182
183 SHAPE_ARC Reversed() const;
184
185 double GetRadius() const;
186
187 SEG GetChord() const
188 {
189 return SEG( m_start, m_end );
190 }
191
196
200 EDA_ANGLE GetStartAngle() const;
201
205 EDA_ANGLE GetEndAngle() const;
206
210 double GetLength() const;
211
221 static double DefaultAccuracyForPCB(){ return 0.005 * PCB_IU_PER_MM; }
222
238 const SHAPE_LINE_CHAIN ConvertToPolyline( double aAccuracy = DefaultAccuracyForPCB(),
239 double* aEffectiveAccuracy = nullptr ) const;
240
241 bool operator==( SHAPE_ARC const& aArc ) const
242 {
243 return ( aArc.m_start == m_start ) && ( aArc.m_end == m_end ) && ( aArc.m_mid == m_mid )
244 && ( aArc.m_width == m_width );
245 }
246
247private:
248 bool ccw( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC ) const
249 {
250 return ( ecoord{ aC.y } - aA.y ) * ( ecoord{ aB.x } - aA.x ) >
251 ( ecoord{ aB.y } - aA.y ) * ( ecoord{ aC.x } - aA.x );
252 }
253
254 void update_bbox();
255
256 bool sliceContainsPoint( const VECTOR2I& p ) const;
257
258private:
262
265};
266
267// Required for Boost Test BOOST_CHECK_EQUAL:
268std::ostream& operator<<( std::ostream& aStream, const SHAPE_ARC& aArc );
269
270#endif
constexpr double PCB_IU_PER_MM
Definition: base_units.h:71
Definition: seg.h:42
EDA_ANGLE GetCentralAngle() const
Definition: shape_arc.cpp:445
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:114
SEG GetChord() const
Definition: shape_arc.h:187
bool IsClockwise() const
Definition: shape_arc.cpp:363
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Definition: shape_arc.h:125
void Move(const VECTOR2I &aVector) override
Definition: shape_arc.cpp:523
SHAPE_ARC & ConstructFromStartEndAngle(const VECTOR2I &aStart, const VECTOR2I &aEnd, const EDA_ANGLE &aAngle, double aWidth=0)
Construct this arc from the given start, end and angle.
Definition: shape_arc.cpp:191
virtual ~SHAPE_ARC()
Definition: shape_arc.h:80
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:352
EDA_ANGLE GetEndAngle() const
Definition: shape_arc.cpp:423
double GetLength() const
Definition: shape_arc.cpp:436
BOX2I m_bbox
Definition: shape_arc.h:264
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter) override
Rotate the arc by a given angle about a point.
Definition: shape_arc.cpp:532
bool sliceContainsPoint(const VECTOR2I &p) const
Definition: shape_arc.cpp:584
SHAPE_ARC()
Definition: shape_arc.h:40
int GetWidth() const
Definition: shape_arc.h:157
void SetWidth(int aWidth)
Definition: shape_arc.h:152
VECTOR2I m_mid
Definition: shape_arc.h:260
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Definition: shape_arc.cpp:209
SHAPE_ARC Reversed() const
Definition: shape_arc.cpp:578
int m_width
Definition: shape_arc.h:263
const VECTOR2I & GetP1() const
Definition: shape_arc.h:113
int IntersectLine(const SEG &aSeg, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aSeg, treating aSeg as an infinite line.
Definition: shape_arc.cpp:273
VECTOR2I m_end
Definition: shape_arc.h:261
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:241
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=DefaultAccuracyForPCB(), double *aEffectiveAccuracy=nullptr) const
Construct a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:461
int Intersect(const SHAPE_ARC &aArc, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aArc.
Definition: shape_arc.cpp:291
double GetRadius() const
Definition: shape_arc.cpp:455
EDA_ANGLE GetStartAngle() const
Definition: shape_arc.cpp:416
void update_bbox()
Definition: shape_arc.cpp:310
static double DefaultAccuracyForPCB()
Definition: shape_arc.h:221
bool operator==(SHAPE_ARC const &aArc) const
Definition: shape_arc.h:241
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
Definition: shape_arc.h:82
void Reverse()
Definition: shape_arc.cpp:572
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:430
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aVector={ 0, 0 })
Definition: shape_arc.cpp:542
bool ccw(const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
Definition: shape_arc.h:248
const VECTOR2I & GetP0() const
Definition: shape_arc.h:112
VECTOR2I m_start
Definition: shape_arc.h:259
bool IsSolid() const override
Definition: shape_arc.h:162
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
An abstract shape on 2D plane.
Definition: shape.h:123
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition: shape.h:178
VECTOR2I::extended_type ecoord
Definition: shape.h:249
@ SH_ARC
circular arc
Definition: shape.h:51
std::ostream & operator<<(std::ostream &aStream, const SHAPE_ARC &aArc)
Definition: shape_arc.cpp:35