Horizon
|
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc segments. More...
#include <shape_line_chain.h>
Classes | |
struct | compareOriginDistance |
struct | INTERSECTION |
Represent an intersection between two line segments. More... | |
class | POINT_INSIDE_TRACKER |
A dynamic state checking if a point lies within polygon with a dynamically built outline ( with each piece of the outline added by AddPolyline () More... | |
Public Types | |
typedef std::vector< INTERSECTION > | INTERSECTIONS |
Public Member Functions | |
SHAPE_LINE_CHAIN () | |
Initialize an empty line chain. | |
SHAPE_LINE_CHAIN (const SHAPE_LINE_CHAIN &aShape) | |
SHAPE_LINE_CHAIN (const std::vector< int > &aV) | |
SHAPE_LINE_CHAIN (const std::vector< wxPoint > &aV, bool aClosed=false) | |
SHAPE_LINE_CHAIN (const std::vector< VECTOR2I > &aV, bool aClosed=false) | |
SHAPE_LINE_CHAIN (const SHAPE_ARC &aArc, bool aClosed=false) | |
SHAPE_LINE_CHAIN (const ClipperLibKiCad::Path &aPath, const std::vector< CLIPPER_Z_VALUE > &aZValueBuffer, const std::vector< SHAPE_ARC > &aArcBuffer) | |
virtual bool | Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override |
Check if point aP lies closer to us than aClearance. | |
virtual bool | Collide (const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override |
Check if segment aSeg lies closer to us than aClearance. | |
SHAPE_LINE_CHAIN & | operator= (const SHAPE_LINE_CHAIN &)=default |
SHAPE * | Clone () const override |
Return a dynamically allocated copy of the shape. | |
void | Clear () |
Remove all points from the line chain. | |
void | SetClosed (bool aClosed) |
Mark the line chain as closed (i.e. | |
bool | IsClosed () const override |
void | SetWidth (int aWidth) |
Set the width of all segments in the chain. | |
int | Width () const |
Get the current width of the segments in the chain. | |
int | SegmentCount () const |
Return the number of segments in this line chain. | |
int | ShapeCount () const |
Return the number of shapes (line segments or arcs) in this line chain. | |
int | PointCount () const |
Return the number of points (vertices) in this line chain. | |
SEG | Segment (int aIndex) |
Return a copy of the aIndex-th segment in the line chain. | |
const SEG | CSegment (int aIndex) const |
Return a constant copy of the aIndex segment in the line chain. | |
int | NextShape (int aPointIndex, bool aForwards=true) const |
Return the vertex index of the next shape in the chain, or -1 if aPointIndex is the last shape. | |
int | PrevShape (int aPointIndex) const |
void | SetPoint (int aIndex, const VECTOR2I &aPos) |
Move a point to a specific location. | |
const VECTOR2I & | CPoint (int aIndex) const |
Return a reference to a given point in the line chain. | |
const std::vector< VECTOR2I > & | CPoints () const |
const VECTOR2I & | CLastPoint () const |
Return the last point in the line chain. | |
const std::vector< SHAPE_ARC > & | CArcs () const |
const std::vector< std::pair< ssize_t, ssize_t > > & | CShapes () const |
const BOX2I | BBox (int aClearance=0) const override |
Compute a bounding box of the shape, with a margin of aClearance a collision. | |
void | GenerateBBoxCache () const |
BOX2I * | GetCachedBBox () const override |
int | Distance (const VECTOR2I &aP, bool aOutlineOnly=false) const |
Compute the minimum distance between the line chain and a point aP. | |
const SHAPE_LINE_CHAIN | Reverse () const |
Reverse point order in the line chain. | |
void | ClearArcs () |
Remove all arc references in the line chain, resulting in a chain formed only of straight segments. | |
long long int | Length () const |
Return length of the line chain in Euclidean metric. | |
void | Append (int aX, int aY, bool aAllowDuplication=false) |
Append a new point at the end of the line chain. | |
void | Append (const VECTOR2I &aP, bool aAllowDuplication=false) |
Append a new point at the end of the line chain. | |
void | Append (const SHAPE_LINE_CHAIN &aOtherLine) |
Append another line chain at the end. | |
void | Append (const SHAPE_ARC &aArc) |
void | Insert (size_t aVertex, const VECTOR2I &aP) |
void | Insert (size_t aVertex, const SHAPE_ARC &aArc) |
void | Replace (int aStartIndex, int aEndIndex, const VECTOR2I &aP) |
Replace points with indices in range [start_index, end_index] with a single point aP. | |
void | Replace (int aStartIndex, int aEndIndex, const SHAPE_LINE_CHAIN &aLine) |
Replace points with indices in range [start_index, end_index] with the points from line chain aLine. | |
void | Remove (int aStartIndex, int aEndIndex) |
Remove the range of points [start_index, end_index] from the line chain. | |
void | Remove (int aIndex) |
Remove the aIndex-th point from the line chain. | |
void | RemoveShape (int aPointIndex) |
Remove the shape at the given index from the line chain. | |
int | Split (const VECTOR2I &aP) |
Insert the point aP belonging to one of the our segments, splitting the adjacent segment in two. | |
int | Find (const VECTOR2I &aP, int aThreshold=0) const |
Search for point aP. | |
int | FindSegment (const VECTOR2I &aP, int aThreshold=1) const |
Search for segment containing point aP. | |
const SHAPE_LINE_CHAIN | Slice (int aStartIndex, int aEndIndex=-1) const |
Return a subset of this line chain containing the [start_index, end_index] range of points. | |
bool | Intersects (const SHAPE_LINE_CHAIN &aChain) const |
int | Intersect (const SEG &aSeg, INTERSECTIONS &aIp) const |
Find all intersection points between our line chain and the segment aSeg. | |
int | Intersect (const SHAPE_LINE_CHAIN &aChain, INTERSECTIONS &aIp, bool aExcludeColinearAndTouching=false) const |
Find all intersection points between our line chain and the line chain aChain. | |
int | PathLength (const VECTOR2I &aP, int aIndex=-1) const |
Compute the walk path length from the beginning of the line chain and the point aP belonging to our line. | |
bool | CheckClearance (const VECTOR2I &aP, const int aDist) const |
Check if point aP is closer to (or on) an edge or vertex of the line chain. | |
const std::optional< INTERSECTION > | SelfIntersecting () const |
Check if the line chain is self-intersecting. | |
SHAPE_LINE_CHAIN & | Simplify (bool aRemoveColinear=true) |
Simplify the line chain by removing colinear adjacent segments and duplicate vertices. | |
int | NearestSegment (const VECTOR2I &aP) const |
Find the segment nearest the given point. | |
const VECTOR2I | NearestPoint (const VECTOR2I &aP, bool aAllowInternalShapePoints=true) const |
Find a point on the line chain that is closest to point aP. | |
const VECTOR2I | NearestPoint (const SEG &aSeg, int &dist) const |
Find a point on the line chain that is closest to the line defined by the points of segment aSeg, also returns the distance. | |
const std::string | Format () const override |
bool | Parse (std::stringstream &aStream) override |
bool | operator!= (const SHAPE_LINE_CHAIN &aRhs) const |
bool | CompareGeometry (const SHAPE_LINE_CHAIN &aOther) const |
void | Move (const VECTOR2I &aVector) override |
void | Mirror (bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 }) |
Mirror the line points about y or x (or both). | |
void | Mirror (const SEG &axis) |
Mirror the line points using an given axis. | |
void | Rotate (double aAngle, const VECTOR2I &aCenter=VECTOR2I(0, 0)) override |
Rotate all vertices by a given angle. | |
bool | IsSolid () const override |
const VECTOR2I | PointAlong (int aPathLength) const |
double | Area (bool aAbsolute=true) const |
Return the area of this chain. | |
size_t | ArcCount () const |
ssize_t | ArcIndex (size_t aSegment) const |
Return the arc index for the given segment index. | |
const SHAPE_ARC & | Arc (size_t aArc) const |
bool | IsSharedPt (size_t aIndex) const |
Test if a point is shared between multiple shapes. | |
bool | IsPtOnArc (size_t aPtIndex) const |
bool | IsArcSegment (size_t aSegment) const |
bool | IsArcStart (size_t aIndex) const |
bool | IsArcEnd (size_t aIndex) const |
virtual const VECTOR2I | GetPoint (int aIndex) const override |
virtual const SEG | GetSegment (int aIndex) const override |
virtual size_t | GetPointCount () const override |
virtual size_t | GetSegmentCount () const override |
![]() | |
SHAPE_LINE_CHAIN_BASE (SHAPE_TYPE aType) | |
SEG::ecoord | SquaredDistance (const VECTOR2I &aP, bool aOutlineOnly=false) const |
bool | PointInside (const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const |
Check if point aP lies inside a polygon (any type) defined by the line chain. | |
bool | PointOnEdge (const VECTOR2I &aP, int aAccuracy=0) const |
Check if point aP lies on an edge or vertex of the line chain. | |
int | EdgeContainingPoint (const VECTOR2I &aP, int aAccuracy=0) const |
Check if point aP lies on an edge or vertex of the line chain. | |
![]() | |
SHAPE (SHAPE_TYPE aType) | |
Create an empty shape of type aType. | |
bool | IsNull () const |
Return true if the shape is a null shape. | |
virtual bool | Collide (const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const |
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision. | |
virtual bool | Collide (const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const |
virtual VECTOR2I | Centre () const |
Compute a center-of-mass of the shape. | |
![]() | |
SHAPE_BASE (SHAPE_TYPE aType) | |
Create an empty shape of type aType. | |
SHAPE_TYPE | Type () const |
Return the type of the shape. | |
virtual bool | HasIndexableSubshapes () const |
virtual size_t | GetIndexableSubshapeCount () const |
virtual void | GetIndexableSubshapes (std::vector< SHAPE * > &aSubshapes) |
Protected Member Functions | |
void | convertArc (ssize_t aArcIndex) |
Convert an arc to only a point chain by removing the arc and references. | |
void | splitArc (ssize_t aPtIndex, bool aCoincident=false) |
Splits an arc into two arcs at aPtIndex. | |
void | amendArc (size_t aArcIndex, const VECTOR2I &aNewStart, const VECTOR2I &aNewEnd) |
void | amendArcStart (size_t aArcIndex, const VECTOR2I &aNewStart) |
void | amendArcEnd (size_t aArcIndex, const VECTOR2I &aNewEnd) |
ssize_t | reversedArcIndex (size_t aSegment) const |
Return the arc index for the given segment index, looking backwards. | |
ClipperLibKiCad::Path | convertToClipper (bool aRequiredOrientation, std::vector< CLIPPER_Z_VALUE > &aZValueBuffer, std::vector< SHAPE_ARC > &aArcBuffer) const |
Create a new Clipper path from the SHAPE_LINE_CHAIN in a given orientation. | |
void | fixIndicesRotation () |
Fix indices of this chain to ensure arcs are not split between the end and start indices. | |
void | mergeFirstLastPointIfNeeded () |
Merge the first and last point if they are the same and this chain is closed. | |
Friends | |
class | SHAPE_POLY_SET |
Additional Inherited Members | |
![]() | |
static const int | MIN_PRECISION_IU = 4 |
This is the minimum precision for all the points in a shape. | |
![]() | |
typedef VECTOR2I::extended_type | ecoord |
![]() | |
SHAPE_TYPE | m_type |
< type of our shape | |
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc segments.
The arc shapes are piecewise approximated for the purpose of boolean operations but are used as arcs when doing collision checks.
It is purposely not named "polyline" to avoid confusion with the existing CPolyLine in Pcbnew.
void SHAPE_LINE_CHAIN::Append | ( | const SHAPE_LINE_CHAIN & | aOtherLine | ) |
Append another line chain at the end.
aOtherLine | is the line chain to be appended. |
|
inline |
Append a new point at the end of the line chain.
aP | is the new point. |
aAllowDuplication | set to true to append the new point even it is the same as the last entered point or false (default) to skip it if it is the same as the last entered point. |
|
inline |
Append a new point at the end of the line chain.
aX | is X coordinate of the new point. |
aY | is Y coordinate of the new point. |
aAllowDuplication | set to true to append the new point even if it is the same as the last entered point, false (default) to skip it if it is the same as the last entered point. |
double SHAPE_LINE_CHAIN::Area | ( | bool | aAbsolute = true | ) | const |
Return the area of this chain.
aAbsolute | If true, returns a positive value. Otherwise the value depends on the orientation of the chain |
|
inlineoverridevirtual |
Compute a bounding box of the shape, with a margin of aClearance a collision.
aClearance | how much the bounding box is expanded wrs to the minimum enclosing rectangle for the shape. |
Implements SHAPE.
|
inline |
bool SHAPE_LINE_CHAIN::CheckClearance | ( | const VECTOR2I & | aP, |
const int | aDist | ||
) | const |
Check if point aP is closer to (or on) an edge or vertex of the line chain.
aP | is the point to check. |
aDist | is the distance in internal units. |
void SHAPE_LINE_CHAIN::ClearArcs | ( | ) |
Remove all arc references in the line chain, resulting in a chain formed only of straight segments.
Any arcs in the chain are removed and only the piecewise linear approximation remains.
|
overridevirtual |
Return a dynamically allocated copy of the shape.
copy | of the shape |
Reimplemented from SHAPE.
|
overridevirtual |
Check if segment aSeg lies closer to us than aClearance.
Note: This is overridden as we want to ensure we test collisions with the arcs in this chain as true arcs rather than segment approximations.
aSeg | the segment to check for collisions with |
aClearance | minimum distance that does not qualify as a collision. |
aActual | an optional pointer to an int to store the actual distance in the event of a collision. |
Reimplemented from SHAPE_LINE_CHAIN_BASE.
|
overridevirtual |
Check if point aP lies closer to us than aClearance.
Note: This is overridden as we want to ensure we test collisions with the arcs in this chain as true arcs rather than segment approximations.
aP | the point to check for collisions with |
aClearance | minimum distance that does not qualify as a collision. |
aActual | an optional pointer to an int to store the actual distance in the event of a collision. |
Reimplemented from SHAPE_LINE_CHAIN_BASE.
|
protected |
Convert an arc to only a point chain by removing the arc and references.
aArcIndex | index of the arc to convert to points |
|
inline |
Return a reference to a given point in the line chain.
aIndex | is the index of the point. |
|
inline |
Return a constant copy of the aIndex segment in the line chain.
aIndex | is the index of the segment in the line chain. Negative values are counted from the end (i.e. -1 means the last segment in the line chain). |
|
inline |
int SHAPE_LINE_CHAIN::Distance | ( | const VECTOR2I & | aP, |
bool | aOutlineOnly = false |
||
) | const |
Compute the minimum distance between the line chain and a point aP.
aP | the point. |
int SHAPE_LINE_CHAIN::Find | ( | const VECTOR2I & | aP, |
int | aThreshold = 0 |
||
) | const |
Search for point aP.
aP | is the point to be looked for. |
int SHAPE_LINE_CHAIN::FindSegment | ( | const VECTOR2I & | aP, |
int | aThreshold = 1 |
||
) | const |
Search for segment containing point aP.
aP | is the point to be looked for. |
|
overridevirtual |
Reimplemented from SHAPE.
|
inlineoverridevirtual |
Reimplemented from SHAPE_LINE_CHAIN_BASE.
|
inlineoverridevirtual |
Implements SHAPE_LINE_CHAIN_BASE.
|
inlineoverridevirtual |
Implements SHAPE_LINE_CHAIN_BASE.
|
inlineoverridevirtual |
Implements SHAPE_LINE_CHAIN_BASE.
|
inlineoverridevirtual |
Implements SHAPE_LINE_CHAIN_BASE.
void SHAPE_LINE_CHAIN::Insert | ( | size_t | aVertex, |
const SHAPE_ARC & | aArc | ||
) |
Step 1: Find the position for the new arc in the existing arc vector
Step 2: Add the arc polyline points to the chain
Step 3: Add the vector of indices to the shape vector
int SHAPE_LINE_CHAIN::Intersect | ( | const SEG & | aSeg, |
INTERSECTIONS & | aIp | ||
) | const |
Find all intersection points between our line chain and the segment aSeg.
aSeg | is the segment chain to find intersections with. |
aIp | is the reference to a vector to store found intersections. Intersection points are sorted with increasing distances from point aSeg.a. |
int SHAPE_LINE_CHAIN::Intersect | ( | const SHAPE_LINE_CHAIN & | aChain, |
INTERSECTIONS & | aIp, | ||
bool | aExcludeColinearAndTouching = false |
||
) | const |
Find all intersection points between our line chain and the line chain aChain.
aChain | is the line chain to find intersections with. |
aIp | is reference to a vector to store found intersections. Intersection points are sorted with increasing path lengths from the starting point of aChain. |
|
inlineoverridevirtual |
Implements SHAPE_LINE_CHAIN_BASE.
|
inline |
Test if a point is shared between multiple shapes.
aIndex |
|
inlineoverridevirtual |
Implements SHAPE.
long long int SHAPE_LINE_CHAIN::Length | ( | ) | const |
Return length of the line chain in Euclidean metric.
void SHAPE_LINE_CHAIN::Mirror | ( | bool | aX = true , |
bool | aY = false , |
||
const VECTOR2I & | aRef = { 0, 0 } |
||
) |
Mirror the line points about y or x (or both).
aX | If true, mirror about the y axis (flip X coordinate). |
aY | If true, mirror about the x axis (flip Y coordinate). |
aRef | sets the reference point about which to mirror. |
void SHAPE_LINE_CHAIN::Mirror | ( | const SEG & | axis | ) |
Mirror the line points using an given axis.
axis | is the axis on which to mirror. |
Find a point on the line chain that is closest to the line defined by the points of segment aSeg, also returns the distance.
aSeg | is the segment defining the line. |
dist | is the reference receiving the distance to the nearest point. |
const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint | ( | const VECTOR2I & | aP, |
bool | aAllowInternalShapePoints = true |
||
) | const |
Find a point on the line chain that is closest to point aP.
aP | is the point to find. |
aAllowInternalShapePoints | if false will not return points internal to an arc (i.e. only the arc endpoints are possible candidates) |
int SHAPE_LINE_CHAIN::NearestSegment | ( | const VECTOR2I & | aP | ) | const |
Find the segment nearest the given point.
aP | is the point to compare with. |
int SHAPE_LINE_CHAIN::NextShape | ( | int | aPointIndex, |
bool | aForwards = true |
||
) | const |
Return the vertex index of the next shape in the chain, or -1 if aPointIndex is the last shape.
If aPointIndex is the start of a segment, this will be ( aPointIndex + 1 ). If aPointIndex is part of an arc, this will be the index of the start of the next shape after the arc, in other words, the last point of the arc.
aPointIndex | is a vertex in the chain. |
aForwards | is true if the next shape is desired, false for previous shape. |
|
overridevirtual |
Reimplemented from SHAPE.
int SHAPE_LINE_CHAIN::PathLength | ( | const VECTOR2I & | aP, |
int | aIndex = -1 |
||
) | const |
Compute the walk path length from the beginning of the line chain and the point aP belonging to our line.
|
inline |
Return the number of points (vertices) in this line chain.
|
inline |
Remove the aIndex-th point from the line chain.
aIndex | is the index of the point to be removed. |
void SHAPE_LINE_CHAIN::Remove | ( | int | aStartIndex, |
int | aEndIndex | ||
) |
Remove the range of points [start_index, end_index] from the line chain.
aStartIndex | is the start of the point range to be replaced (inclusive). |
aEndIndex | is the end of the point range to be replaced (inclusive). |
void SHAPE_LINE_CHAIN::RemoveShape | ( | int | aPointIndex | ) |
Remove the shape at the given index from the line chain.
If the given index is inside an arc, the entire arc will be removed. Otherwise this is equivalent to Remove( aPointIndex ).
aPointIndex | is the index of the point to remove. |
void SHAPE_LINE_CHAIN::Replace | ( | int | aStartIndex, |
int | aEndIndex, | ||
const SHAPE_LINE_CHAIN & | aLine | ||
) |
Replace points with indices in range [start_index, end_index] with the points from line chain aLine.
aStartIndex | is the start of the point range to be replaced (inclusive). |
aEndIndex | is the end of the point range to be replaced (inclusive). |
aLine | is the replacement line chain. |
void SHAPE_LINE_CHAIN::Replace | ( | int | aStartIndex, |
int | aEndIndex, | ||
const VECTOR2I & | aP | ||
) |
Replace points with indices in range [start_index, end_index] with a single point aP.
aStartIndex | is the start of the point range to be replaced (inclusive). |
aEndIndex | is the end of the point range to be replaced (inclusive). |
aP | is the replacement point. |
const SHAPE_LINE_CHAIN SHAPE_LINE_CHAIN::Reverse | ( | ) | const |
Reverse point order in the line chain.
|
overridevirtual |
Rotate all vertices by a given angle.
aCenter | is the rotation center. |
aAngle | is the rotation angle in radians. |
Implements SHAPE.
|
inline |
Return a copy of the aIndex-th segment in the line chain.
aIndex | is the index of the segment in the line chain. Negative values are counted from the end (i.e. -1 means the last segment in the line chain). |
|
inline |
Return the number of segments in this line chain.
const std::optional< SHAPE_LINE_CHAIN::INTERSECTION > SHAPE_LINE_CHAIN::SelfIntersecting | ( | ) | const |
Check if the line chain is self-intersecting.
|
inline |
Mark the line chain as closed (i.e.
with a segment connecting the last point with the first point).
aClosed | whether the line chain is to be closed or not. |
void SHAPE_LINE_CHAIN::SetPoint | ( | int | aIndex, |
const VECTOR2I & | aPos | ||
) |
Move a point to a specific location.
aIndex | is the index of the point to move. |
aPos | is the new absolute location of the point. |
|
inline |
Set the width of all segments in the chain.
aWidth | is the width in internal units. |
int SHAPE_LINE_CHAIN::ShapeCount | ( | ) | const |
Return the number of shapes (line segments or arcs) in this line chain.
This is kind of like SegmentCount() but will only count arcs as 1 segment.
SHAPE_LINE_CHAIN & SHAPE_LINE_CHAIN::Simplify | ( | bool | aRemoveColinear = true | ) |
Simplify the line chain by removing colinear adjacent segments and duplicate vertices.
aRemoveColinear | controls the removal of colinear adjacent segments. |
const SHAPE_LINE_CHAIN SHAPE_LINE_CHAIN::Slice | ( | int | aStartIndex, |
int | aEndIndex = -1 |
||
) | const |
Return a subset of this line chain containing the [start_index, end_index] range of points.
aStartIndex | is the start of the point range to be returned (inclusive). |
aEndIndex | is the end of the point range to be returned (inclusive). |
int SHAPE_LINE_CHAIN::Split | ( | const VECTOR2I & | aP | ) |
Insert the point aP belonging to one of the our segments, splitting the adjacent segment in two.
aP | is the point to be inserted. |
|
protected |
Splits an arc into two arcs at aPtIndex.
Parameter aCoincident
controls whether the two arcs are to be coincident at aPtIndex or whether a short straight segment should be created instead
aPtIndex | index of the point in the chain in which to split the arc |
aCoincident | If true, the end point of the first arc will be coincident with the start point of the second arc at aPtIndex. If false, the end point of the first arc will be at aPtIndex-1 and the start point of the second arc will be at aPtIndex, resulting in a short straight line segment between aPtIndex-1 and aPtIndex. |
|
inline |
Get the current width of the segments in the chain.