1 #ifndef VTESTBED_GEOMETRY_BSP_TREE_HH 2 #define VTESTBED_GEOMETRY_BSP_TREE_HH 10 #include <vtestbed/base/view.hh> 11 #include <vtestbed/geometry/plane.hh> 12 #include <vtestbed/geometry/polygon.hh> 13 #include <vtestbed/geometry/triangle.hh> 46 using pointer = value_type*;
47 using const_pointer =
const value_type*;
48 using reference = value_type&;
49 using const_reference =
const value_type&;
54 pointer _ptr =
nullptr;
60 if (!tree.empty()) { this->_queue.push(&tree); }
61 this->_ptr = this->current_node();
72 return this->_queue == rhs._queue;
77 return !this->operator==(rhs);
80 inline pointer operator->() {
return this->_ptr; }
81 inline const_pointer operator->()
const {
return this->_ptr; }
82 inline reference operator*() {
return *this->_ptr; }
83 inline const_reference operator*()
const {
return *this->_ptr; }
85 inline const_reference
87 auto& q = this->_queue;
89 if (t.front()) { q.push(t.front().get()); }
90 if (t.back()) { q.push(t.back().get()); }
92 this->_ptr = q.empty() ? nullptr : this->current_node();
107 {
return this->_queue.front(); }
111 {
return this->_queue.front(); }
116 template <
class T,
int N>
129 template <
class T,
int N>
133 using scalar_type = T;
134 static constexpr
const int dimensions = N;
136 using value_type =
typename traits_type::value_type;
150 struct Polygon_and_plane {
154 Polygon_and_plane(
const plane_type& plane,
const value_type& polygon):
155 plane(plane), polygon(polygon) {}
170 _plane(plane), _epsilon(eps) {}
174 _plane(plane), _epsilon(eps) {
175 this->insert(std::forward<polygon_array>(polygons));
180 this->insert(std::forward<polygon_array>(polygons));
188 { this->clear(); this->deep_copy(rhs);
return *
this; }
189 inline ~
BSP_tree() { this->clear_nodes(); }
195 size_t subtract(
const BSP_tree& rhs);
200 return !all(plane().normal() == T{});
203 inline const plane_type plane()
const {
return this->_plane; }
209 return this->_polygons;
212 inline const value_type&
213 polygon(
size_t i)
const {
214 return this->_polygons[i];
231 inline scalar_type accuracy()
const {
return this->_epsilon; }
232 void accuracy(scalar_type rhs);
242 this->_polygons = rhs._polygons;
243 this->_plane = rhs._plane;
258 if (!ptr) { ptr.reset(
new BSP_tree<T,N>); }
return ptr.get();
262 {
return get_pointer(this->_front); }
264 {
return get_pointer(this->_back); }
268 if (ptr && ptr->empty()) { ptr.reset(); }
272 update_accuracy(T eps) {
273 if (eps < this->_epsilon) { this->_epsilon = eps; }
278 template <
class T,
int N>
283 auto n = b.subtract(lhs);
288 a.insert(std::move(b));
294 template <
class T,
int N>
296 set_difference(
const BSP_tree<T,N>& lhs,
const BSP_tree<T,N>& rhs) {
297 BSP_tree<T,N> a(lhs), b(rhs);
304 a.insert(std::move(b));
310 template <
class T,
int N>
313 BSP_tree<T,N> a(lhs), b(rhs);
319 a.insert(std::move(b));
329 #endif // vim:filetype=cpp
T set_intersection(T... args)
Three- and two-dimensional plane.
Traverse BSP tree nodes using depth-first search.