KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ellipse_geom_manager.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <trigo.h>
23#include <algorithm>
24
25using namespace KIGFX::PREVIEW;
26
27
29{
30 // clang-format off
31 switch( GetStep() )
32 {
33 case SET_BBOX_C1: return setBboxCorner1( aPt );
34 case SET_BBOX_C2: return setBboxCorner2( aPt );
35 case SET_START_ANGLE: return setStartAngle( aPt );
36 case SET_END_ANGLE: return setEndAngle( aPt );
37 case COMPLETE: return false;
38 }
39 // clang-format on
40
41 return false;
42}
43
44
46{
47 m_bboxC1 = aPt;
48 m_bboxC2 = aPt;
49 return true;
50}
51
52
54{
55 m_bboxC2 = aPt;
56
57 const VECTOR2I first = m_bboxC1;
58 const VECTOR2I second = m_bboxC2;
59 const VECTOR2I center = ( first + second ) / 2;
60 const int halfW = std::abs( second.x - first.x ) / 2;
61 const int halfH = std::abs( second.y - first.y ) / 2;
62
63 if( halfW >= halfH )
64 {
65 m_majorRadius = std::max( halfW, 1 );
66 m_minorRadius = std::max( halfH, 1 );
68 }
69 else
70 {
71 m_majorRadius = std::max( halfH, 1 );
72 m_minorRadius = std::max( halfW, 1 );
74 }
75
77
78 // Keep full ellipse preview during bbox building.
81
82 return true;
83}
84
85
87{
89
90 m_startAngle = ellipse.GetAngleAtPoint( aPt );
92
93 return true;
94}
95
96
98{
100 EDA_ANGLE cursorAngle = ellipse.GetAngleAtPoint( aPt );
101
102 // Enforce end > start using 360 wrapping.
103 while( cursorAngle <= m_startAngle )
104 cursorAngle = cursorAngle + ANGLE_360;
105
106 m_endAngle = cursorAngle;
107
108 return m_endAngle != m_startAngle;
109}
110
111
Plain ellipse / elliptical-arc data.
Definition ellipse.h:32
EDA_ANGLE GetAngleAtPoint(const VECTOR2< NumericType > &aPt) const
Get the parametric angle of a point on the ellipse.
Definition ellipse.cpp:109
ELLIPSE< int > GetEllipse() const
Get the ellipse defined by the current geometry (valid after SET_BBOX_C2).
bool acceptPoint(const VECTOR2I &aPt) override
< Function that accepts a point for a stage, or rejects it to return to the previous stage
@ SET_START_ANGLE
Waiting to lock in the start angle.
@ SET_BBOX_C1
Waiting to lock in first bbox corner.
@ SET_END_ANGLE
Waiting to lock in the end angle.
@ SET_BBOX_C2
Waiting to lock in second bbox corner.
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
static constexpr EDA_ANGLE ANGLE_360
Definition eda_angle.h:417
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
VECTOR2I center
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682