Horizon
Loading...
Searching...
No Matches
convert_basic_shapes_to_polygon.cpp File Reference
#include <algorithm>
#include <bitset>
#include <math.h>
#include <type_traits>
#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>

Classes

struct  ROUNDED_CORNER

Functions

void TransformCircleToPolygon (SHAPE_LINE_CHAIN &aCornerBuffer, const wxPoint &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 &aCornerBuffer, const wxPoint &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 &aCornerBuffer, const wxPoint &aStart, const wxPoint &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 &aCornerBuffer, const wxPoint &aPosition, const wxSize &aSize, double 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 &aCornerBuffer, const wxPoint &aPosition, const wxSize &aSize, double 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, double aStartAngleDeg, double aArcAngleDeg, double aAccuracy, ERROR_LOC aErrorLoc)
 Generate a polyline to approximate a arc.
void TransformArcToPolygon (SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
 Convert arc to multiple straight segments.
void TransformRingToPolygon (SHAPE_POLY_SET &aCornerBuffer, const wxPoint &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,
double aStartAngleDeg,
double 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 (in degrees) of the arc.
aArcAngleDegis the angle (in degrees) of the arc.
aErroris the internal units allowed for error approximation.
aErrorLocdetermines if the approximation error be placed outside or inside the polygon.

◆ TransformArcToPolygon()

void TransformArcToPolygon ( SHAPE_POLY_SET & aCornerBuffer,
const wxPoint & aStart,
const wxPoint & aMid,
const wxPoint & aEnd,
int aWidth,
int aError,
ERROR_LOC aErrorLoc )

Convert arc to multiple straight segments.

Parameters
aCornerBufferis 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.

We start by making rounded ends on the arc

◆ TransformCircleToPolygon() [1/2]

void TransformCircleToPolygon ( SHAPE_LINE_CHAIN & aCornerBuffer,
const wxPoint & aCenter,
int aRadius,
int aError,
ERROR_LOC aErrorLoc,
int aMinSegCount = 0 )

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

Parameters
aCornerBufferis 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 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.

◆ TransformCircleToPolygon() [2/2]

void TransformCircleToPolygon ( SHAPE_POLY_SET & aCornerBuffer,
const wxPoint & aCenter,
int aRadius,
int aError,
ERROR_LOC aErrorLoc,
int aMinSegCount = 0 )

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

Parameters
aCornerBufferis 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.

◆ TransformOvalToPolygon()

void TransformOvalToPolygon ( SHAPE_POLY_SET & aCornerBuffer,
const wxPoint & aStart,
const wxPoint & 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
aCornerBufferis 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.

◆ TransformRingToPolygon()

void TransformRingToPolygon ( SHAPE_POLY_SET & aCornerBuffer,
const wxPoint & aCentre,
int aRadius,
int aWidth,
int aError,
ERROR_LOC aErrorLoc )

Convert arcs to multiple straight segments.

Parameters
aCornerBufferis 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.

◆ TransformRoundChamferedRectToPolygon()

void TransformRoundChamferedRectToPolygon ( SHAPE_POLY_SET & aCornerBuffer,
const wxPoint & aPosition,
const wxSize & aSize,
double 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
aCornerBufferis 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 rotation in 0.1 degrees of 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.

◆ TransformTrapezoidToPolygon()

void TransformTrapezoidToPolygon ( SHAPE_POLY_SET & aCornerBuffer,
const wxPoint & aPosition,
const wxSize & aSize,
double 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
aCornerBufferis 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.