KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ellipse.cpp
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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <geometry/ellipse.h>
21
22
23template <typename NumericType>
24ELLIPSE<NumericType>::ELLIPSE( const VECTOR2<NumericType>& aCenter, NumericType aMajorRadius,
25 NumericType aMinorRadius, EDA_ANGLE aRotation, EDA_ANGLE aStartAngle,
26 EDA_ANGLE aEndAngle ) :
27 Center( aCenter ),
28 MajorRadius( aMajorRadius ),
29 MinorRadius( aMinorRadius ),
30 Rotation( aRotation ),
31 StartAngle( aStartAngle ),
32 EndAngle( aEndAngle )
33{
34}
35
36
37template <typename NumericType>
39 const VECTOR2<NumericType>& aMajor, double aRatio,
40 EDA_ANGLE aStartAngle, EDA_ANGLE aEndAngle ) :
41 Center( aCenter ),
42 StartAngle( aStartAngle ),
43 EndAngle( aEndAngle )
44{
45 MajorRadius = aMajor.EuclideanNorm();
46 MinorRadius = NumericType( MajorRadius * aRatio );
47 Rotation = EDA_ANGLE( std::atan2( aMajor.y, aMajor.x ), RADIANS_T );
48}
49
50
51template <typename NumericType>
53{
54 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
55 Center.x = 2 * aRef.x - Center.x;
56 else
57 Center.y = 2 * aRef.y - Center.y;
58
60
61 const EDA_ANGLE oldStart = StartAngle;
62 const EDA_ANGLE oldEnd = EndAngle;
63
64 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
65 {
66 // theta' = pi - theta -> [s, e] -> [pi - e, pi - s]
67 StartAngle = ANGLE_180 - oldEnd;
68 EndAngle = ANGLE_180 - oldStart;
69 }
70 else
71 {
72 // theta' = -theta -> [s, e] -> [-e, -s]
73 StartAngle = -oldEnd;
74 EndAngle = -oldStart;
75 }
76}
77
78
79template class ELLIPSE<double>;
80template class ELLIPSE<int>;
Plain ellipse / elliptical-arc data.
Definition ellipse.h:32
NumericType MinorRadius
Definition ellipse.h:76
EDA_ANGLE Rotation
Definition ellipse.h:77
void Mirror(const VECTOR2< NumericType > &aRef, FLIP_DIRECTION aFlipDirection)
Mirror the ellipse along a horizontal or vertical axis passing through aRef.
Definition ellipse.cpp:52
EDA_ANGLE StartAngle
Definition ellipse.h:78
ELLIPSE()
Definition ellipse.h:34
NumericType MajorRadius
Definition ellipse.h:75
EDA_ANGLE EndAngle
Definition ellipse.h:79
VECTOR2< NumericType > Center
Definition ellipse.h:74
Define a general 2D-vector/point.
Definition vector2d.h:71
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:283
@ RADIANS_T
Definition eda_angle.h:32
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:415
FLIP_DIRECTION
Definition mirror.h:27
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:28