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 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
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#include <sstream>
27
31
32const std::string SHAPE_SEGMENT::Format( bool aCplusPlus ) const
33{
34 std::stringstream ss;
35
36 if( aCplusPlus )
37 {
38 ss << "SHAPE_SEGMENT( VECTOR2I( ";
39 ss << m_seg.A.x;
40 ss << ", ";
41 ss << m_seg.A.y;
42 ss << "), VECTOR2I( ";
43 ss << m_seg.B.x;
44 ss << ", ";
45 ss << m_seg.B.y;
46 ss << "), ";
47 ss << m_width;
48 ss << "); ";
49 }
50 else
51 {
52 ss << SHAPE::Format( aCplusPlus ) << " ";
53 ss << m_seg.A.x;
54 ss << " ";
55 ss << m_seg.A.y;
56 ss << " ";
57 ss << m_seg.B.x;
58 ss << " ";
59 ss << m_seg.B.y;
60 ss << " ";
61 ss << m_width;
62 }
63
64 return ss.str();
65}
66
67const std::string SHAPE_CIRCLE::Format( bool aCplusPlus ) const
68{
69 std::stringstream ss;
70
71 if( aCplusPlus )
72 {
73 ss << "SHAPE_CIRCLE( VECTOR2I( ";
74 ss << m_circle.Center.x;
75 ss << ", ";
76 ss << m_circle.Center.y;
77 ss << "), ";
78 ss << m_circle.Radius;
79 ss << "); ";
80 } else
81 {
82 ss << SHAPE::Format( aCplusPlus ) << " ";
83 ss << m_circle.Center.x;
84 ss << " ";
85 ss << m_circle.Center.y;
86 ss << " ";
87 ss << m_circle.Radius;
88 }
89 return ss.str();
90}
91
92
94 ERROR_LOC aErrorLoc ) const
95{
96 TransformCircleToPolygon( aBuffer, m_circle.Center, m_circle.Radius, aError, aErrorLoc );
97}
98
99
100bool SHAPE_SEGMENT::Is45Degree( EDA_ANGLE aTollerance ) const
101{
103
104 double f = fmod( mag.AsDegrees(), 45.0 );
105 double d = aTollerance.AsDegrees();
106
107 if( f >= 45.0 - d || f <= d )
108 {
109 return true;
110 }
111
112 return false;
113}
114
115
117 ERROR_LOC aErrorLoc ) const
118{
119 TransformOvalToPolygon( aBuffer, m_seg.A, m_seg.B, m_width, aError, aErrorLoc );
120}
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:47
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.