KiCad PCB EDA Suite
shape_segment.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 (C) 2017 CERN
5 * @author Tomasz Wlostowski <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <sstream>
26
29
30const std::string SHAPE_SEGMENT::Format( bool aCplusPlus ) const
31{
32 std::stringstream ss;
33
34 if( aCplusPlus )
35 {
36 ss << "SHAPE_SEGMENT( VECTOR2I( ";
37 ss << m_seg.A.x;
38 ss << ", ";
39 ss << m_seg.A.y;
40 ss << "), VECTOR2I( ";
41 ss << m_seg.B.x;
42 ss << ", ";
43 ss << m_seg.B.y;
44 ss << "), ";
45 ss << m_width;
46 ss << "); ";
47 }
48 else
49 {
50 ss << SHAPE::Format( aCplusPlus ) << " ";
51 ss << m_seg.A.x;
52 ss << " ";
53 ss << m_seg.A.y;
54 ss << " ";
55 ss << m_seg.B.x;
56 ss << " ";
57 ss << m_seg.B.y;
58 ss << " ";
59 ss << m_width;
60 }
61
62 return ss.str();
63}
64
65const std::string SHAPE_CIRCLE::Format( bool aCplusPlus ) const
66{
67 std::stringstream ss;
68
69 if( aCplusPlus )
70 {
71 ss << "SHAPE_CIRCLE( VECTOR2I( ";
72 ss << m_circle.Center.x;
73 ss << ", ";
74 ss << m_circle.Center.y;
75 ss << "), ";
76 ss << m_circle.Radius;
77 ss << "); ";
78 } else
79 {
80 ss << SHAPE::Format( aCplusPlus ) << " ";
81 ss << m_circle.Center.x;
82 ss << " ";
83 ss << m_circle.Center.y;
84 ss << " ";
85 ss << m_circle.Radius;
86 }
87 return ss.str();
88}
89
90bool SHAPE_SEGMENT::Is45Degree( EDA_ANGLE aTollerance ) const
91{
93
94 double f = fmod( mag.AsDegrees(), 45.0 );
95 double d = aTollerance.AsDegrees();
96
97 if( f >= 45.0 - d || f <= d )
98 {
99 return true;
100 }
101
102 return false;
103}
104
VECTOR2I Center
Public to make access simpler.
Definition: circle.h:116
int Radius
Public to make access simpler.
Definition: circle.h:115
double AsDegrees() const
Definition: eda_angle.h:149
EDA_ANGLE Normalize180()
Definition: eda_angle.h:288
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
CIRCLE m_circle
Definition: shape_circle.h:141
virtual const std::string Format(bool aCplusPlus=true) const override
bool Is45Degree(EDA_ANGLE aTollerance=EDA_ANGLE(1.0, DEGREES_T)) const
virtual const std::string Format(bool aCplusPlus=true) const override
virtual const std::string Format(bool aCplusPlus=true) const
Definition: shape.cpp:41