![]() |
KiCad PCB EDA Suite
|
a few functions useful in geometry calculations. More...
Go to the source code of this file.
Classes | |
class | DISABLE_ARC_RADIUS_CORRECTION |
When creating polygons to create a clearance polygonal area, the polygon must be same or bigger than the original shape. More... | |
Enumerations | |
enum | ERROR_LOC { ERROR_OUTSIDE, ERROR_INSIDE } |
When approximating an arc or circle, should the error be placed on the outside or inside of the curve? (Generally speaking filled shape errors go on the inside and knockout errors go on the outside. More... | |
Functions | |
int | GetArcToSegmentCount (int aRadius, int aErrorMax, double aArcAngleDegree) |
int | CircleToEndSegmentDeltaRadius (int aInnerCircleRadius, int aSegCount) |
int | GetCircleToPolyCorrection (int aMaxError) |
template<typename T > | |
VECTOR2< T > | GetVectorSnapped45 (const VECTOR2< T > &aVec, bool only45=false) |
Snap a vector onto the nearest 0, 45 or 90 degree line. More... | |
template<typename in_type , typename ret_type = in_type, typename pad_type = unsigned int, typename = typename std::enable_if<std::is_unsigned<pad_type>::value>::type> | |
VECTOR2< ret_type > | GetClampedCoords (const VECTOR2< in_type > &aCoords, pad_type aPadding=0u) |
Clamps a vector to values that can be negated, respecting numeric limits of coordinates data type with specified padding. More... | |
bool | ClipLine (const EDA_RECT *aClipBox, int &x1, int &y1, int &x2, int &y2) |
Test if any part of a line falls within the bounds of a rectangle. More... | |
constexpr double | dot_mark_len (double aLineWidth) |
Dashed and dotted line patterns. More... | |
constexpr double | dash_gap_len (double aLineWidth) |
constexpr double | dash_mark_len (double aLineWidth) |
a few functions useful in geometry calculations.
Definition in file geometry_utils.h.
enum ERROR_LOC |
When approximating an arc or circle, should the error be placed on the outside or inside of the curve? (Generally speaking filled shape errors go on the inside and knockout errors go on the outside.
This preserves minimum clearances.)
Enumerator | |
---|---|
ERROR_OUTSIDE | |
ERROR_INSIDE |
Definition at line 45 of file geometry_utils.h.
int CircleToEndSegmentDeltaRadius | ( | int | aInnerCircleRadius, |
int | aSegCount | ||
) |
aInnerCircleRadius | is the radius of the circle tangent to the middle of segments |
aSegCount | is the seg count to approximate the circle |
Definition at line 67 of file geometry_utils.cpp.
References delta, and KiROUND().
Referenced by ConvertArcToPolyline(), SHAPE_ARC::ConvertToPolyline(), CornerListToPolygon(), TransformArcToPolygon(), TransformCircleToPolygon(), TransformOvalToPolygon(), and PAD::TransformShapeWithClearanceToPolygon().
bool ClipLine | ( | const EDA_RECT * | aClipBox, |
int & | x1, | ||
int & | y1, | ||
int & | x2, | ||
int & | y2 | ||
) |
Test if any part of a line falls within the bounds of a rectangle.
Please note that this is only accurate for lines that are one pixel wide.
aClipBox | - The rectangle to test. |
x1 | - X coordinate of one end of a line. |
y1 | - Y coordinate of one end of a line. |
x2 | - X coordinate of the other end of a line. |
y2 | - Y coordinate of the other end of a line. |
Definition at line 137 of file geometry_utils.cpp.
References clipOutCode(), EDA_RECT::GetBottom(), EDA_RECT::GetRight(), EDA_RECT::GetX(), and EDA_RECT::GetY().
Referenced by KIGFX::SCH_PAINTER::draw(), GRCSegm(), SCH_BUS_ENTRY_BASE::Print(), SCH_LINE::Print(), KIGFX::ORIGIN_VIEWITEM::ViewDraw(), and WinClipAndDrawLine().
constexpr double dash_gap_len | ( | double | aLineWidth | ) |
Definition at line 202 of file geometry_utils.h.
References dot_mark_len().
Referenced by dash_mark_len(), KIGFX::SCH_PAINTER::draw(), PLOTTER::GetDashGapLenIU(), SCH_BUS_ENTRY_BASE::Print(), and SCH_LINE::Print().
constexpr double dash_mark_len | ( | double | aLineWidth | ) |
Definition at line 207 of file geometry_utils.h.
References dash_gap_len(), and dot_mark_len().
Referenced by KIGFX::SCH_PAINTER::draw(), PLOTTER::GetDashMarkLenIU(), SCH_BUS_ENTRY_BASE::Print(), and SCH_LINE::Print().
constexpr double dot_mark_len | ( | double | aLineWidth | ) |
Dashed and dotted line patterns.
Definition at line 197 of file geometry_utils.h.
Referenced by dash_gap_len(), dash_mark_len(), KIGFX::SCH_PAINTER::draw(), PLOTTER::GetDotMarkLenIU(), SCH_BUS_ENTRY_BASE::Print(), and SCH_LINE::Print().
int GetArcToSegmentCount | ( | int | aRadius, |
int | aErrorMax, | ||
double | aArcAngleDegree | ||
) |
aRadius | is the radius od the circle or arc |
aErrorMax | is the max error This is the max distance between the middle of a segment and the circle. |
aArcAngleDegree | is the arc angle in degrees |
Definition at line 43 of file geometry_utils.cpp.
References KiROUND(), and MIN_SEGCOUNT_FOR_CIRCLE.
Referenced by DRC_TEST_PROVIDER_SOLDER_MASK::buildRTrees(), SHAPE_POLY_SET::chamferFilletPolygon(), ZONE_FILLER::computeRawFilledArea(), ConvertArcToPolyline(), ConvertOutlineToPolygon(), SHAPE_ARC::ConvertToPolyline(), CornerListToPolygon(), BOARD_ADAPTER::createTrack(), KIGFX::PCB_PAINTER::draw(), KIGFX::OPENGL_GAL::DrawArcSegment(), EXPORTER_PCB_VRML::ExportVrmlPadHole(), EXPORTER_PCB_VRML::ExportVrmlViaHoles(), ZONE_FILLER::fillSingleZone(), gen_arc(), BOARD_ADAPTER::GetCircleSegmentCount(), EAGLE_PLUGIN::loadPolygon(), EAGLE_PLUGIN::loadSignals(), EAGLE_PLUGIN::packagePolygon(), PlotSolderMaskLayer(), PlotStandardLayer(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run(), TransformCircleToPolygon(), TransformOvalToPolygon(), PAD::TransformShapeWithClearanceToPolygon(), ZONE::TransformShapeWithClearanceToPolygon(), ZONE::TransformSmoothedOutlineToPolygon(), and ZONE::TransformSolidAreasShapesToPolygon().
int GetCircleToPolyCorrection | ( | int | aMaxError | ) |
aMaxError | is the same error value used to calculate the number of segments. |
When creating a polygon from a circle, the polygon is inside the circle. Only corners are on the circle. This is incorrect when building clearance areas of circles, that need to build the equivalent polygon outside the circle.
Definition at line 106 of file geometry_utils.cpp.
References s_disable_arc_correction.
Referenced by CornerListToPolygon(), TransformCircleToPolygon(), TransformOvalToPolygon(), and PAD::TransformShapeWithClearanceToPolygon().
VECTOR2<ret_type> GetClampedCoords | ( | const VECTOR2< in_type > & | aCoords, |
pad_type | aPadding = 0u |
||
) |
Clamps a vector to values that can be negated, respecting numeric limits of coordinates data type with specified padding.
Numeric limits are (-2^31 + 1) to (2^31 - 1).
Takes care of rounding in case of floating point to integer conversion.
aCoord | - vector to clamp. |
aPadding | - padding from the limits. Must not be negative. |
Definition at line 150 of file geometry_utils.h.
References KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by KIGFX::WX_VIEW_CONTROLS::ForceCursorPosition(), KIGFX::WX_VIEW_CONTROLS::GetCursorPosition(), KIGFX::WX_VIEW_CONTROLS::GetMousePosition(), KIGFX::WX_VIEW_CONTROLS::onMotion(), KIGFX::WX_VIEW_CONTROLS::refreshMouse(), KIGFX::WX_VIEW_CONTROLS::SetCrossHairCursorPosition(), KIGFX::WX_VIEW_CONTROLS::SetCursorPosition(), and KIGFX::WX_VIEW_CONTROLS::WarpCursor().
VECTOR2<T> GetVectorSnapped45 | ( | const VECTOR2< T > & | aVec, |
bool | only45 = false |
||
) |
Snap a vector onto the nearest 0, 45 or 90 degree line.
The magnitude of the vector is NOT kept, instead the coordinates are set equal (and/or opposite) or to zero as needed. The effect of this is that if the starting vector is on a square grid, the resulting snapped vector will still be on the same grid.
a | vector to be snapped |
Definition at line 107 of file geometry_utils.h.
References VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by EC_45DEGREE::Apply(), DRAWING_TOOL::constrainDimension(), EDIT_TOOL::doMoveSelection(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetEnd(), and POLYGON_GEOM_MANAGER::updateLeaderPoints().