24#ifndef POLY_YSTRIPES_INDEX_H
25#define POLY_YSTRIPES_INDEX_H
73 for(
int outlineIdx = 0; outlineIdx <
m_outlineCount; outlineIdx++ )
77 for(
int holeIdx = 0; holeIdx < aPolySet.
HoleCount( outlineIdx ); holeIdx++ )
86 int64_t yMin = INT_MAX;
87 int64_t yMax = INT_MIN;
89 for(
int outlineIdx = 0; outlineIdx <
m_outlineCount; outlineIdx++ )
96 for(
int j = 0; j < ptCount; j++ )
104 m_edges.push_back( { p1, p2, outlineIdx,
false } );
106 yMin = std::min( yMin,
static_cast<int64_t
>( std::min( p1.
y, p2.
y ) ) );
107 yMax = std::max( yMax,
static_cast<int64_t
>( std::max( p1.
y, p2.
y ) ) );
111 for(
int holeIdx = 0; holeIdx < aPolySet.
HoleCount( outlineIdx ); holeIdx++ )
116 if( holePtCount < 3 )
119 for(
int j = 0; j < holePtCount; j++ )
127 m_edges.push_back( { p1, p2, outlineIdx,
true } );
129 yMin = std::min( yMin,
static_cast<int64_t
>( std::min( p1.
y, p2.
y ) ) );
130 yMax = std::max( yMax,
static_cast<int64_t
>( std::max( p1.
y, p2.
y ) ) );
138 int stripeCount =
static_cast<int>( std::sqrt(
static_cast<double>(
m_edges.size() ) ) );
139 stripeCount = std::max( 1, std::min( stripeCount, 65536 ) );
143 int64_t yRange = yMax - yMin;
159 for(
size_t i = 0; i <
m_edges.size(); i++ )
162 int64_t eYMin = std::min(
static_cast<int64_t
>( e.
p1.
y ),
163 static_cast<int64_t
>( e.
p2.
y ) );
164 int64_t eYMax = std::max(
static_cast<int64_t
>( e.
p1.
y ),
165 static_cast<int64_t
>( e.
p2.
y ) );
170 for(
int s = sMin; s <= sMax; s++ )
193 int stripe =
yToStripe(
static_cast<int64_t
>( aPt.
y ) );
197 int crossingsStack[8] = {};
198 int* crossings = crossingsStack;
199 std::vector<int> crossingsHeap;
204 crossings = crossingsHeap.data();
213 if( ( p1.
y >= aPt.
y ) == ( p2.
y >= aPt.
y ) )
217 const int d =
rescale( diff.
x, ( aPt.
y - p1.
y ), diff.
y );
219 if( aPt.
x - p1.
x < d )
225 if( crossings[i] & 1 )
232 int sMin =
yToStripe(
static_cast<int64_t
>( aPt.
y ) - aAccuracy );
233 int sMax =
yToStripe(
static_cast<int64_t
>( aPt.
y ) + aAccuracy );
236 for(
int s = sMin; s <= sMax; s++ )
262 int64_t offset = aY -
m_yMin;
int yToStripe(int64_t aY) const
std::vector< EDGE > m_edges
bool Contains(const VECTOR2I &aPt, int aAccuracy=0) const
Test whether a point is inside the indexed polygon set.
POLY_YSTRIPES_INDEX()=default
std::vector< std::vector< int > > m_stripes
void Build(const SHAPE_POLY_SET &aPolySet)
Build the spatial index from a SHAPE_POLY_SET's outlines and holes.
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 HoleCount(int aOutline) const
Returns the number of holes in a given outline.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
table push_back({ "Source", "Layer", "Vertices", "Strategy", "Build(us)", "ns/query", "Mquery/s", "Inside" })
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).
VECTOR2< int32_t > VECTOR2I