24#ifndef POLY_CONTAINMENT_INDEX_H
25#define POLY_CONTAINMENT_INDEX_H
66 for(
int outlineIdx = 0; outlineIdx <
m_outlineCount; outlineIdx++ )
74 for(
int j = 0; j < ptCount; j++ )
79 intptr_t idx =
static_cast<intptr_t
>(
m_segments.size() );
80 m_segments.push_back( { p1, p2, outlineIdx } );
82 int min[2] = { std::min( p1.
x, p2.
x ), std::min( p1.
y, p2.
y ) };
83 int max[2] = { std::max( p1.
x, p2.
x ), std::max( p1.
y, p2.
y ) };
84 builder.
Add( min, max, idx );
111 int crossingsStack[8] = {};
112 int* crossings = crossingsStack;
113 std::vector<int> crossingsHeap;
118 crossings = crossingsHeap.data();
122 int searchMin[2] = { aPt.
x, aPt.
y };
123 int searchMax[2] = { INT_MAX, aPt.
y };
125 auto rayCrossVisitor = [&]( intptr_t idx ) ->
bool
131 if( ( p1.
y >= aPt.
y ) == ( p2.
y >= aPt.
y ) )
135 const int d =
rescale( diff.
x, ( aPt.
y - p1.
y ), diff.
y );
137 if( aPt.
x - p1.
x < d )
143 m_tree.Search( searchMin, searchMax, rayCrossVisitor );
147 if( crossings[i] & 1 )
153 int edgeMin[2] = { aPt.
x - aAccuracy, aPt.
y - aAccuracy };
154 int edgeMax[2] = { aPt.
x + aAccuracy, aPt.
y + aAccuracy };
158 auto edgeDistVisitor = [&]( intptr_t idx ) ->
bool
172 m_tree.Search( edgeMin, edgeMax, edgeDistVisitor );
Builder for constructing a PACKED_RTREE from a set of items.
void Add(const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], const DATATYPE &aData)
Static (immutable) packed R-tree built via Hilbert-curve bulk loading.
void Build(const SHAPE_POLY_SET &aPolySet)
Build the spatial index from a SHAPE_POLY_SET's outlines.
POLY_CONTAINMENT_INDEX()=default
KIRTREE::PACKED_RTREE< intptr_t, int, 2 > m_tree
bool Contains(const VECTOR2I &aPt, int aAccuracy=0) const
Test whether a point is inside the indexed polygon set.
std::vector< EDGE > m_segments
ecoord SquaredDistance(const SEG &aSeg) const
VECTOR2I::extended_type ecoord
static SEG::ecoord Square(int a)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).
VECTOR2< int32_t > VECTOR2I