KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KIGEOM Namespace Reference

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_POINT2IGetOvalKeyPoints (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 VECTOR2IGetOtherEnd (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< SEGGetSegsInDirection (const BOX2I &aBox, DIRECTION_45::Directions aDir)
 Get the segments of a box that are in the given direction.
 
std::optional< SEGClipHalfLineToBox (const HALF_LINE &aRay, const BOX2I &aBox)
 Get the segment of a half-line that is inside a box, if any.
 
std::optional< SEGClipLineToBox (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_POINT2IGetCircleKeyPoints (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< VECTOR2IMakeRegularPolygonPoints (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< VECTOR2IMakeRegularPolygonPoints (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< SEGMakeCrossSegments (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 VECTOR2IGetNearestEndpoint (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.
 

Typedef Documentation

◆ OVAL_KEY_POINT_FLAGS

using KIGEOM::OVAL_KEY_POINT_FLAGS = typedef unsigned int

Definition at line 121 of file oval.h.

Enumeration Type Documentation

◆ OVAL_KEY_POINTS

Enumerator
OVAL_CENTER 
OVAL_CAP_TIPS 
OVAL_CAP_CENTERS 
OVAL_SIDE_MIDPOINTS 
OVAL_SIDE_ENDS 
OVAL_CARDINAL_EXTREMES 
OVAL_ALL_KEY_POINTS 

Definition at line 110 of file oval.h.

Function Documentation

◆ AddHoleIfValid()

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.

Parameters
aOutlineis the outline to add the hole to.
aHoleis the hole to add.
Returns
true if the hole was added, false if it was not.

Definition at line 382 of file shape_utils.cpp.

References SHAPE_POLY_SET::AddHole().

Referenced by FABMASTER::loadZone().

◆ BoxHitTest() [1/2]

bool KIGEOM::BoxHitTest ( const BOX2I aHitter,
const BOX2I aHittee,
bool  aHitteeContained,
int  aAccuracy 
)

Perform a box-to-box hit test.

Parameters
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().

◆ BoxHitTest() [2/2]

bool KIGEOM::BoxHitTest ( const VECTOR2I aHitPoint,
const BOX2I aHittee,
int  aAccuracy 
)

Perform a point-to-box hit test.

Parameters
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().

◆ BoxToSegs()

std::array< SEG, 4 > KIGEOM::BoxToSegs ( const BOX2I aBox)

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()().

◆ ClipHalfLineToBox()

std::optional< SEG > KIGEOM::ClipHalfLineToBox ( const HALF_LINE aRay,
const BOX2I aBox 
)

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().

◆ ClipLineToBox()

std::optional< SEG > KIGEOM::ClipLineToBox ( const LINE aLine,
const BOX2I aBox 
)

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().

◆ CollectBoxCorners()

void KIGEOM::CollectBoxCorners ( const BOX2I aBox,
std::vector< VECTOR2I > &  aCorners 
)

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().

◆ ConvertToChain()

◆ GetCircleKeyPoints()

std::vector< TYPED_POINT2I > KIGEOM::GetCircleKeyPoints ( const CIRCLE aCircle,
bool  aIncludeCenter 
)

Get key points of an CIRCLE.

  • The four cardinal points
  • Optionally the center

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().

◆ GetLengthRatioFromStart()

double KIGEOM::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.

   /--- 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().

◆ GetNearestEndpoint()

const VECTOR2I & KIGEOM::GetNearestEndpoint ( const SEG aSeg,
const VECTOR2I aPoint 
)

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().

◆ GetOtherEnd()

const VECTOR2I & KIGEOM::GetOtherEnd ( const SEG aSeg,
const VECTOR2I aPoint 
)

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().

◆ GetOvalKeyPoints()

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:

  • The middles of the sides
  • The tips of the end caps
  • The extreme cardinal points of the whole oval (if rotated non-cardinally)
Parameters
aOvalSize- The size of the oval (overall length and width)
aRotation- The rotation of the oval
aFlags- The flags indicating which points to return
Returns
std::vector<TYPED_POINT2I> - The list of points and their geomtrical types

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().

◆ GetPoint()

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.

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

◆ GetProjectedPointLengthRatio()

double KIGEOM::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.

  /--- 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().

◆ GetSegsInDirection()

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().

◆ GetSharedEndpoint()

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().

◆ MakeArcCw180()

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.

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

◆ MakeArcCw90()

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.

_ \

  • | <— This is the NE arc from the + point.

+-->x | (So Southerly point are bigger in y) v y

Parameters
aCenteris the arc center.
aRadiusis the arc radius.
aDiris 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.

◆ MakeCrossSegments()

std::vector< SEG > KIGEOM::MakeCrossSegments ( const VECTOR2I aCenter,
const VECTOR2I aSize,
EDA_ANGLE  aAngle 
)

Create the two segments for a cross.

Parameters
aCenteris the center of the cross
aSizeis the size of the cross (can be x != y)
aAngleis 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().

◆ MakeRegularPolygonPoints() [1/2]

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().

◆ MakeRegularPolygonPoints() [2/2]

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.

Parameters
aCenterthe center of the polygon
aNpolygon side count (e.g. 6 = hexagon)
aRadiusthe distance from the centre to a corner/flat
aAcrossCornerstrue if the radius is to the corners, false to the side midpoints
aAngleis 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().

◆ NormalisedSeg()

SEG KIGEOM::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.

Definition at line 35 of file shape_utils.cpp.

References SEG::A, SEG::B, LexicographicalCompare(), and SEG::Reversed().

◆ PointIsInDirection()

template<typename T >
bool KIGEOM::PointIsInDirection ( const VECTOR2< T > &  aPoint,
const VECTOR2< T > &  aDirection,
const VECTOR2< T > &  aFrom 
)

◆ PointProjectsOntoSegment()

bool KIGEOM::PointProjectsOntoSegment ( const VECTOR2I aPoint,
const SEG aSeg 
)

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().

◆ PointsAreInSameDirection()

template<typename T >
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().

◆ RectifyPolygon()

◆ RoundGrid()

VECTOR2I KIGEOM::RoundGrid ( const VECTOR2I aVec,
int  aGridSize 
)

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.

◆ RoundNW()

VECTOR2I KIGEOM::RoundNW ( const VECTOR2I aVec,
int  aGridSize 
)

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().

◆ RoundSE()

VECTOR2I KIGEOM::RoundSE ( const VECTOR2I aVec,
int  aGridSize 
)

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().

◆ SegIsInDirection()

bool KIGEOM::SegIsInDirection ( const SEG aSeg,
const VECTOR2I aDirection 
)

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().