sandbox
Loading...
Searching...
No Matches
box.hpp
1#ifndef LIBSBX_MATH_BOX_HPP_
2#define LIBSBX_MATH_BOX_HPP_
3
4#include <array>
5
6#include <libsbx/math/concepts.hpp>
7#include <libsbx/math/plane.hpp>
8#include <libsbx/math/vector3.hpp>
9
10namespace sbx::math {
11
12template<scalar Type>
13class basic_box {
14
15public:
16
17 using value_type = Type;
20 using size_type = std::size_t;
21
22 basic_box() noexcept = default;
23
24 basic_box(const std::array<plane_type, 6u>& planes) noexcept
25 : _planes{planes} { }
26
27 basic_box(std::array<plane_type, 6u>&& planes) noexcept
28 : _planes{std::move(planes)} { }
29
30 auto intersects(const volume_type& volume) const -> bool {
31 for (const auto& plane : planes()) {
32 const auto vp = math::vector3{
33 (plane.normal().x() >= 0 ? volume.max().x() : volume.min().x()),
34 (plane.normal().y() >= 0 ? volume.max().y() : volume.min().y()),
35 (plane.normal().z() >= 0 ? volume.max().z() : volume.min().z())
36 };
37
38 if (plane.distance_to_point(vp) < -0.5f) {
39 return false;
40 }
41 }
42
43 return true;
44 }
45
46 auto planes() const noexcept -> const std::array<plane_type, 6u>& {
47 return _planes;
48 }
49
50 auto plane(const size_type index) const noexcept -> const plane_type& {
51 return _planes[index];
52 }
53
54private:
55
56 std::array<plane_type, 6u> _planes;
57
58}; // class basic_box
59
61
62using box = boxf;
63
64} // namespace sbx::math
65
66#endif // LIBSBX_MATH_BOX_HPP_
Definition: box.hpp:13
Definition: plane.hpp:10
Definition: vector3.hpp:22
Definition: volume.hpp:11