29#include <wx/translation.h>
36 if( !aValue.ToCDouble( &value ) )
37 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse number from '%s'" ), aValue ) );
72 std::vector<SHAPE_LINE_CHAIN> result;
78 auto readNumber = [&]( wxString& aOut )
80 wxUniChar ch = data[pos];
82 while( ch ==
' ' || ch ==
',' )
85 while( isdigit( ch ) || ch ==
'.' || ch ==
'-' )
90 if( pos == data.size() )
99 wxUniChar sym = data[pos++];
114 result.emplace_back( chain );
124 else if( sym ==
'Z' )
129 result.emplace_back( chain );
133 else if( sym ==
'L' )
137 if( pos >= data.size() )
140 wxUniChar ch = data[pos];
142 while( ch ==
' ' || ch ==
',' )
144 if( ++pos >= data.size() )
164 else if( sym ==
'A' )
166 wxString radX, radY,
unknown, farFlag, cwFlag, endX, endY;
171 readNumber( farFlag );
172 readNumber( cwFlag );
176 bool isFar = farFlag == wxS(
"1" );
177 bool cw = cwFlag == wxS(
"1" );
184 double d =
delta.EuclideanNorm();
185 double h = sqrt( std::max( 0.0, rad.
x * rad.
x - d * d / 4 ) );
192 start +
delta / 2 +
delta.Perpendicular().Resize( ( isFar ^ cw ) ? h : -h );
202 else if( sym ==
'C' )
204 wxString p1_xStr, p1_yStr, p2_xStr, p2_yStr, p3_xStr, p3_yStr;
205 readNumber( p1_xStr );
206 readNumber( p1_yStr );
207 readNumber( p2_xStr );
208 readNumber( p2_yStr );
209 readNumber( p3_xStr );
210 readNumber( p3_yStr );
220 std::vector<VECTOR2I> bezierPoints;
221 converter.
GetPoly( bezierPoints, aArcMinSegLen, 16 );
223 chain.
Append( bezierPoints );
227 }
while( pos < data.size() );
231 result.emplace_back( chain );
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMinSegLen=0, int aMaxSegCount=32)
Convert a Bezier curve to a polygon.
std::vector< SHAPE_LINE_CHAIN > ParseLineChains(const wxString &aData, int aArcMinSegLen)
static double Convert(const wxString &aValue)
double RelPosX(double aValue)
double RelPosY(double aValue)
VECTOR2< T > RelPos(const VECTOR2< T > &aVec)
virtual double ScaleSize(double aValue)=0
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
void Clear()
Remove all points from the line chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
#define THROW_IO_ERROR(msg)