MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / FindContainedRecursive

Method FindContainedRecursive

src/core/kdtree.hpp:273–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271
272 template <typename Outputter>
273 void FindContainedRecursive(CoordT p1[2], CoordT p2[2], size_t node_idx, int level, const Outputter &outputter) const
274 {
275 /* Dimension index of current level */
276 int dim = level % 2;
277 /* Node reference */
278 const node &n = this->nodes[node_idx];
279
280 /* Coordinate of element splitting at this node */
281 CoordT ec = TxyFunc()(n.element, dim);
282 /* Opposite coordinate of element */
283 CoordT oc = TxyFunc()(n.element, 1 - dim);
284
285 /* Test if this element is within rectangle */
286 if (ec >= p1[dim] && ec < p2[dim] && oc >= p1[1 - dim] && oc < p2[1 - dim]) outputter(n.element);
287
288 /* Recurse left if part of rectangle is left of split */
289 if (p1[dim] < ec && n.left != INVALID_NODE) this->FindContainedRecursive(p1, p2, n.left, level + 1, outputter);
290
291 /* Recurse right if part of rectangle is right of split */
292 if (p2[dim] > ec && n.right != INVALID_NODE) this->FindContainedRecursive(p1, p2, n.right, level + 1, outputter);
293 }
294
295 /** Debugging function, counts number of occurrences of an element regardless of its correct position in the tree */
296 size_t CountValue(const T &element, size_t node_idx) const

Callers 1

FindContainedMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected