PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
intervaltree.h
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 *
6 * PostGIS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PostGIS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18 *
19 **********************************************************************
20 *
21 * Copyright 2023 Paul Ramsey <pramsey@cleverelephant.ca>
22 *
23 **********************************************************************/
24
25#pragma once
26
27#include "liblwgeom_internal.h"
28
29#define ITREE_MAX_NODES 4
30
31typedef enum
32{
34 ITREE_BOUNDARY = 0, /* any boundary case stops calculations */
36 ITREE_OK = 2 /* calculations may continue */
38
47
48/*
49 * A multi-polygon is converted into an interval tree for
50 * searching, with one indexed ring in the index for each
51 * (non-empty, non-degenerate) ring in the input.
52 * The indexes are arranged in order they are read off
53 * the multipolygon, so (P0R0, P0R1, P1R0, P1R1) etc.
54 * The ringCounts allow hopping to the exterior rings.
55 */
56typedef struct IntervalTree
57{
58 struct IntervalTreeNode *nodes; /* store nodes here in flat array */
59 struct IntervalTreeNode **indexes; /* store pointers to index root nodes here */
60 POINTARRAY **indexArrays; /* store original ring data here */
61 uint32_t numIndexes; /* utilization of the indexes/indexArrays */
62 uint32_t *ringCounts; /* number of rings in each polygon */
63 uint32_t numPolys; /* number of polygons */
64 uint32_t numNodes; /* utilization of the nodes array */
65 uint32_t maxNodes; /* capacity of the nodes array */
67
68/*
69 * Public prototypes
70 */
72void itree_free(IntervalTree *itree);
74
75
76
#define ITREE_MAX_NODES
void itree_free(IntervalTree *itree)
IntervalTreeResult
@ ITREE_BOUNDARY
@ ITREE_OK
@ ITREE_INSIDE
@ ITREE_OUTSIDE
IntervalTreeResult itree_point_in_multipolygon(const IntervalTree *itree, const LWPOINT *point)
IntervalTree * itree_from_lwgeom(const LWGEOM *geom)
struct IntervalTreeNode * children[ITREE_MAX_NODES]
uint32_t numChildren
uint32_t maxNodes
struct IntervalTreeNode * nodes
uint32_t numNodes
struct IntervalTreeNode ** indexes
uint32_t * ringCounts
uint32_t numPolys
POINTARRAY ** indexArrays
uint32_t numIndexes