20#ifndef POLY_YSTRIPES_INDEX_H
21#define POLY_YSTRIPES_INDEX_H
69 for(
int outlineIdx = 0; outlineIdx <
m_outlineCount; outlineIdx++ )
73 for(
int holeIdx = 0; holeIdx < aPolySet.
HoleCount( outlineIdx ); holeIdx++ )
82 int64_t yMin = INT_MAX;
83 int64_t yMax = INT_MIN;
85 for(
int outlineIdx = 0; outlineIdx <
m_outlineCount; outlineIdx++ )
92 for(
int j = 0; j < ptCount; j++ )
100 m_edges.push_back( { p1, p2, outlineIdx,
false } );
102 yMin = std::min( yMin,
static_cast<int64_t
>( std::min( p1.
y, p2.
y ) ) );
103 yMax = std::max( yMax,
static_cast<int64_t
>( std::max( p1.
y, p2.
y ) ) );
107 for(
int holeIdx = 0; holeIdx < aPolySet.
HoleCount( outlineIdx ); holeIdx++ )
112 if( holePtCount < 3 )
115 for(
int j = 0; j < holePtCount; j++ )
123 m_edges.push_back( { p1, p2, outlineIdx,
true } );
125 yMin = std::min( yMin,
static_cast<int64_t
>( std::min( p1.
y, p2.
y ) ) );
126 yMax = std::max( yMax,
static_cast<int64_t
>( std::max( p1.
y, p2.
y ) ) );
134 int stripeCount =
static_cast<int>( std::sqrt(
static_cast<double>(
m_edges.size() ) ) );
135 stripeCount = std::max( 1, std::min( stripeCount, 65536 ) );
139 int64_t yRange = yMax - yMin;
155 for(
size_t i = 0; i <
m_edges.size(); i++ )
158 int64_t eYMin = std::min(
static_cast<int64_t
>( e.
p1.
y ),
159 static_cast<int64_t
>( e.
p2.
y ) );
160 int64_t eYMax = std::max(
static_cast<int64_t
>( e.
p1.
y ),
161 static_cast<int64_t
>( e.
p2.
y ) );
166 for(
int s = sMin; s <= sMax; s++ )
189 int stripe =
yToStripe(
static_cast<int64_t
>( aPt.
y ) );
193 int crossingsStack[8] = {};
194 int* crossings = crossingsStack;
195 std::vector<int> crossingsHeap;
200 crossings = crossingsHeap.data();
209 if( ( p1.
y >= aPt.
y ) == ( p2.
y >= aPt.
y ) )
213 const int d =
rescale( diff.
x, ( aPt.
y - p1.
y ), diff.
y );
215 if( aPt.
x - p1.
x < d )
221 if( crossings[i] & 1 )
228 int sMin =
yToStripe(
static_cast<int64_t
>( aPt.
y ) - aAccuracy );
229 int sMax =
yToStripe(
static_cast<int64_t
>( aPt.
y ) + aAccuracy );
232 for(
int s = sMin; s <= sMax; s++ )
258 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