1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// src/index/mod.rs
//! Candidate filters over the parts and the edges of a polygonal value.
//!
//! # What an index is, here
//!
//! An index **filters candidates**. [`PartIndex::candidates`] returns every
//! part whose box meets a window; [`EdgeIndex::candidates`] returns every
//! ring edge whose box meets it. Neither decides anything geometric: the
//! caller tests each candidate exactly, with this crate's predicates or
//! its own arrangement. The index's one obligation is therefore **no false
//! negatives**: nothing whose box meets the window is left out. It meets that
//! obligation exactly, because:
//!
//! 1. every entry's box contains its geometry: a part's box is its exterior
//! ring's envelope, which contains the holes too (`Polygon::new` checks
//! that each hole lies inside the exterior), and an edge's box is the
//! minimum and maximum of its two endpoints, both exact selections of
//! stored coordinates;
//! 2. every node's box contains its children's, by exact union; and
//! 3. the overlap test is the closed-interval comparison of stored values,
//! the same one [`Envelope::intersects`] makes.
//!
//! The argument in full, and the tests that attack each condition, are in
//! `situs`, the crate that holds the tree. This module never names it in a
//! public signature: the API is typed in [`Envelope`], [`Polygon`] and
//! `usize`, and the one private module `seam` converts (ADR-31). An
//! `Envelope` and a `situs` box have the same validity rules, so the
//! conversion has no failure path; the seam's property tests hold that in
//! place.
//!
//! # Candidates are exactly the entries whose boxes meet the window
//!
//! Not a superset: a leaf entry is reported only after its own box is
//! tested. So a caller may rely on `candidates` returning precisely the
//! parts, or edges, whose boxes intersect the window (closed, so touching
//! counts), in an order that is deterministic but not meaningful.
//!
//! # Ids
//!
//! Entries are identified by `u32` inside the tree. More than `u32::MAX`
//! parts or edges is [`GeometryError::TooManyEntries`], never a truncation.
//! Edges are numbered through a side table of [`EdgeRef`]s, so the public
//! API speaks in `(part, ring, edge)` triples and `usize`.
//!
//! # Not here
//!
//! Prepared predicates build on these, and a part filter is a consumer
//! of [`PartIndex`].
pub use ;
use crateGeometryError;
use crate;
/// Converts an entry count to the index's `u32` id space.
///
/// # Errors
///
/// [`GeometryError::TooManyEntries`] if `count` exceeds `u32::MAX`.
pub
// ===========================================================================
// PartIndex
// ===========================================================================
/// A candidate filter over the parts of a polygonal value.
///
/// Built once over a slice of parts (a `MultiPolygon`'s polygons, or any
/// `&[Polygon]`); each part's box is its exterior ring's envelope.
/// [`Self::candidates`] then returns the indices of exactly the parts whose
/// boxes meet a window. Exact: see the module doc.
///
/// ```
/// use geometres::index::PartIndex;
/// use geometres::types::{Coord2d, CoordSeq, Envelope, LinearRing, Polygon};
///
/// let square = |x: f64, y: f64| {
/// let ring = LinearRing::new(CoordSeq::new(vec![
/// Coord2d::new(x, y), Coord2d::new(x + 1.0, y),
/// Coord2d::new(x + 1.0, y + 1.0), Coord2d::new(x, y + 1.0),
/// ]))?;
/// Polygon::new_simple(ring)
/// };
/// let parts = vec![square(0.0, 0.0)?, square(5.0, 5.0)?, square(1.0, 0.0)?];
/// let index = PartIndex::new(&parts)?;
///
/// let window = Envelope::new(Coord2d::new(1.0, 0.5), Coord2d::new(1.5, 0.5))?;
/// let mut hits = Vec::new();
/// index.candidates(&window, |part| hits.push(part));
/// hits.sort_unstable();
/// assert_eq!(hits, [0, 2]); // part 0 touches the window at x = 1; part 2 contains it
/// # Ok::<(), geometres::GeometryError>(())
/// ```
// ===========================================================================
// EdgeIndex
// ===========================================================================
/// One ring edge of a polygonal value, by position.
///
/// `ring` 0 is the part's exterior; `ring` `k ≥ 1` is `holes()[k − 1]`.
/// `edge` is the position in `LinearRing::edges`, so edge `i` runs from
/// vertex `i` to vertex `i + 1`, and the last edge closes the ring.
/// A candidate filter over every ring edge of a polygonal value.
///
/// Each edge's box is the minimum and maximum of its two endpoints.
/// [`Self::candidates`] returns exactly the edges whose boxes meet a
/// window, as [`EdgeRef`]s. Exact: see the module doc.