KiCad PCB EDA Suite
Loading...
Searching...
No Matches
convert_basic_shapes_to_polygon.cpp File Reference
#include <algorithm>
#include <bitset>
#include <math.h>
#include <convert_basic_shapes_to_polygon.h>
#include <geometry/geometry_utils.h>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_poly_set.h>
#include <math/util.h>
#include <math/vector2d.h>
#include <trigo.h>

Go to the source code of this file.

Classes

struct  ROUNDED_CORNER
 

Functions

void TransformCircleToPolygon (SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount)
 Convert a circle to a polygon, using multiple straight lines.
 
void TransformCircleToPolygon (SHAPE_POLY_SET &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount)
 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)
 Convert a oblong shape to a polygon, using multiple segments.
 
void CornerListToPolygon (SHAPE_POLY_SET &outline, std::vector< ROUNDED_CORNER > &aCorners, int aInflate, int aError, ERROR_LOC aErrorLoc)
 
void CornerListRemoveDuplicates (std::vector< ROUNDED_CORNER > &aCorners)
 
void TransformTrapezoidToPolygon (SHAPE_POLY_SET &aBuffer, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aRotation, int aDeltaX, int aDeltaY, int aInflate, int aError, ERROR_LOC aErrorLoc)
 Convert a rectangle or trapezoid to a polygon.
 
void TransformRoundChamferedRectToPolygon (SHAPE_POLY_SET &aBuffer, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aInflate, int aError, ERROR_LOC aErrorLoc)
 Convert a rectangle with rounded corners and/or chamfered corners to a polygon.
 
int ConvertArcToPolyline (SHAPE_LINE_CHAIN &aPolyline, VECTOR2I aCenter, int aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aArcAngle, double aAccuracy, ERROR_LOC aErrorLoc)
 Generate a polyline to approximate a arc.
 
