Horizon
Loading...
Searching...
No Matches
shape_arc.h
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-2021 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 <convert_to_biu.h>
31#include <math/vector2d.h> // for VECTOR2I
32
34
35class SHAPE_ARC : public SHAPE
36{
37public:
38
39 SHAPE_ARC() :
40 SHAPE( SH_ARC ),
41 m_width( 0 )
42 {};
43
55 SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint, double aCenterAngle,
56 int aWidth = 0 );
57
64 SHAPE_ARC( const VECTOR2I& aArcStart, const VECTOR2I& aArcMid, const VECTOR2I& aArcEnd,
65 int aWidth );
66
75 SHAPE_ARC( const SEG& aSegmentA, const SEG& aSegmentB, int aRadius, int aWidth = 0 );
76
77 SHAPE_ARC( const SHAPE_ARC& aOther );
78
79 virtual ~SHAPE_ARC() {}
80
81 SHAPE* Clone() const override
82 {
83 return new SHAPE_ARC( *this );
84 }
85
95 SHAPE_ARC& ConstructFromStartEndAngle( const VECTOR2I& aStart, const VECTOR2I& aEnd,
96 double aAngle, double aWidth = 0 );
97
107 SHAPE_ARC& ConstructFromStartEndCenter( const VECTOR2I& aStart, const VECTOR2I& aEnd,
108 const VECTOR2I& aCenter, bool aClockwise = false,
109 double aWidth = 0 );
110
111 const VECTOR2I& GetP0() const { return m_start; }
112 const VECTOR2I& GetP1() const { return m_end; }
113 const VECTOR2I& GetArcMid() const { return m_mid; }
114 VECTOR2I GetCenter() const;
115
116 const BOX2I BBox( int aClearance = 0 ) const override;
117
118 bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
119 VECTOR2I* aLocation = nullptr ) const override;
120 bool Collide( const VECTOR2I& aP, int aClearance = 0, int* aActual = nullptr,
121 VECTOR2I* aLocation = nullptr ) const override;
122
123
124 bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr,
125 VECTOR2I* aLocation = nullptr ) const override
126 {
127 return SHAPE::Collide( aShape, aClearance, aActual, aLocation );
128 }
129
138 int IntersectLine( const SEG& aSeg, std::vector<VECTOR2I>* aIpsBuffer ) const;
139
147 int Intersect( const SHAPE_ARC& aArc, std::vector<VECTOR2I>* aIpsBuffer ) const;
148
149 bool IsClockwise() const;
150
151 void SetWidth( int aWidth )
152 {
153 m_width = aWidth;
154 }
155
156 int GetWidth() const
157 {
158 return m_width;
159 }
160
161 bool IsSolid() const override
162 {
163 return true;
164 }
165
166 void Move( const VECTOR2I& aVector ) override;
167
174 void Rotate( double aAngle, const VECTOR2I& aCenter ) override;
175
176 void Mirror( bool aX = true, bool aY = false, const VECTOR2I& aVector = { 0, 0 } );
177
178 void Mirror( const SEG& axis );
179
180 void Reverse();
181
182 SHAPE_ARC Reversed() const;
183
184 double GetRadius() const;
185
186 SEG GetChord() const
187 {
188 return SEG( m_start, m_end );
189 }
190
194 double GetCentralAngle() const;
195
199 double GetStartAngle() const;
200
204 double GetEndAngle() const;
205
209 double GetLength() const;
210
220 static double DefaultAccuracyForPCB(){ return 0.005 * PCB_IU_PER_MM; }
221
237 const SHAPE_LINE_CHAIN ConvertToPolyline( double aAccuracy = DefaultAccuracyForPCB(),
238 double* aEffectiveAccuracy = nullptr ) const;
239
240 bool operator==( SHAPE_ARC const& aArc ) const
241 {
242 return ( aArc.m_start == m_start ) && ( aArc.m_end == m_end ) && ( aArc.m_mid == m_mid )
243 && ( aArc.m_width == m_width );
244 }
245
246private:
247 bool ccw( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC ) const
248 {
249 return ( ecoord{ aC.y } - aA.y ) * ( ecoord{ aB.x } - aA.x ) >
250 ( ecoord{ aB.y } - aA.y ) * ( ecoord{ aC.x } - aA.x );
251 }
252
253 void update_bbox();
254
255 bool sliceContainsPoint( const VECTOR2I& p ) const;
256
257private:
258 VECTOR2I m_start;
259 VECTOR2I m_mid;
260 VECTOR2I m_end;
261
262 int m_width;
263 BOX2I m_bbox;
264};
265
266// Required for Boost Test BOOST_CHECK_EQUAL:
267std::ostream& operator<<( std::ostream& aStream, const SHAPE_ARC& aArc );
268
269#endif
Definition seg.h:41
Definition shape_arc.h:36
SHAPE_ARC & ConstructFromStartEndAngle(const VECTOR2I &aStart, const VECTOR2I &aEnd, double aAngle, double aWidth=0)
Construct this arc from the given start, end and angle.
Definition shape_arc.cpp:183
double GetEndAngle() const
Definition shape_arc.cpp:414
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:340
double GetLength() const
Definition shape_arc.cpp:430
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:201
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: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:229
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:458
int Intersect(const SHAPE_ARC &aArc, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aArc.
Definition shape_arc.cpp:279
double GetStartAngle() const
Definition shape_arc.cpp:404
static double DefaultAccuracyForPCB()
Definition shape_arc.h:220
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
Definition shape_arc.h:81
double GetCentralAngle() const
Definition shape_arc.cpp:439
void Rotate(double aAngle, const VECTOR2I &aCenter) override
Rotate the arc by a given angle about a point.
Definition shape_arc.cpp:530
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Definition shape_line_chain.h:81
An abstract shape on 2D plane.
Definition shape.h:117
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:165