34 for (uint32_t i = 0; i < itree->
numIndexes; i++)
48 uint32_t num_nodes = 0;
49 uint32_t level_nodes = 0;
52 if (!pa || pa->
npoints < 4)
return 0;
57 while(level_nodes > 1)
61 num_nodes += level_nodes;
62 level_nodes = next_level_nodes;
71 uint32_t num_nodes = 0;
72 for (uint32_t i = 0; i < poly->
nrings; i++)
83 uint32_t num_nodes = 0;
84 for (uint32_t i = 0; i < mpoly->
ngeoms; i++)
103 lwerror(
"%s ran out of node space", __func__);
122 uint32_t end_node = itree->
numNodes;
123 uint32_t start_node = end_node - nodes_remaining;
139 for (uint32_t i = 0; i < num_parents; i++)
143 children_end = children_end > end_node ? end_node : children_end;
150 for (uint32_t j = children_start; j < children_end; j++)
171 if (pt1->
x == pt2->
x && pt1->
y == pt2->
y)
175 if (isfinite(pt1->
x) &&
187 uint32_t nodes_remaining = 0;
188 uint32_t leaf_nodes = 0;
193 lwerror(
"%s called with unusable ring", __func__);
196 for (uint32_t i = 0; i < pa->
npoints-1; i++)
214 nodes_remaining = leaf_nodes;
215 while (nodes_remaining > 1)
241 if (poly->
nrings == 0)
return itree;
251 for (uint32_t j = 0; j < poly->
nrings; j++)
272 if (mpoly->
ngeoms == 0)
return itree;
282 for (uint32_t i = 0; i < mpoly->
ngeoms; i++)
290 for (uint32_t j = 0; j < poly->
nrings; j++)
312 if (!geom)
lwerror(
"%s called with null geometry", __func__);
320 lwerror(
"%s got asked to build index on non-polygon", __func__);
338 return ((seg2->
x - seg1->
x) * (point->
y - seg1->
y) -
339 (point->
x - seg1->
x) * (seg2->
y - seg1->
y));
354 double maxX =
FP_MAX(seg1->
x, seg2->
x);
355 double maxY =
FP_MAX(seg1->
y, seg2->
y);
356 double minX =
FP_MIN(seg1->
x, seg2->
x);
357 double minY =
FP_MIN(seg1->
y, seg2->
y);
359 return point->
x >= minX && point->
x <= maxX &&
360 point->
y >= minY && point->
y <= maxY;
378 if (!node_contains_value)
403 if ((seg1->
y <= pt->
y) && (pt->
y < seg2->
y) && (side > 0))
405 *winding_number = *winding_number + 1;
413 else if ((seg2->
y <= pt->
y) && (pt->
y < seg1->
y) && (side < 0))
415 *winding_number = *winding_number - 1;
437 int winding_number = 0;
446 if (winding_number == 0)
473 if (!pt || !(isfinite(pt->
x) && isfinite(pt->
y)))
477 for (uint32_t p = 0; p < itree->
numPolys; p++)
482 if (ringCount == 0)
continue;
char result[OUT_DOUBLE_BUFFER_SIZE]
static uint32_t itree_num_nodes_pointarray(const POINTARRAY *pa)
static IntervalTreeResult itree_point_in_ring(const IntervalTree *itree, uint32_t ringNumber, const POINT2D *pt)
static void itree_add_pointarray(IntervalTree *itree, const POINTARRAY *pa)
static uint32_t itree_num_rings(const LWMPOLY *mpoly)
IntervalTree * itree_from_lwgeom(const LWGEOM *geom)
static int itree_point_on_segment(const POINT2D *seg1, const POINT2D *seg2, const POINT2D *point)
static int itree_edge_invalid(const POINT2D *pt1, const POINT2D *pt2)
void itree_free(IntervalTree *itree)
static uint32_t itree_num_nodes_multipolygon(const LWMPOLY *mpoly)
static IntervalTreeResult itree_point_in_ring_recursive(const IntervalTreeNode *node, const POINTARRAY *pa, const POINT2D *pt, int *winding_number)
static uint32_t itree_merge_nodes(IntervalTree *itree, uint32_t nodes_remaining)
static IntervalTree * itree_from_multipolygon(const LWMPOLY *mpoly)
static double itree_segment_side(const POINT2D *seg1, const POINT2D *seg2, const POINT2D *point)
IntervalTreeResult itree_point_in_multipolygon(const IntervalTree *itree, const LWPOINT *point)
static IntervalTreeNode * itree_new_node(IntervalTree *itree)
static IntervalTree * itree_from_polygon(const LWPOLY *poly)
static uint32_t itree_num_nodes_polygon(const LWPOLY *poly)
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
uint32_t lwgeom_count_rings(const LWGEOM *geom)
Count the total number of rings in any LWGEOM.
void ptarray_free(POINTARRAY *pa)
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
int lwpoint_is_empty(const LWPOINT *point)
void * lwalloc0(size_t sz)
#define FP_CONTAINS_INCL(A, X, B)
int lwpoly_is_empty(const LWPOLY *poly)
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
struct IntervalTreeNode * children[ITREE_MAX_NODES]
struct IntervalTreeNode * nodes
struct IntervalTreeNode ** indexes
POINTARRAY ** indexArrays