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, -(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 T* data() {
return value; }
106 const T* data()
const {
return value; }
118 return dot(pl.n, v) + pl.p;
121 template<
typename T,
typename R>
122 constexpr T distance(
const t_plane<T>& pl,
const t_vec3<R>& v)
124 using normal_type =
typename t_plane<T>::normal_type;
125 return dot(pl.n, normal_type(v)) + pl.p;
129 template<
class PlaneItr,
typename T>
130 constexpr
bool intersect(PlaneItr first, PlaneItr last,
const t_sphere<T>& s)
132 auto negative_radius = -s.radius;
133 for (
auto itr = first; itr != last; ++itr)
135 if (distance(*itr, s.center) < negative_radius)
return false;
140 template<
class Polytope,
typename T>
141 constexpr
bool intersect(
const Polytope& polytope,
const t_sphere<T>& s)
143 return intersect(polytope.begin(), polytope.end(), s);
147 #if defined(__clang__)
148 # pragma clang diagnostic pop
150 #if defined(__GNUC__)
151 # pragma GCC diagnostic pop
t_vec3 template class that a represents a 3D vector
Definition: vec3.h:34
t_vec4 template class that a represents a 4D vector
Definition: vec4.h:34