46 return ( aSeg.
A == aPoint ) ? aSeg.
B : aSeg.
A;
52 if( aSegA.
A == aSegB.
A || aSegA.
A == aSegB.
B )
56 else if( aSegA.
B == aSegB.
A || aSegA.
B == aSegB.
B )
67 const std::array<VECTOR2I, 4> corners = {
75 SEG{ corners[0], corners[1] },
76 SEG{ corners[1], corners[2] },
77 SEG{ corners[2], corners[3] },
78 SEG{ corners[3], corners[0] },
146 std::optional<VECTOR2I> ptA, ptB;
148 for(
const SEG& boxSeg : boxSegs )
158 if( !ptA || *intersection == *ptA )
172 return SEG( *ptA, *ptB );
177 if( ptA && *ptA != aRay.
GetStart() )
192 std::optional<VECTOR2I> ptA, ptB;
194 for(
const SEG& boxSeg : boxSegs )
199 if( intersection && boxSeg.Contains( *intersection ) )
202 if( !ptA || *intersection == *ptA )
217 return SEG( *ptA, *ptB );
252 default: wxFAIL_MSG(
"Invalid direction" );
return SHAPE_ARC();
286 default: wxFAIL_MSG(
"Invalid direction" );
308 return nw +
VECTOR2I( -aOutset, -aOutset );
316 wxFAIL_MSG(
"Invalid direction" );
325 std::vector<TYPED_POINT2I> pts;
340 pt.m_point += aCircle.
Center;
351 const auto handleSegment = [&](
const SEG& aSeg )
353 const VECTOR2I p0( aSeg.A.x, aSeg.B.y );
354 const VECTOR2I p1( aSeg.B.x, aSeg.A.y );
356 raOutline.
Append( aSeg.A );
365 handleSegment( aPoly.
CSegment( i ) );
constexpr coord_type GetLeft() const
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
constexpr coord_type GetBottom() const
Represent basic circle geometry with utility geometry functions.
VECTOR2I Center
Public to make access simpler.
int Radius
Public to make access simpler.
Directions
Available directions, there are 8 of them, as on a rectilinear map (north = up) + an extra undefined ...
OPT_VECTOR2I Intersect(const SEG &aSeg) const
const VECTOR2I & GetStart() const
Get the start point of the ray.
OPT_VECTOR2I Intersect(const SEG &aOther) const
SEG Reversed() const
Returns the center point of the line.
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const override
Check if point aP lies inside a closed shape.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsClosed() const override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Simplify(int aMaxError=0)
Simplify the line chain by removing colinear adjacent segments and duplicate vertices.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
const VECTOR2I & GetPosition() const
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_180
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.
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 connec...
std::vector< SEG > GetSegsInDirection(const BOX2I &aBox, DIRECTION_45::Directions aDir)
Get the segments of a box that are in the given direction.
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.
std::array< SEG, 4 > BoxToSegs(const BOX2I &aBox)
Decompose a BOX2 into four segments.
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 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 giv...
SHAPE_LINE_CHAIN RectifyPolygon(const SHAPE_LINE_CHAIN &aPoly)
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 give...
void CollectBoxCorners(const BOX2I &aBox, std::vector< VECTOR2I > &aCorners)
Add the 4 corners of a BOX2I to a vector.
const VECTOR2I & GetOtherEnd(const SEG &aSeg, const VECTOR2I &aPoint)
Get the end point of the segment that is not the given point.
@ PT_CENTER
The point is the center of something.
@ PT_QUADRANT
The point is on a quadrant of a circle (N, E, S, W points).
std::optional< VECTOR2I > OPT_VECTOR2I
Utility functions for working with shapes.
VECTOR2< int32_t > VECTOR2I
constexpr int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)