38 return static_cast<double>( aSeg.
TCoef( aPoint ) ) / length;
54 return ( aSeg.
A == aPoint ) ? aSeg.
B : aSeg.
A;
60 if( aSegA.
A == aSegB.
A || aSegA.
A == aSegB.
B )
64 else if( aSegA.
B == aSegB.
A || aSegA.
B == aSegB.
B )
75 const std::array<VECTOR2I, 4> corners = {
83 SEG{ corners[0], corners[1] },
84 SEG{ corners[1], corners[2] },
85 SEG{ corners[2], corners[3] },
86 SEG{ corners[3], corners[0] },
168 std::optional<VECTOR2I> ptA, ptB;
170 for(
const SEG& boxSeg : boxSegs )
180 if( !ptA || *intersection == *ptA )
194 return SEG( *ptA, *ptB );
199 if( ptA && *ptA != aRay.
GetStart() )
214 std::optional<VECTOR2I> ptA, ptB;
216 for(
const SEG& boxSeg : boxSegs )
221 if( intersection && boxSeg.Contains( *intersection ) )
224 if( !ptA || *intersection == *ptA )
239 return SEG( *ptA, *ptB );
274 default: wxFAIL_MSG(
"Invalid direction" );
return SHAPE_ARC();
308 default: wxFAIL_MSG(
"Invalid direction" );
330 return nw +
VECTOR2I( -aOutset, -aOutset );
338 wxFAIL_MSG(
"Invalid direction" );
347 std::vector<TYPED_POINT2I> pts;
362 pt.m_point += aCircle.
Center;
373 const auto handleSegment = [&](
const SEG& aSeg )
375 const VECTOR2I p0( aSeg.A.x, aSeg.B.y );
376 const VECTOR2I p1( aSeg.B.x, aSeg.A.y );
378 raOutline.
Append( aSeg.A );
387 handleSegment( aPoly.
CSegment( i ) );
405 if( aHole.PointCount() < 3 || aHole.Area() == 0 )
410 aOutline.
AddHole( std::move( aHole ) );
419 std::vector<VECTOR2I> pts;
421 for(
size_t i = 0; i < aN; i++ )
424 pts.push_back(
KiROUND( pt + aCenter ) );
432 int aRadius,
bool aAcrossCorners,
435 if( !aAcrossCorners )
438 aRadius = aRadius / (
FULL_CIRCLE / ( aN * 2 ) ).Cos();
449 std::vector<SEG> segs;
452 segs.emplace_back( pt0, aCenter - ( pt0 - aCenter ) );
455 segs.emplace_back( pt0, aCenter - ( pt0 - aCenter ) );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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
VECTOR2I::extended_type ecoord
ecoord TCoef(const VECTOR2I &aP) const
ecoord SquaredLength() const
SEG Reversed() const
Returns the center point of the line.
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.
int PointCount() const
Return the number of points (vertices) in this line chain.
void Simplify(int aTolerance=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 VECTOR2I & CLastPoint() const
Return the last point in the line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const override
Check if point aP lies inside a closed shape.
Represent a set of closed polygons.
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index.
int GetWidth() const override
const VECTOR2I & GetPosition() const
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE FULL_CIRCLE
static constexpr EDA_ANGLE ANGLE_180
bool AddHoleIfValid(SHAPE_POLY_SET &aOutline, SHAPE_LINE_CHAIN &&aHole)
Adds a hole to a polygon if it is valid (i.e.
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.
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.
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::vector< SEG > MakeCrossSegments(const VECTOR2I &aCenter, const VECTOR2I &aSize, EDA_ANGLE aAngle)
Create the two segments for a cross.
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...
SHAPE_LINE_CHAIN BoxToLineChain(const BOX2I &aBox)
double ParameterAlong(const SEG &aSeg, const VECTOR2I &aPoint)
Position of a point along a segment.
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.
wxString result
Test unit parsing edge cases and error handling.
VECTOR2I GetRotated(const VECTOR2I &aVector, const EDA_ANGLE &aAngle)
Return a new VECTOR2I that is the result of rotating aVector by aAngle.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
constexpr int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)