|
KiCad PCB EDA Suite
|
Spatial index for efficient point-in-polygon containment testing. More...
#include <poly_containment_index.h>
Classes | |
| struct | EDGE |
Public Member Functions | |
| POLY_CONTAINMENT_INDEX ()=default | |
| void | Build (const SHAPE_POLY_SET &aPolySet) |
| Build the spatial index from a SHAPE_POLY_SET's outlines. | |
| bool | Contains (const VECTOR2I &aPt, int aAccuracy=0) const |
| Test whether a point is inside the indexed polygon set. | |
Private Attributes | |
| std::vector< EDGE > | m_segments |
| KIRTREE::PACKED_RTREE< intptr_t, int, 2 > | m_tree |
| int | m_outlineCount = 0 |
Spatial index for efficient point-in-polygon containment testing.
Standard SHAPE_LINE_CHAIN::PointInside() is O(V) per query, ray-casting against every edge. For large polygons with many containment queries (e.g. testing thousands of via positions against zone fills with tens of thousands of vertices), this becomes a bottleneck.
This class builds an R-tree of polygon edges so containment queries become O(log V + K) where K is the number of edges the horizontal ray actually crosses. The ray-crossing algorithm matches SHAPE_LINE_CHAIN_BASE::PointInside() exactly, including the accuracy semantics where aAccuracy > 1 falls back to edge-distance testing.
Definition at line 49 of file poly_containment_index.h.
|
default |
|
inline |
Build the spatial index from a SHAPE_POLY_SET's outlines.
Indexes every edge of every outline in the polygon set. Must be called before Contains(). Only indexes outlines, not holes (zone fills are fractured and have no holes).
Definition at line 60 of file poly_containment_index.h.
References KIRTREE::PACKED_RTREE< DATATYPE, ELEMTYPE, NUMDIMS, FANOUT >::Builder::Add(), KIRTREE::PACKED_RTREE< DATATYPE, ELEMTYPE, NUMDIMS, FANOUT >::Builder::Build(), SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), m_outlineCount, m_segments, m_tree, SHAPE_POLY_SET::OutlineCount(), SHAPE_LINE_CHAIN::PointCount(), VECTOR2< T >::x, and VECTOR2< T >::y.
|
inline |
Test whether a point is inside the indexed polygon set.
Uses the same ray-crossing algorithm as SHAPE_LINE_CHAIN_BASE::PointInside(). When aAccuracy > 1, also checks if the point is within aAccuracy distance of any edge (matching the PointOnEdge fallback behavior).
| aPt | The point to test. |
| aAccuracy | Distance threshold for edge-proximity fallback. Values <= 1 skip the edge test for performance. |
Definition at line 104 of file poly_containment_index.h.
References m_outlineCount, m_segments, m_tree, POLY_CONTAINMENT_INDEX::EDGE::outlineIdx, POLY_CONTAINMENT_INDEX::EDGE::p1, POLY_CONTAINMENT_INDEX::EDGE::p2, rescale(), SEG::Square(), SEG::SquaredDistance(), VECTOR2< T >::x, and VECTOR2< T >::y.
|
private |
Definition at line 190 of file poly_containment_index.h.
Referenced by Build(), and Contains().
|
private |
Definition at line 188 of file poly_containment_index.h.
Referenced by Build(), and Contains().
|
private |
Definition at line 189 of file poly_containment_index.h.
Referenced by Build(), and Contains().