KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2024 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#pragma once
27
28#include <core/mirror.h> // for FLIP_DIRECTION
29#include <geometry/shape.h>
30#include <base_units.h>
31#include <math/vector2d.h> // for VECTOR2I
32#include <geometry/eda_angle.h>
33
34class CIRCLE;
36
37class SHAPE_ARC : public SHAPE
38{
39public:
40
42 SHAPE( SH_ARC ),
43 m_width( 0 ),
44 m_radius( 0 )
45 {};
46
58 SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint,
59 const EDA_ANGLE& aCenterAngle, int aWidth = 0 );
60
67 SHAPE_ARC( const VECTOR2I& aArcStart, const VECTOR2I& aArcMid, const VECTOR2I& aArcEnd,
68 int aWidth );
69
78 SHAPE_ARC( const SEG& aSegmentA, const SEG& aSegmentB, int aRadius, int aWidth = 0 );
79
80 SHAPE_ARC( const SHAPE_ARC& aOther );
81
82 virtual ~SHAPE_ARC() {}
83
84 SHAPE* Clone() const override
85 {
86 return new SHAPE_ARC( *this );
87 }
88
98 SHAPE_ARC& ConstructFromStartEndAngle( const VECTOR2I& aStart, const VECTOR2I& aEnd,
99 const EDA_ANGLE& aAngle, double aWidth = 0 );
100
110 SHAPE_ARC& ConstructFromStartEndCenter( const VECTOR2I& aStart, const VECTOR2I& aEnd,
111 const VECTOR2I& aCenter, bool aClockwise = false,
112 double aWidth = 0 );
113
114 const VECTOR2I& GetP0() const { return m_start; }
115 const VECTOR2I& GetP1() const { return m_end; }
116 const VECTOR2I& GetArcMid() const { return m_mid; }
117 const VECTOR2I& GetCenter() const;
118
119 const BOX2I BBox( int aClearance = 0 ) const override;
120
121 VECTOR2I NearestPoint( const VECTOR2I& aP ) const;
122
123 bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
124 VECTOR2I* aLocation = nullptr ) const override;
125 bool Collide( const VECTOR2I& aP, int aClearance = 0, int* aActual = nullptr,
126 VECTOR2I* aLocation = nullptr ) const override;
127
128
129 bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr,
130 VECTOR2I* aLocation = nullptr ) const override
131 {
132 return SHAPE::Collide( aShape, aClearance, aActual, aLocation );
133 }
134
143 int IntersectLine( const SEG& aSeg, std::vector<VECTOR2I>* aIpsBuffer ) const;
144
152 int Intersect( const CIRCLE& aArc, std::vector<VECTOR2I>* aIpsBuffer ) const;
153
161 int Intersect( const SHAPE_ARC& aArc, std::vector<VECTOR2I>* aIpsBuffer ) const;
162
163 void SetWidth( int aWidth )
164 {
165 m_width = aWidth;
166 }
167
168 int GetWidth() const
169 {
170 return m_width;
171 }
172
173 bool IsSolid() const override
174 {
175 return true;
176 }
177
178 void Move( const VECTOR2I& aVector ) override;
179
186 void Rotate( const EDA_ANGLE& aAngle, const VECTOR2I& aCenter ) override;
187
188 void Mirror( const VECTOR2I& aRef, FLIP_DIRECTION aFlipDirection );
189
190 void Mirror( const SEG& axis );
191
192 void Reverse();
193
194 SHAPE_ARC Reversed() const;
195
196 double GetRadius() const;
197
198 SEG GetChord() const
199 {
200 return SEG( m_start, m_end );
201 }
202
207
211 EDA_ANGLE GetStartAngle() const;
212
216 EDA_ANGLE GetEndAngle() const;
217
221 double GetLength() const;
222
232 static double DefaultAccuracyForPCB(){ return 0.005 * PCB_IU_PER_MM; }
233
249 const SHAPE_LINE_CHAIN ConvertToPolyline( double aAccuracy = DefaultAccuracyForPCB(),
250 double* aEffectiveAccuracy = nullptr ) const;
251
252 bool operator==( SHAPE_ARC const& aArc ) const
253 {
254 return ( aArc.m_start == m_start ) && ( aArc.m_end == m_end ) && ( aArc.m_mid == m_mid )
255 && ( aArc.m_width == m_width );
256 }
257
258 void TransformToPolygon( SHAPE_POLY_SET& aBuffer, int aError,
259 ERROR_LOC aErrorLoc ) const override;
260
264 bool IsCCW() const
265 {
266 VECTOR2L mid = m_mid;
267 VECTOR2L v1 = m_end - mid;
268 VECTOR2L v2 = m_start - mid;
269
270 return v1.Cross( v2 ) > 0;
271 }
272
273 bool IsClockwise() const { return !IsCCW(); }
274
275private:
276 void update_values();
277
278 bool sliceContainsPoint( const VECTOR2I& p ) const;
279
280private:
285
286 BOX2I m_bbox; // Calculated value
287 VECTOR2I m_center; // Calculated value
288 double m_radius; // Calculated value
289};
290
291// Required for Boost Test BOOST_CHECK_EQUAL:
292std::ostream& operator<<( std::ostream& aStream, const SHAPE_ARC& aArc );
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
Definition: approximation.h:32
constexpr double PCB_IU_PER_MM
Definition: base_units.h:70
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:33
Definition: seg.h:42
EDA_ANGLE GetCentralAngle() const
Definition: shape_arc.cpp:538
double m_radius
Definition: shape_arc.h:288
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:116
void update_values()
Definition: shape_arc.cpp:353
SEG GetChord() const
Definition: shape_arc.h:198
bool IsClockwise() const
Definition: shape_arc.h:273
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Definition: shape_arc.h:129
void Move(const VECTOR2I &aVector) override
Definition: shape_arc.cpp:626
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:194
virtual ~SHAPE_ARC()
Definition: shape_arc.h:82
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:403
EDA_ANGLE GetEndAngle() const
Definition: shape_arc.cpp:515
bool IsCCW() const
Definition: shape_arc.h:264
double GetLength() const
Definition: shape_arc.cpp:529
BOX2I m_bbox
Definition: shape_arc.h:286
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter) override
Rotate the arc by a given angle about a point.
Definition: shape_arc.cpp:635
bool sliceContainsPoint(const VECTOR2I &p) const
Definition: shape_arc.cpp:686
VECTOR2I NearestPoint(const VECTOR2I &aP) const
Definition: shape_arc.cpp:417
SHAPE_ARC()
Definition: shape_arc.h:41
int Intersect(const CIRCLE &aArc, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and a CIRCLE.
Definition: shape_arc.cpp:316
int GetWidth() const
Definition: shape_arc.h:168
void SetWidth(int aWidth)
Definition: shape_arc.h:163
VECTOR2I m_mid
Definition: shape_arc.h:282
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:212
void Mirror(const VECTOR2I &aRef, FLIP_DIRECTION aFlipDirection)
Definition: shape_arc.cpp:645
SHAPE_ARC Reversed() const
Definition: shape_arc.cpp:680
VECTOR2I m_center
Definition: shape_arc.h:287
int m_width
Definition: shape_arc.h:284
const VECTOR2I & GetP1() const
Definition: shape_arc.h:115
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:295
VECTOR2I m_end
Definition: shape_arc.h:283
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:244
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:560
double GetRadius() const
Definition: shape_arc.cpp:554
EDA_ANGLE GetStartAngle() const
Definition: shape_arc.cpp:507
void TransformToPolygon(SHAPE_POLY_SET &aBuffer, int aError, ERROR_LOC aErrorLoc) const override
Fills a SHAPE_POLY_SET with a polygon representation of this shape.
Definition: shape_arc.cpp:712
static double DefaultAccuracyForPCB()
Definition: shape_arc.h:232
bool operator==(SHAPE_ARC const &aArc) const
Definition: shape_arc.h:252
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
Definition: shape_arc.h:84
void Reverse()
Definition: shape_arc.cpp:674
const VECTOR2I & GetP0() const
Definition: shape_arc.h:114
VECTOR2I m_start
Definition: shape_arc.h:281
bool IsSolid() const override
Definition: shape_arc.h:173
const VECTOR2I & GetCenter() const
Definition: shape_arc.cpp:523
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
An abstract shape on 2D plane.
Definition: shape.h:126
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:181
VECTOR3< T > Cross(const VECTOR3< T > &aVector) const
Compute cross product of self with aVector.
Definition: vector3.h:129
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
Definition: eda_text.cpp:1195
FLIP_DIRECTION
Definition: mirror.h:27
@ SH_ARC
circular arc
Definition: shape.h:54
VECTOR3I v1(5, 5, 5)
VECTOR2I v2(1, 0)