KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
30
31const std::string SHAPE_SEGMENT::Format( bool aCplusPlus ) const
32{
33 std::stringstream ss;
34
35 if( aCplusPlus )
36 {
37 ss << "SHAPE_SEGMENT( VECTOR2I( ";
38 ss << m_seg.A.x;
39 ss << ", ";
40 ss << m_seg.A.y;
41 ss << "), VECTOR2I( ";
42 ss << m_seg.B.x;
43 ss << ", ";
44 ss << m_seg.B.y;
45 ss << "), ";
46 ss << m_width;
47 ss << "); ";
48 }
49 else
50 {
51 ss << SHAPE::Format( aCplusPlus ) << " ";
52 ss << m_seg.A.x;
53 ss << " ";
54 ss << m_seg.A.y;
55 ss << " ";
56 ss << m_seg.B.x;
57 ss << " ";
58 ss << m_seg.B.y;
59 ss << " ";
60 ss << m_width;
61 }
62
63 return ss.str();
64}
65
66const std::string SHAPE_CIRCLE::Format( bool aCplusPlus ) const
67{
68 std::stringstream ss;
69
70 if( aCplusPlus )
71 {
72 ss << "SHAPE_CIRCLE( VECTOR2I( ";
73 ss << m_circle.Center.x;
74 ss << ", ";
75 ss << m_circle.Center.y;
76 ss << "), ";
77 ss << m_circle.Radius;
78 ss << "); ";
79 } else
80 {
81 ss << SHAPE::Format( aCplusPlus ) << " ";
82 ss << m_circle.Center.x;
83 ss << " ";
84 ss << m_circle.Center.y;
85 ss << " ";
86 ss << m_circle.Radius;
87 }
88 return ss.str();
89}
90
91
93 ERROR_LOC aErrorLoc ) const
94{
95 TransformCircleToPolygon( aBuffer, m_circle.Center, m_circle.Radius, aError, aErrorLoc );
96}
97
98
99bool SHAPE_SEGMENT::Is45Degree( EDA_ANGLE aTollerance ) const
100{
102
103 double f = fmod( mag.AsDegrees(), 45.0 );
104 double d = aTollerance.AsDegrees();
105
106 if( f >= 45.0 - d || f <= d )
107 {
108 return true;
109 }
110
111 return false;
112}
113
114
116 ERROR_LOC aErrorLoc ) const
117{
118 TransformOvalToPolygon( aBuffer, m_seg.A, m_seg.B, m_width, aError, aErrorLoc );
119}
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
VECTOR2I Center
Public to make access simpler.
Definition: circle.h:130
int Radius
Public to make access simpler.
Definition: circle.h:129
double AsDegrees() const
Definition: eda_angle.h:113
EDA_ANGLE Normalize180()
Definition: eda_angle.h:260
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
CIRCLE m_circle
Definition: shape_circle.h:154
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.
virtual const std::string Format(bool aCplusPlus=true) const override
Represent a set of closed polygons.
bool Is45Degree(EDA_ANGLE aTollerance=EDA_ANGLE(1.0, DEGREES_T)) const
virtual const std::string Format(bool aCplusPlus=true) const override
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.
virtual const std::string Format(bool aCplusPlus=true) const
Definition: shape.cpp:46
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.