65 template <
class,
class>
72 using DistanceNode =
typename Tree::DistanceNode;
73 using offset_t =
typename Tree::offset_t;
80 S(
float dist_sq, Node node,
bool returnable) noexcept
81 : dist_sq(dist_sq), node(node), returnable(returnable)
85 bool operator>(S
const& rhs)
const noexcept {
return dist_sq > rhs.dist_sq; }
88 using Queue = std::priority_queue<S, std::vector<S>, std::greater<S>>;
95 using iterator_category = std::forward_iterator_tag;
96 using difference_type = std::ptrdiff_t;
97 using value_type = DistanceNode;
98 using reference = value_type
const&;
99 using pointer = value_type
const*;
104 bool only_leaves,
bool only_exists)
107 , epsilon_sq_(epsilon * epsilon)
108 , only_leaves_(only_leaves)
109 , only_exists_(only_exists)
111 if (only_exists_ && !t_->exists(node)) {
116 if (returnable(node)) {
117 queue_.emplace(dist_sq, node,
true);
119 if (traversable(node)) {
120 queue_.emplace(dist_sq + epsilon_sq_, node,
false);
128 template <
class Geometry2>
131 , query_(other.query_)
132 , epsilon_sq_(other.epsilon_sq_)
133 , queue_(other.queue_)
135 , only_leaves_(other.only_leaves_)
136 , only_exists_(other.only_exists_)
154 reference operator*()
const {
return ret_; }
156 pointer operator->()
const {
return &ret_; }
158 template <
class Geometry2>
161 return ret_ == other.ret_;
164 template <
class Geometry2>
167 return !(*
this == other);
171 [[nodiscard]]
bool returnable(Node
const& node)
const
173 return !only_leaves_ || t_->
isLeaf(node.index);
176 [[nodiscard]]
bool returnable(S
const& s)
const {
return s.returnable; }
178 [[nodiscard]]
bool traversable(Node
const& node)
const
183 [[nodiscard]]
bool exists(Node
const& node)
const
185 return only_exists_ || t_->code(node.index) == node.code;
188 [[nodiscard]] Node sibling(Node
const& node, offset_t sibling_index)
const
190 return Node(t_->sibling(node.code, sibling_index),
191 exists(node) ? t_->sibling(node.index, sibling_index) : node.index);
194 [[nodiscard]] Node child(Node
const& node, offset_t child_index)
const
197 t_->
child(node.code, child_index),
198 t_->
isParent(node.index) ? t_->
child(node.index, child_index) : node.index);
201 [[nodiscard]] Node parent(Node
const& node)
const
203 return Node(t_->parent(node.code),
204 exists(node) ? t_->parent(node.index) : node.index);
207 [[nodiscard]] offset_t offset(Node
const& node)
const {
return node.code.
offset(); }
211 while (!queue_.empty()) {
212 S cur = queue_.top();
213 if (returnable(cur)) {
214 ret_ = DistanceNode(cur.node, std::sqrt(cur.dist_sq));
220 Node node = child(cur.node, 0);
221 for (offset_t i{}; BF > i; ++i) {
222 node = sibling(node, i);
225 if (returnable(node)) {
226 queue_.emplace(dist_sq, node,
true);
228 if (traversable(node)) {
229 queue_.emplace(dist_sq + epsilon_sq_, node,
false);
static constexpr offset_type branchingFactor() noexcept
Returns the branching factor of the tree (i.e., 2 = binary tree, 4 = quadtree, 8 = octree,...