17 # pragma GCC diagnostic push
18 # pragma GCC diagnostic ignored "-Wpedantic"
20 #if defined(__clang__)
21 # pragma clang diagnostic push
22 # pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
23 # pragma clang diagnostic ignored "-Wnested-anon-types"
26 #include <vsg/maths/sphere.h>
53 value{0.0, 0.0, 0.0, 0.0} {}
56 value{pl[0], pl[1], pl[2], pl[3]} {}
61 value{v[0], v[1], v[2], v[3]} {}
63 constexpr
t_plane(value_type nx, value_type ny, value_type nz, value_type in_p) :
64 value{nx, ny, nz, in_p} {}
67 value{normal.x, normal.y, normal.z, in_p} {}
70 value{normal.x, normal.y, normal.z, -dot(position, normal)} {}
74 value{v[0], v[1], v[2], v[3]} {}
78 value{v[0], v[1], v[2], v[3]} {}
80 constexpr std::size_t size()
const {
return 4; }
82 value_type& operator[](std::size_t i) {
return value[i]; }
83 value_type operator[](std::size_t i)
const {
return value[i]; }
88 value[0] =
static_cast<value_type
>(rhs[0]);
89 value[1] =
static_cast<value_type
>(rhs[1]);
90 value[2] =
static_cast<value_type
>(rhs[2]);
91 value[3] =
static_cast<value_type
>(rhs[3]);
95 void set(value_type in_x, value_type in_y, value_type in_z, value_type in_d)
103 bool valid()
const {
return n.x != 0.0 && n.y != 0.0 && n.z != 0.0; }
105 explicit operator bool()
const noexcept {
return valid(); }
107 T* data() {
return value; }
108 const T* data()
const {
return value; }
120 return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2] && lhs[3] == rhs[3];
124 constexpr
bool operator!=(
const t_plane<T>& lhs,
const t_plane<T>& rhs)
126 return lhs[0] != rhs[0] || lhs[1] != rhs[1] || lhs[2] != rhs[2] || lhs[3] != rhs[3];
130 constexpr
bool operator<(
const t_plane<T>& lhs,
const t_plane<T>& rhs)
132 if (lhs[0] < rhs[0])
return true;
133 if (lhs[0] > rhs[0])
return false;
134 if (lhs[1] < rhs[1])
return true;
135 if (lhs[1] > rhs[1])
return false;
136 if (lhs[2] < rhs[2])
return true;
137 if (lhs[2] > rhs[2])
return false;
138 return lhs[3] < rhs[3];
142 constexpr T distance(
const t_plane<T>& pl,
const t_vec3<T>& v)
144 return dot(pl.n, v) + pl.p;
147 template<
typename T,
typename R>
148 constexpr T distance(
const t_plane<T>& pl,
const t_vec3<R>& v)
150 using normal_type =
typename t_plane<T>::normal_type;
151 return dot(pl.n, normal_type(v)) + pl.p;
155 template<
class PlaneItr,
typename T>
156 constexpr
bool intersect(PlaneItr first, PlaneItr last,
const t_sphere<T>& s)
158 auto negative_radius = -s.radius;
159 for (
auto itr = first; itr != last; ++itr)
161 if (distance(*itr, s.center) < negative_radius)
return false;
166 template<
class Polytope,
typename T>
167 constexpr
bool intersect(
const Polytope& polytope,
const t_sphere<T>& s)
169 return intersect(polytope.begin(), polytope.end(), s);
173 #if defined(__clang__)
174 # pragma clang diagnostic pop
176 #if defined(__GNUC__)
177 # pragma GCC diagnostic pop
t_vec3 template class that represents a 3D vector
Definition: vec3.h:34
t_vec4 template class that represents a 4D vector
Definition: vec4.h:35