sandbox
Loading...
Searching...
No Matches
plane.hpp
1#ifndef LIBSBX_MATH_PLANE_HPP_
2#define LIBSBX_MATH_PLANE_HPP_
3
4#include <libsbx/math/concepts.hpp>
5#include <libsbx/math/vector3.hpp>
6
7namespace sbx::math {
8
9template<scalar Type>
11
12public:
13
14 using value_type = Type;
16
17 basic_plane() noexcept = default;
18
19 basic_plane(const vector_type& normal, const value_type distance) noexcept
20 : _normal{normal},
21 _distance{distance} { }
22
24 : _normal{plane.x(), plane.y(), plane.z()},
25 _distance{plane.w()} { }
26
27 auto normal() const noexcept -> const vector_type& {
28 return _normal;
29 }
30
31 auto distance() const noexcept -> value_type {
32 return _distance;
33 }
34
35 auto distance_to_point(const vector_type& point) const noexcept -> value_type {
36 return math::vector3::dot(_normal, point) + _distance;
37 }
38
39 auto normalize() noexcept -> basic_plane& {
40 const auto length = _normal.length();
41
42 _normal /= length;
43 _distance /= length;
44
45 return *this;
46 }
47
48private:
49
50 vector_type _normal;
51 value_type _distance;
52
53}; // class basic_plane
54
56
57using plane = planef;
58
59} // namespace sbx::math
60
61#endif // LIBSBX_MATH_PLANE_HPP_
Definition: plane.hpp:10
Definition: vector4.hpp:22