PostGIS  3.7.0dev-r@@SVN_REVISION@@
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 
31 typedef enum
32 {
34  ITREE_BOUNDARY = 0, /* any boundary case stops calculations */
36  ITREE_OK = 2 /* calculations may continue */
38 
39 typedef struct IntervalTreeNode
40 {
41  double min;
42  double max;
44  uint32_t edgeIndex;
45  uint32_t numChildren;
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  */
56 typedef 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  */
72 void itree_free(IntervalTree *itree);
74 
75 
76 
#define ITREE_MAX_NODES
Definition: intervaltree.h:29
struct IntervalTreeNode IntervalTreeNode
struct IntervalTree IntervalTree
IntervalTree * itree_from_lwgeom(const LWGEOM *geom)
Definition: intervaltree.c:310
void itree_free(IntervalTree *itree)
Definition: intervaltree.c:28
IntervalTreeResult
Definition: intervaltree.h:32
@ ITREE_BOUNDARY
Definition: intervaltree.h:34
@ ITREE_OK
Definition: intervaltree.h:36
@ ITREE_INSIDE
Definition: intervaltree.h:33
@ ITREE_OUTSIDE
Definition: intervaltree.h:35
IntervalTreeResult itree_point_in_multipolygon(const IntervalTree *itree, const LWPOINT *point)
Definition: intervaltree.c:461
struct IntervalTreeNode * children[ITREE_MAX_NODES]
Definition: intervaltree.h:43
uint32_t edgeIndex
Definition: intervaltree.h:44
uint32_t numChildren
Definition: intervaltree.h:45
uint32_t maxNodes
Definition: intervaltree.h:65
struct IntervalTreeNode * nodes
Definition: intervaltree.h:58
uint32_t numNodes
Definition: intervaltree.h:64
struct IntervalTreeNode ** indexes
Definition: intervaltree.h:59
uint32_t * ringCounts
Definition: intervaltree.h:62
uint32_t numPolys
Definition: intervaltree.h:63
POINTARRAY ** indexArrays
Definition: intervaltree.h:60
uint32_t numIndexes
Definition: intervaltree.h:61