KiCad PCB EDA Suite
|
Typedefs | |
using | OVAL_KEY_POINT_FLAGS = unsigned int |
Enumerations | |
enum | OVAL_KEY_POINTS { OVAL_CENTER = 1 << 0 , OVAL_CAP_TIPS = 1 << 1 , OVAL_CAP_CENTERS = 1 << 2 , OVAL_SIDE_MIDPOINTS = 1 << 3 , OVAL_SIDE_ENDS = 1 << 4 , OVAL_CARDINAL_EXTREMES = 1 << 5 , OVAL_ALL_KEY_POINTS = 0xFF } |
Functions | |
bool | BoxHitTest (const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy) |
Perform a point-to-box hit test. | |
bool | BoxHitTest (const BOX2I &aHitter, const BOX2I &aHittee, bool aHitteeContained, int aAccuracy) |
Perform a box-to-box hit test. | |
SHAPE_LINE_CHAIN | ConvertToChain (const OVAL &aOval) |
std::vector< TYPED_POINT2I > | GetOvalKeyPoints (const OVAL &aOval, OVAL_KEY_POINT_FLAGS aFlags) |
Get a list of interesting points on an oval (rectangle with semicircular end caps) | |
SEG | NormalisedSeg (const SEG &aSeg) |
Returns a SEG such that the start point is smaller or equal in x and y compared to the end point. | |
const VECTOR2I & | GetOtherEnd (const SEG &aSeg, const VECTOR2I &aPoint) |
Get the end point of the segment that is not the given point. | |
OPT_VECTOR2I | GetSharedEndpoint (const SEG &aSegA, const SEG &aSegB) |
Get the shared endpoint of two segments, if it exists, or std::nullopt if the segments are not connected end-to-end. | |
std::array< SEG, 4 > | BoxToSegs (const BOX2I &aBox) |
Decompose a BOX2 into four segments. | |
void | CollectBoxCorners (const BOX2I &aBox, std::vector< VECTOR2I > &aCorners) |
Add the 4 corners of a BOX2I to a vector. | |
std::vector< SEG > | GetSegsInDirection (const BOX2I &aBox, DIRECTION_45::Directions aDir) |
Get the segments of a box that are in the given direction. | |
std::optional< SEG > | ClipHalfLineToBox (const HALF_LINE &aRay, const BOX2I &aBox) |
Get the segment of a half-line that is inside a box, if any. | |
std::optional< SEG > | ClipLineToBox (const LINE &aLine, const BOX2I &aBox) |
Get the segment of a line that is inside a box, if any. | |
SHAPE_ARC | MakeArcCw90 (const VECTOR2I &aCenter, int aRadius, DIRECTION_45::Directions aDir) |
Get a SHAPE_ARC representing a 90-degree arc in the clockwise direction with the midpoint in the given direction from the center. | |
SHAPE_ARC | MakeArcCw180 (const VECTOR2I &aCenter, int aRadius, DIRECTION_45::Directions aDir) |
Get a SHAPE_ARC representing a 180-degree arc in the clockwise direction with the midpoint in the given direction from the center. | |
VECTOR2I | GetPoint (const SHAPE_RECT &aRect, DIRECTION_45::Directions aDir, int aOutset=0) |
Get the point on a rectangle that corresponds to a given direction. | |
std::vector< TYPED_POINT2I > | GetCircleKeyPoints (const CIRCLE &aCircle, bool aIncludeCenter) |
Get key points of an CIRCLE. | |
SHAPE_LINE_CHAIN | RectifyPolygon (const SHAPE_LINE_CHAIN &aPoly) |
bool | AddHoleIfValid (SHAPE_POLY_SET &aOutline, SHAPE_LINE_CHAIN &&aHole) |
Adds a hole to a polygon if it is valid (i.e. | |
std::vector< VECTOR2I > | MakeRegularPolygonPoints (const VECTOR2I &aCenter, size_t aN, const VECTOR2I &aPt0) |
Get the corners of a regular polygon from the centre, one point and the number of sides. | |
std::vector< VECTOR2I > | MakeRegularPolygonPoints (const VECTOR2I &aCenter, size_t aN, int aRadius, bool aAcrossCorners, EDA_ANGLE aAngle) |
Make a regular polygon of the given size across the corners. | |
std::vector< SEG > | MakeCrossSegments (const VECTOR2I &aCenter, const VECTOR2I &aSize, EDA_ANGLE aAngle) |
Create the two segments for a cross. | |
template<typename T > | |
bool | PointIsInDirection (const VECTOR2< T > &aPoint, const VECTOR2< T > &aDirection, const VECTOR2< T > &aFrom) |
template<typename T > | |
bool | PointsAreInSameDirection (const VECTOR2< T > &aPointA, const VECTOR2< T > &aPointB, const VECTOR2< T > &aFrom) |
Check that the two given points are in the same direction from some other point. | |
bool | SegIsInDirection (const SEG &aSeg, const VECTOR2I &aDirection) |
Determine if a segment's vector is within 90 degrees of a given direction. | |
bool | PointProjectsOntoSegment (const VECTOR2I &aPoint, const SEG &aSeg) |
Determine if a point projects onto a segment. | |
double | GetLengthRatioFromStart (const VECTOR2I &aPoint, const SEG &aSeg) |
Get the ratio of the vector to a point from the segment's start, compared to the segment's length. | |
double | GetProjectedPointLengthRatio (const VECTOR2I &aPoint, const SEG &aSeg) |
Get the ratio of the vector to a point projected onto a segment from the start, relative to the segment's length. | |
const VECTOR2I & | GetNearestEndpoint (const SEG &aSeg, const VECTOR2I &aPoint) |
Get the nearest end of a segment to a point. | |
VECTOR2I | RoundGrid (const VECTOR2I &aVec, int aGridSize) |
Round a vector to the nearest grid point in any direction. | |
VECTOR2I | RoundNW (const VECTOR2I &aVec, int aGridSize) |
Round a vector to the nearest grid point in the NW direction. | |
VECTOR2I | RoundSE (const VECTOR2I &aVec, int aGridSize) |
Round a vector to the nearest grid point in the SE direction. | |
using KIGEOM::OVAL_KEY_POINT_FLAGS = typedef unsigned int |
bool KIGEOM::AddHoleIfValid | ( | SHAPE_POLY_SET & | aOutline, |
SHAPE_LINE_CHAIN && | aHole | ||
) |
Adds a hole to a polygon if it is valid (i.e.
it has 3 or more points and a non-zero area.)
This is important if you are reading in a polygon from a file and aren't sure if it will end up being valid. Leaving invalid holes in a SHAP_POLY_SET will violate the invariant that holes are non-null.
aOutline | is the outline to add the hole to. |
aHole | is the hole to add. |
Definition at line 382 of file shape_utils.cpp.
References SHAPE_POLY_SET::AddHole().
Referenced by FABMASTER::loadZone().
bool KIGEOM::BoxHitTest | ( | const BOX2I & | aHitter, |
const BOX2I & | aHittee, | ||
bool | aHitteeContained, | ||
int | aAccuracy | ||
) |
Perform a box-to-box hit test.
aHitter | - The box that is either hitting or containing the hittee. |
aHittee | - The box that is either being hit or contained by the hitter (this is possibly an object's bounding box). |
aHitteeContained | - True if the hittee is tested for total containment, false if it is tested for intersection. |
aAccuracy | - The accuracy of the hit test. |
Definition at line 209 of file geometry_utils.cpp.
References BOX2< Vec >::Contains(), BOX2< Vec >::GetInflated(), and BOX2< Vec >::Intersects().
Perform a point-to-box hit test.
aHitPoint | - The point that is hitting the box |
aHittee | - The box that is tested for hit. |
aAccuracy | - The accuracy of the hit test. |
Definition at line 202 of file geometry_utils.cpp.
References BOX2< Vec >::Contains(), and BOX2< Vec >::GetInflated().
Referenced by SCH_BITMAP::HitTest(), and PCB_REFERENCE_IMAGE::HitTest().
Decompose a BOX2 into four segments.
Segments are returned in the order: Top, Right, Bottom, Left.
Definition at line 66 of file shape_utils.cpp.
References BOX2< Vec >::GetBottom(), BOX2< Vec >::GetLeft(), BOX2< Vec >::GetRight(), and BOX2< Vec >::GetTop().
Referenced by ClipHalfLineToBox(), ClipLineToBox(), and INTERSECTION_VISITOR::operator()().
Get the segment of a half-line that is inside a box, if any.
Definition at line 140 of file shape_utils.cpp.
References BoxToSegs(), HALF_LINE::GetStart(), and HALF_LINE::Intersect().
Referenced by BOOST_AUTO_TEST_CASE(), and KIGFX::CONSTRUCTION_GEOM::ViewDraw().
Get the segment of a line that is inside a box, if any.
Definition at line 188 of file shape_utils.cpp.
References BoxToSegs(), and LINE::Intersect().
Referenced by KIGFX::CONSTRUCTION_GEOM::ViewDraw().
Add the 4 corners of a BOX2I to a vector.
Definition at line 84 of file shape_utils.cpp.
References BOX2< Vec >::GetBottom(), BOX2< Vec >::GetLeft(), BOX2< Vec >::GetRight(), and BOX2< Vec >::GetTop().
Referenced by MULTICHANNEL_TOOL::buildRAOutline().
SHAPE_LINE_CHAIN KIGEOM::ConvertToChain | ( | const OVAL & | aOval | ) |
Definition at line 69 of file oval.cpp.
References SEG::A, ANGLE_180, ANGLE_90, SHAPE_LINE_CHAIN::Append(), SEG::B, GetRotated(), OVAL::GetSegment(), OVAL::GetWidth(), VECTOR2< T >::Resize(), and SHAPE_LINE_CHAIN::SetClosed().
Referenced by OUTSET_ROUTINE::ProcessItem().
std::vector< TYPED_POINT2I > KIGEOM::GetCircleKeyPoints | ( | const CIRCLE & | aCircle, |
bool | aIncludeCenter | ||
) |
Get key points of an CIRCLE.
Definition at line 324 of file shape_utils.cpp.
References CIRCLE::Center, PT_CENTER, PT_QUADRANT, and CIRCLE::Radius.
Referenced by PCB_GRID_HELPER::computeAnchors(), and PCB_SHAPE::GetConnectionPoints().
Get the ratio of the vector to a point from the segment's start, compared to the segment's length.
/--- aPoint
A<—+-----—>B <– Length L | | >|-—|<– Length R
The point doesn't have to lie on the segment.
Definition at line 41 of file vector_utils.cpp.
References SEG::A, and SEG::Length().
Referenced by BOOST_AUTO_TEST_CASE(), DIM_ALIGNED_TEXT_UPDATER::getDimensionNewTextPosition(), and GetProjectedPointLengthRatio().
Get the nearest end of a segment to a point.
If equidistant, the start point is returned.
Definition at line 62 of file vector_utils.cpp.
References SEG::A, SEG::B, and VECTOR2< T >::Distance().
Referenced by BOOST_AUTO_TEST_CASE(), and DIM_ALIGNED_TEXT_UPDATER::getDimensionNewTextPosition().
Get the end point of the segment that is not the given point.
Definition at line 45 of file shape_utils.cpp.
References SEG::A, and SEG::B.
Referenced by ComputeChamferPoints(), and ComputeDogbone().
std::vector< TYPED_POINT2I > KIGEOM::GetOvalKeyPoints | ( | const OVAL & | aOval, |
OVAL_KEY_POINT_FLAGS | aFlags | ||
) |
Get a list of interesting points on an oval (rectangle with semicircular end caps)
This may includes:
aOvalSize | - The size of the oval (overall length and width) |
aRotation | - The rotation of the oval |
aFlags | - The flags indicating which points to return |
Definition at line 84 of file oval.cpp.
References ANGLE_90, OVAL::GetAngle(), OVAL::GetCenter(), OVAL::GetLength(), OVAL::GetWidth(), EDA_ANGLE::IsCardinal(), EDA_ANGLE::Normalize90(), OVAL_CAP_CENTERS, OVAL_CAP_TIPS, OVAL_CARDINAL_EXTREMES, OVAL_CENTER, OVAL_SIDE_ENDS, OVAL_SIDE_MIDPOINTS, PT_CENTER, PT_END, PT_MID, PT_QUADRANT, and RotatePoint().
Referenced by PCB_GRID_HELPER::computeAnchors(), and DoOvalPointTestChecks().
VECTOR2I KIGEOM::GetPoint | ( | const SHAPE_RECT & | aRect, |
DIRECTION_45::Directions | aDir, | ||
int | aOutset = 0 |
||
) |
Get the point on a rectangle that corresponds to a given direction.
For directions N, E, S, W, the point is the center of the side. For directions NW, NE, SW, SE, the point is the corner.
aOutset | is a distance to move the point outwards from the rectangle, in the direction of the corner (i.e. perpendicular to the side, or 45 degrees from the corner). |
Definition at line 294 of file shape_utils.cpp.
References DIRECTION_45::E, SHAPE_RECT::GetHeight(), SHAPE_RECT::GetPosition(), SHAPE_RECT::GetWidth(), DIRECTION_45::N, DIRECTION_45::NE, DIRECTION_45::NW, DIRECTION_45::S, DIRECTION_45::SE, DIRECTION_45::SW, and DIRECTION_45::W.
Get the ratio of the vector to a point projected onto a segment from the start, relative to the segment's length.
/--- projects o |
A<—+-----—>B <– Length L | | >|-—|<– Length R
The ratio is R / L. IF 0, the point is at A. If 1, the point is at B. It assumes the point projects onto the segment.
Definition at line 49 of file vector_utils.cpp.
References SEG::A, SEG::B, GetLengthRatioFromStart(), and SEG::NearestPoint().
std::vector< SEG > KIGEOM::GetSegsInDirection | ( | const BOX2I & | aBox, |
DIRECTION_45::Directions | aDir | ||
) |
Get the segments of a box that are in the given direction.
N,E,S,W are the sides of the box. NE,SE,SW,NW are the corners of the box, which return the two segments that meet at the corner, in the order of the direction (e.g. NW = N, then W).
Definition at line 93 of file shape_utils.cpp.
References DIRECTION_45::E, BOX2< Vec >::GetBottom(), BOX2< Vec >::GetLeft(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetTop(), DIRECTION_45::LAST, DIRECTION_45::N, DIRECTION_45::NE, DIRECTION_45::NW, DIRECTION_45::S, DIRECTION_45::SE, DIRECTION_45::SW, DIRECTION_45::UNDEFINED, and DIRECTION_45::W.
Referenced by RECTANGLE_POINT_EDIT_BEHAVIOR::UpdateItem().
OPT_VECTOR2I KIGEOM::GetSharedEndpoint | ( | const SEG & | aSegA, |
const SEG & | aSegB | ||
) |
Get the shared endpoint of two segments, if it exists, or std::nullopt if the segments are not connected end-to-end.
Definition at line 51 of file shape_utils.cpp.
References SEG::A, and SEG::B.
Referenced by ComputeChamferPoints(), and ComputeDogbone().
SHAPE_ARC KIGEOM::MakeArcCw180 | ( | const VECTOR2I & | aCenter, |
int | aRadius, | ||
DIRECTION_45::Directions | aDir | ||
) |
Get a SHAPE_ARC representing a 180-degree arc in the clockwise direction with the midpoint in the given direction from the center.
aDir | is the direction from the center to the midpoint (only N, E, S, W are valid). |
Definition at line 258 of file shape_utils.cpp.
References ANGLE_180, DIRECTION_45::E, DIRECTION_45::N, DIRECTION_45::S, and DIRECTION_45::W.
SHAPE_ARC KIGEOM::MakeArcCw90 | ( | const VECTOR2I & | aCenter, |
int | aRadius, | ||
DIRECTION_45::Directions | aDir | ||
) |
Get a SHAPE_ARC representing a 90-degree arc in the clockwise direction with the midpoint in the given direction from the center.
_ \
+-->x | (So Southerly point are bigger in y) v y
aCenter | is the arc center. |
aRadius | is the arc radius. |
aDir | is the direction from the center to the midpoint (only NW, NE, SW, SE are valid). |
Definition at line 225 of file shape_utils.cpp.
References ANGLE_90, DIRECTION_45::NE, DIRECTION_45::NW, DIRECTION_45::SE, and DIRECTION_45::SW.
std::vector< SEG > KIGEOM::MakeCrossSegments | ( | const VECTOR2I & | aCenter, |
const VECTOR2I & | aSize, | ||
EDA_ANGLE | aAngle | ||
) |
Create the two segments for a cross.
aCenter | is the center of the cross |
aSize | is the size of the cross (can be x != y) |
aAngle | is the angle of the cross (postive = rotate cross CCW) |
Definition at line 425 of file shape_utils.cpp.
References GetRotated(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by FABMASTER::createBoardItems().
std::vector< VECTOR2I > KIGEOM::MakeRegularPolygonPoints | ( | const VECTOR2I & | aCenter, |
size_t | aN, | ||
const VECTOR2I & | aPt0 | ||
) |
Get the corners of a regular polygon from the centre, one point and the number of sides.
Definition at line 394 of file shape_utils.cpp.
References FULL_CIRCLE, GetRotated(), and KiROUND().
Referenced by MakeRegularPolygonPoints(), and FABMASTER::processPolygon().
std::vector< VECTOR2I > KIGEOM::MakeRegularPolygonPoints | ( | const VECTOR2I & | aCenter, |
size_t | aN, | ||
int | aRadius, | ||
bool | aAcrossCorners, | ||
EDA_ANGLE | aAngle | ||
) |
Make a regular polygon of the given size across the corners.
aCenter | the center of the polygon |
aN | polygon side count (e.g. 6 = hexagon) |
aRadius | the distance from the centre to a corner/flat |
aAcrossCorners | true if the radius is to the corners, false to the side midpoints |
aAngle | is the angle from the centre to one point. 0 is the point is to the right, and CCW from there. |
Definition at line 410 of file shape_utils.cpp.
References FULL_CIRCLE, GetRotated(), and MakeRegularPolygonPoints().
Returns a SEG such that the start point is smaller or equal in x and y compared to the end point.
Definition at line 35 of file shape_utils.cpp.
References SEG::A, SEG::B, LexicographicalCompare(), and SEG::Reversed().
bool KIGEOM::PointIsInDirection | ( | const VECTOR2< T > & | aPoint, |
const VECTOR2< T > & | aDirection, | ||
const VECTOR2< T > & | aFrom | ||
) |
Definition at line 57 of file vector_utils.h.
Referenced by BOOST_AUTO_TEST_CASE(), DIM_ALIGNED_TEXT_UPDATER::getDimensionNewTextPosition(), PointsAreInSameDirection(), and SegIsInDirection().
Determine if a point projects onto a segment.
/--- projects /--- does not project o o | |
|<---------—>| x aSeg
Definition at line 32 of file vector_utils.cpp.
References SEG::A, SEG::B, and SEG::NearestPoint().
Referenced by BOOST_AUTO_TEST_CASE(), and DIM_ALIGNED_TEXT_UPDATER::getDimensionNewTextPosition().
bool KIGEOM::PointsAreInSameDirection | ( | const VECTOR2< T > & | aPointA, |
const VECTOR2< T > & | aPointB, | ||
const VECTOR2< T > & | aFrom | ||
) |
Check that the two given points are in the same direction from some other point.
I.e. the vectors from aFrom to aPointA and aFrom to aPointB are within 90 degrees.
Definition at line 70 of file vector_utils.h.
References PointIsInDirection().
Referenced by ComputeDogbone().
SHAPE_LINE_CHAIN KIGEOM::RectifyPolygon | ( | const SHAPE_LINE_CHAIN & | aPoly | ) |
Definition at line 348 of file shape_utils.cpp.
References SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::CSegment(), SHAPE_LINE_CHAIN::IsClosed(), SHAPE_LINE_CHAIN_BASE::PointInside(), SHAPE_LINE_CHAIN::SegmentCount(), SHAPE_LINE_CHAIN::SetClosed(), and SHAPE_LINE_CHAIN::Simplify().
Referenced by MULTICHANNEL_TOOL::buildRAOutline().
Round a vector to the nearest grid point in any direction.
Definition at line 87 of file vector_utils.cpp.
References RoundNearest(), VECTOR2< T >::x, and VECTOR2< T >::y.
Round a vector to the nearest grid point in the NW direction.
This means x and y are both rounded downwards (regardless of sign).
Definition at line 92 of file vector_utils.cpp.
References RoundDown(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by GetRectRoundedToGridOutwards().
Round a vector to the nearest grid point in the SE direction.
This means x and y are both rounded upwards (regardless of sign).
Definition at line 97 of file vector_utils.cpp.
References RoundUp(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by GetRectRoundedToGridOutwards().
Determine if a segment's vector is within 90 degrees of a given direction.
Definition at line 26 of file vector_utils.cpp.
References SEG::A, SEG::B, and PointIsInDirection().