69 item->m_LineWidth = aWidth;
77 for(
size_t ii = 1; ii < aPoints.size(); ii++ )
78 addSegment( aPoints[ii - 1], aPoints[ii], aWidth );
80 if( aClose && aPoints.size() > 2 )
81 addSegment( aPoints.back(), aPoints.front(), aWidth );
87 if( aPoints.size() < 3 )
94 auto item = std::make_unique<DS_DATA_ITEM_POLYGONS>();
99 item->m_LineWidth = 0.01;
106 for(
const VECTOR2D& point : aPoints )
116 double aMinorRadius,
const EDA_ANGLE& aRotation,
117 double aStartRadians,
double aSweepRadians )
const
119 std::vector<VECTOR2D> points;
121 const double major =
std::abs( aMajorRadius );
122 const double minor =
std::abs( aMinorRadius );
123 const double largest = std::max( major, minor );
125 if( largest <= 0.0 || aSweepRadians == 0.0 )
129 const double ratio = std::clamp( 1.0 -
FLATTEN_ERROR_MM / largest, -1.0, 1.0 );
130 const double step = std::max( 2.0 * std::acos( ratio ), 1e-3 );
131 const int count = std::max( 2, (
int) std::ceil(
std::abs( aSweepRadians ) / step ) );
133 const double rotCos = std::cos( aRotation.
AsRadians() );
134 const double rotSin = std::sin( aRotation.
AsRadians() );
136 for(
int ii = 0; ii <= count; ii++ )
138 const double angle = aStartRadians + aSweepRadians * ii / count;
139 const double x = major * std::cos( angle );
140 const double y = minor * std::sin( angle );
142 points.emplace_back( aCenter.
x + x * rotCos - y * rotSin, aCenter.
y + x * rotSin + y * rotCos );
157 bool aFilled,
const COLOR4D& aFillColor )
166 const VECTOR2D startVec = aStart - aCenter;
168 const double startAngle = std::atan2( startVec.
y, startVec.
x );
171 std::vector<VECTOR2D> points =
182 bool aFilled,
const COLOR4D& aFillColor )
184 std::vector<VECTOR2D> points;
186 points.reserve( aVertices.size() );
188 for(
const VECTOR2D& vertex : aVertices )
189 points.push_back(
mapPoint( vertex ) );
199 double aWidth,
double aThickness,
double aOrientation,
203 auto item = std::make_unique<DS_DATA_ITEM_TEXT>( aText );
208 item->SetStart( position.
x, position.
y,
LT_CORNER );
212 if( aWidth > 0.0 && aHeight > 0.0 )
216 item->m_Orient = aOrientation;
217 item->m_Hjustify = aHJustify;
218 item->m_Vjustify = aVJustify;
230 std::vector<VECTOR2D> points;
242 std::vector<VECTOR2D> points =
flattenEllipseArc( aCenter, aMajorRadius, aMinorRadius, aRotation, 0.0, 2.0 *
M_PI );
264 double sweep = ( aEndAngle - aStartAngle ).AsRadians();
267 while( sweep <= 0.0 )
270 std::vector<VECTOR2D> points =
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
void addPolyline(const std::vector< VECTOR2D > &aPoints, double aWidth, bool aClose)
Add a run of points as segments, closing back to the first point when asked.
std::vector< VECTOR2D > flattenEllipseArc(const VECTOR2D &aCenter, double aMajorRadius, double aMinorRadius, const EDA_ANGLE &aRotation, double aStartRadians, double aSweepRadians) const
Walk an elliptical arc, which covers circles and arcs as well.
GRAPHICS_IMPORTER_PL_EDITOR()
double mapLineWidth(const IMPORTED_STROKE &aStroke) const
The line width to draw a stroke with, in millimetres.
void AddEllipseArc(const VECTOR2D &aCenter, double aMajorRadius, double aMinorRadius, const EDA_ANGLE &aRotation, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle, const IMPORTED_STROKE &aStroke) override
Create an object representing an elliptical arc.
void AddText(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify, const COLOR4D &aColor) override
Create an object representing a text.
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, const EDA_ANGLE &aAngle, const IMPORTED_STROKE &aStroke) override
Create an object representing an arc.
void addSegment(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth)
DS_DATA_ITEM_POLYGONS * m_polygons
All filled areas go into one item, the way a traced logo is one object.
VECTOR2D mapPoint(const VECTOR2D &aPoint) const
Scale and offset an imported point into the drawing sheet's millimetres.
std::vector< std::unique_ptr< DS_DATA_ITEM > > m_dataItems
void AddSpline(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, const IMPORTED_STROKE &aStroke) override
Create an object representing an arc.
void AddLine(const VECTOR2D &aOrigin, const VECTOR2D &aEnd, const IMPORTED_STROKE &aStroke) override
Create an object representing a line segment.
void AddPolygon(const std::vector< VECTOR2D > &aVertices, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor) override
Create an object representing a polygon.
void addFilledPolygon(const std::vector< VECTOR2D > &aPoints)
Add a run of points as one contour of the filled polygon item.
void AddCircle(const VECTOR2D &aCenter, double aRadius, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor) override
Create an object representing a circle.
void AddEllipse(const VECTOR2D &aCenter, double aMajorRadius, double aMinorRadius, const EDA_ANGLE &aRotation, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor=COLOR4D::UNSPECIFIED) override
Create an object representing a closed ellipse.
VECTOR2D GetScale() const
double GetLineWidthMM() const
Return the line width used for importing the outlines (in mm).
double m_millimeterToIu
Factor to convert millimeters to Internal Units.
const VECTOR2D & GetImportOffsetMM() const
A clone of IMPORTED_STROKE, but with floating-point width.
A color representation with 4 components: red, green, blue, alpha.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
static constexpr EDA_ANGLE ANGLE_0
static constexpr double FLATTEN_ERROR_MM
How far a flattened curve may sit from the real one, in mm.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
VECTOR2< double > VECTOR2D