void TransformArcToPolygon (SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
 Convert arc to multiple straight segments.
 
void TransformRingToPolygon (SHAPE_POLY_SET &aBuffer, const VECTOR2I &aCentre, int aRadius, int aWidth, int aError, ERROR_LOC aErrorLoc)
 Convert arcs to multiple straight segments.
 

Function Documentation

◆ ConvertArcToPolyline()

int ConvertArcToPolyline ( SHAPE_LINE_CHAIN aPolyline,
VECTOR2I  aCenter,
int  aRadius,
const EDA_ANGLE aStartAngleDeg,
const EDA_ANGLE aArcAngleDeg,
double  aAccuracy,
ERROR_LOC  aErrorLoc 
)

Generate a polyline to approximate a arc.

Parameters
aPolylineis a buffer to store the polyline.
aCenteris the center of the arc.
aRadiusis the radius of the arc.
aStartAngleDegis the starting point of the arc.
aArcAngleDegis the angle of the arc.
aErroris the internal units allowed for error approximation.
aErrorLocdetermines if the approximation error be placed outside or inside the polygon.

Definition at line 518 of file convert_basic_shapes_to_polygon.cpp.

References std::abs(), SHAPE_LINE_CHAIN::Append(), EDA_ANGLE::AsDegrees(), CircleToEndSegmentDeltaRadius(), EDA_ANGLE::Cos(), delta, ERROR_INSIDE, GetArcToSegmentCount(), KiROUND(), EDA_ANGLE::Sin(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DSN::SPECCTRA_DB::makeIMAGE(), and TransformArcToPolygon().

◆ CornerListRemoveDuplicates()

void CornerListRemoveDuplicates ( std::vector< ROUNDED_CORNER > &  aCorners)

◆ CornerListToPolygon()

◆ TransformArcToPolygon()

void TransformArcToPolygon ( SHAPE_POLY_SET aBuffer,
const VECTOR2I aStart,
const VECTOR2I aMid,
const VECTOR2I aEnd,
int  aWidth,
int  aError,
ERROR_LOC  aErrorLoc 
)

Convert arc to multiple straight segments.

Parameters
aBufferis a buffer to store the polygon.
aCentreis the center of the arc or circle.
aStartis the start point of the arc or a point on the circle.
aArcAngleis the arc angle in 0.1 degrees. For a circle, aArcAngle = 3600.
aWidthis the width (thickness) of the line.
aErroris the internal units allowed for error in approximation.
aErrorLocdetermines if the approximation error be placed outside or inside the polygon.

Definition at line 579 of file convert_basic_shapes_to_polygon.cpp.

References ANGLE_0, ANGLE_180, SHAPE_POLY_SET::Append(), ConvertArcToPolyline(), SEG::Distance(), ERROR_INSIDE, ERROR_OUTSIDE, SHAPE_ARC::GetCenter(), SHAPE_ARC::GetCentralAngle(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), SHAPE_ARC::GetRadius(), SHAPE_ARC::GetStartAngle(), SHAPE_ARC::GetWidth(), SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::Outline(), and TransformOvalToPolygon().

Referenced by BOOST_AUTO_TEST_CASE(), KIGFX::PCB_PAINTER::draw(), CADSTAR_PCB_ARCHIVE_LOADER::loadCoppers(), EDA_SHAPE::TransformShapeToPolygon(), PCB_TRACK::TransformShapeToPolygon(), and SHAPE_ARC::TransformToPolygon().

◆ TransformCircleToPolygon() [1/2]

void TransformCircleToPolygon ( SHAPE_LINE_CHAIN aBuffer,
const VECTOR2I aCenter,
int  aRadius,
int  aError,
ERROR_LOC  aErrorLoc,
int  aMinSegCount = 0 
)

◆ TransformCircleToPolygon() [2/2]

void TransformCircleToPolygon ( SHAPE_POLY_SET aBuffer,
const VECTOR2I aCenter,
int  aRadius,
int  aError,
ERROR_LOC  aErrorLoc,
int  aMinSegCount = 0 
)

Convert a circle to a polygon, using multiple straight lines.

Parameters
aBufferis a buffer to store the polygon.
aCenteris the center of the circle.
aRadiusis the radius of the circle.
aErroris the internal units allowed for error in approximation.
aErrorLocdetermines if the approximation error be placed outside or inside the polygon.
aMinSegCountis the min count of segments to approximate. Default = 0 to do not force a min count.

Definition at line 77 of file convert_basic_shapes_to_polygon.cpp.

References ANGLE_0, ANGLE_360, SHAPE_POLY_SET::Append(), CircleToEndSegmentDeltaRadius(), delta, ERROR_OUTSIDE, FULL_CIRCLE, GetArcToSegmentCount(), GetCircleToPolyCorrection(), SHAPE_POLY_SET::NewOutline(), RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ TransformOvalToPolygon()

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.

It is similar to TransformRoundedEndsSegmentToPolygon, but the polygon is outside the actual oblong shape (a segment with rounded ends). It is suitable to create oblong clearance areas because multiple segments create a smaller area than the circle. The radius of the circle to approximate must be bigger ( radius*aCorrectionFactor) to create segments outside the circle.

Parameters
aBufferis a buffer to store the polygon.
aStartis the first point of the segment.
aEndis the second point of the segment.
aWidthis the width of the segment.
aErroris the internal units allowed for error in approximation.
aErrorLocdetermines if the approximation error be placed outside or inside the polygon.
aMinSegCountis the min count of segments to approximate. Default = 0 to do not force a min count.

Definition at line 122 of file convert_basic_shapes_to_polygon.cpp.

References ANGLE_180, ANGLE_360, SHAPE_POLY_SET::Append(), SHAPE_POLY_SET::BooleanIntersection(), CircleToEndSegmentDeltaRadius(), correction, delta, ERROR_OUTSIDE, EuclideanNorm(), FULL_CIRCLE, GetArcToSegmentCount(), GetCircleToPolyCorrection(), KiROUND(), SHAPE_POLY_SET::Move(), SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE, SHAPE_POLY_SET::Rotate(), RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by buildPadOutlineAsPolygon(), FOOTPRINT::CheckPads(), CALLBACK_GAL::DrawGlyph(), CADSTAR_PCB_ARCHIVE_LOADER::loadCoppers(), DIALOG_PAD_PROPERTIES::padValuesOK(), PCB_IO_EASYEDAPRO_PARSER::ParseBoard(), PCB_IO_KICAD_SEXPR_PARSER::parseZONE(), DXF_PLOTTER::PlotPoly(), DXF_PLOTTER::ThickSegment(), TransformArcToPolygon(), PAD::TransformHoleToPolygon(), EDA_SHAPE::TransformShapeToPolygon(), PCB_DIMENSION_BASE::TransformShapeToPolygon(), PCB_TRACK::TransformShapeToPolygon(), PCB_TEXTBOX::TransformShapeToPolygon(), PAD::TransformShapeToPolygon(), PCB_TEXT::TransformTextToPolySet(), PCB_TEXTBOX::TransformTextToPolySet(), and SHAPE_SEGMENT::TransformToPolygon().

◆ TransformRingToPolygon()

void TransformRingToPolygon ( SHAPE_POLY_SET aBuffer,
const VECTOR2I aCentre,
int  aRadius,
int  aWidth,
int  aError,
ERROR_LOC  aErrorLoc 
)

Convert arcs to multiple straight segments.

Parameters
aBufferis a buffer to store the polygon.
aCentreis the center of the arc or circle.
aRadiusis the radius of the circle.
aWidthis the width (thickness) of the ring.
aErroris the internal units allowed for error in approximation.
aErrorLocdetermines if the approximation error be placed outside or inside the polygon.

Definition at line 641 of file convert_basic_shapes_to_polygon.cpp.

References SHAPE_POLY_SET::Append(), ERROR_INSIDE, ERROR_OUTSIDE, SHAPE_POLY_SET::Fracture(), SHAPE_POLY_SET::Hole(), SHAPE_POLY_SET::NewHole(), SHAPE_POLY_SET::PM_FAST, and TransformCircleToPolygon().

Referenced by buildPadOutlineAsPolygon(), AM_PRIMITIVE::ConvertBasicShapeToPolygon(), and EDA_SHAPE::TransformShapeToPolygon().

◆ TransformRoundChamferedRectToPolygon()

void TransformRoundChamferedRectToPolygon ( SHAPE_POLY_SET aBuffer,
const VECTOR2I aPosition,
const VECTOR2I aSize,
const EDA_ANGLE aRotation,
int  aCornerRadius,
double  aChamferRatio,
int  aChamferCorners,
int  aInflate,
int  aError,
ERROR_LOC  aErrorLoc 
)

Convert a rectangle with rounded corners and/or chamfered corners to a polygon.

Convert rounded corners arcs to multiple straight lines. This will generate at least 16 segments per circle.

Parameters
aBufferis a buffer to store the polygon.
aPositionis the coordinate of the center of the rectangle.
aSizeis the size of the rectangle.
aCornerRadiusis the radius of rounded corners (can be 0).
aRotationis the rotationof the rectangle.
aChamferRatiois the ratio between smaller rect side and chamfer value.
aChamferCornersis the identifier of the corners to chamfer:
  • 0 = no chamfer
  • 1 = TOP_LEFT
  • 2 = TOP_RIGHT
  • 4 = BOTTOM_LEFT
  • 8 = BOTTOM_RIGHT One can have more than one chamfered corner by ORing the corner identifiers.
aInflateis the (positive) shape inflation or 0
aErroris the IU allowed for error in approximation.
aErrorLocdetermines if the approximation error be placed outside or inside the polygon.

Definition at line 451 of file convert_basic_shapes_to_polygon.cpp.

References SHAPE_POLY_SET::Append(), chamfer, CornerListRemoveDuplicates(), CornerListToPolygon(), EDA_ANGLE::IsZero(), KiROUND(), SHAPE_POLY_SET::Move(), RECT_CHAMFER_BOTTOM_LEFT, RECT_CHAMFER_BOTTOM_RIGHT, RECT_CHAMFER_TOP_LEFT, RECT_CHAMFER_TOP_RIGHT, SHAPE_POLY_SET::Rotate(), sign(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PAD::BuildEffectiveShapes(), GENCAD_EXPORTER::CreatePadsShapesSection(), GERBER_PLOTTER::FlashPadChamferRoundRect(), DXF_PLOTTER::FlashPadRoundRect(), GERBER_PLOTTER::FlashPadRoundRect(), HPGL_PLOTTER::FlashPadRoundRect(), PSLIKE_PLOTTER::FlashPadRoundRect(), DSN::SPECCTRA_DB::makePADSTACK(), PCB_IO_EASYEDAPRO_PARSER::ParseContour(), and PAD::TransformShapeToPolygon().

◆ TransformTrapezoidToPolygon()

void TransformTrapezoidToPolygon ( SHAPE_POLY_SET aBuffer,
const VECTOR2I aPosition,
const VECTOR2I aSize,
const EDA_ANGLE aRotation,
int  aDeltaX,
int  aDeltaY,
int  aInflate,
int  aError,
ERROR_LOC  aErrorLoc 
)

Convert a rectangle or trapezoid to a polygon.

This will generate at least 16 segments per circle (when using inflate).

Parameters
aBufferis a buffer to store the polygon.
aPositionis the coordinate of the center of the rectangle.
aSizeis the size of the rectangle.
aDeltaXis the delta for trapezoids in X direction
aDeltaYis the delta for trapezoids in Y direction
aInflateis the (positive) shape inflation or 0
aErroris the IU allowed for error in approximation.
aErrorLocdetermines if the approximation error be placed outside or inside the polygon.

Definition at line 378 of file convert_basic_shapes_to_polygon.cpp.

References std::abs(), SHAPE_POLY_SET::Append(), CornerListRemoveDuplicates(), CornerListToPolygon(), EDA_ANGLE::IsZero(), KiROUND(), SHAPE_POLY_SET::Move(), SHAPE_POLY_SET::Rotate(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PAD::TransformShapeToPolygon().