UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
intersects.hpp
1
42#ifndef UFO_CONTAINER_TREE_PREDICATE_INTERSECTS_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_INTERSECTS_HPP
44
45// UFO
46#include <ufo/container/tree/predicate/filter.hpp>
47#include <ufo/container/tree/predicate/spatial.hpp>
48#include <ufo/geometry/intersects.hpp>
49
50// STL
51#include <type_traits>
52
53namespace ufo::pred
54{
55template <class Geometry>
56struct Intersects {
57 Geometry geometry;
58};
59
60template <class Geometry>
61struct Filter<Intersects<Geometry>> {
63
64 template <class Tree>
65 static constexpr void init(Pred&, Tree const&) noexcept
66 {
67 }
68
69 template <class Value>
70 [[nodiscard]] static constexpr bool returnableValue(Pred const& p,
71 Value const& v) noexcept
72 {
73 if constexpr (is_pair_v<std::remove_cvref_t<Value>>) {
74 return intersects(v.first, p.geometry);
75 } else {
76 return intersects(v, p.geometry);
77 }
78 }
79
80 template <class Tree>
81 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
82 typename Tree::Node const& n) noexcept
83 {
84 return intersects(t.bounds(n), p.geometry);
85 }
86
87 template <class Tree>
88 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
89 typename Tree::Node const& n) noexcept
90 {
91 return intersects(t.bounds(n), p.geometry);
92 }
93
94 template <class Tree>
95 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
96 typename Tree::Node const& n,
97 typename Tree::Ray const&) noexcept
98 {
99 return returnable(p, t, n);
100 }
101
102 template <class Tree>
103 [[nodiscard]] static constexpr bool traversableRay(Pred const& p, Tree const& t,
104 typename Tree::Node const& n,
105 typename Tree::Ray const&) noexcept
106 {
107 return traversable(p, t, n);
108 }
109};
110
111namespace detail
112{
113template <class Geometry>
114struct is_spatial_pred<Intersects<Geometry>> : std::true_type {
115};
116} // namespace detail
117
118} // namespace ufo::pred
119
120#endif // UFO_CONTAINER_TREE_PREDICATE_INTERSECTS_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104
Bounds bounds() const
Returns the bounds of the tree (/ root node).
Definition tree.hpp:567
constexpr bool intersects(A const &a, B const &b)
Checks if two shapes intersect.