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/vec2.h> 
   57             value{v.x, v.y, v.z} {}
 
   59         constexpr 
t_vec3(value_type in_x, value_type in_y, value_type in_z) :
 
   60             value{in_x, in_y, in_z} {}
 
   64             value{v.x, v.y, in_z} {}
 
   68             value{
static_cast<T
>(v.x), 
static_cast<T
>(v.y), 
static_cast<T
>(v.z)} {}
 
   70         constexpr std::size_t size()
 const { 
return 3; }
 
   72         value_type& operator[](std::size_t i) { 
return value[i]; }
 
   73         value_type operator[](std::size_t i)
 const { 
return value[i]; }
 
   78             value[0] = 
static_cast<value_type
>(rhs[0]);
 
   79             value[1] = 
static_cast<value_type
>(rhs[1]);
 
   80             value[2] = 
static_cast<value_type
>(rhs[2]);
 
   84         T* data() { 
return value; }
 
   85         const T* data()
 const { 
return value; }
 
   87         void set(value_type in_x, value_type in_y, value_type in_z)
 
   96             value[0] += rhs.value[0];
 
   97             value[1] += rhs.value[1];
 
   98             value[2] += rhs.value[2];
 
  104             value[0] -= rhs.value[0];
 
  105             value[1] -= rhs.value[1];
 
  106             value[2] -= rhs.value[2];
 
  110         inline t_vec3& operator*=(value_type rhs)
 
  120             value[0] *= rhs.value[0];
 
  121             value[1] *= rhs.value[1];
 
  122             value[2] *= rhs.value[2];
 
  126         inline t_vec3& operator/=(value_type rhs)
 
  128             if constexpr (std::is_floating_point_v<value_type>)
 
  130                 value_type inv = 
static_cast<value_type
>(1.0) / rhs;
 
  166         return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2];
 
  170     constexpr 
bool operator!=(
const t_vec3<T>& lhs, 
const t_vec3<T>& rhs)
 
  172         return lhs[0] != rhs[0] || lhs[1] != rhs[1] || lhs[2] != rhs[2];
 
  176     constexpr 
bool operator<(
const t_vec3<T>& lhs, 
const t_vec3<T>& rhs)
 
  178         if (lhs[0] < rhs[0]) 
return true;
 
  179         if (lhs[0] > rhs[0]) 
return false;
 
  180         if (lhs[1] < rhs[1]) 
return true;
 
  181         if (lhs[1] > rhs[1]) 
return false;
 
  182         return lhs[2] < rhs[2];
 
  186     constexpr t_vec3<T> operator-(
const t_vec3<T>& lhs, 
const t_vec3<T>& rhs)
 
  188         return t_vec3<T>(lhs[0] - rhs[0], lhs[1] - rhs[1], lhs[2] - rhs[2]);
 
  192     constexpr t_vec3<T> operator-(
const t_vec3<T>& v)
 
  194         return t_vec3<T>(-v[0], -v[1], -v[2]);
 
  198     constexpr t_vec3<T> operator+(
const t_vec3<T>& lhs, 
const t_vec3<T>& rhs)
 
  200         return t_vec3<T>(lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2]);
 
  204     constexpr t_vec3<T> operator*(
const t_vec3<T>& lhs, T rhs)
 
  206         return t_vec3<T>(lhs[0] * rhs, lhs[1] * rhs, lhs[2] * rhs);
 
  210     constexpr t_vec3<T> operator*(
const t_vec3<T>& lhs, 
const t_vec3<T>& rhs)
 
  212         return t_vec3<T>(lhs[0] * rhs[0], lhs[1] * rhs[1], lhs[2] * rhs[2]);
 
  216     constexpr t_vec3<T> operator/(
const t_vec3<T>& lhs, T rhs)
 
  218         if constexpr (std::is_floating_point_v<T>)
 
  220             T inv = 
static_cast<T
>(1.0) / rhs;
 
  221             return t_vec3<T>(lhs[0] * inv, lhs[1] * inv, lhs[2] * inv);
 
  225             return t_vec3<T>(lhs[0] / rhs, lhs[1] / rhs, lhs[2] / rhs);
 
  230     constexpr T length(
const t_vec3<T>& v)
 
  232         return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
 
  236     constexpr T length2(
const t_vec3<T>& v)
 
  238         return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
 
  242     constexpr t_vec3<T> normalize(
const t_vec3<T>& v)
 
  244         return v / length(v);
 
  248     constexpr T dot(
const t_vec3<T>& lhs, 
const t_vec3<T>& rhs)
 
  250         return lhs[0] * rhs[0] + lhs[1] * rhs[1] + lhs[2] * rhs[2];
 
  254     constexpr t_vec3<T> cross(
const t_vec3<T>& lhs, 
const t_vec3<T>& rhs)
 
  256         return t_vec3<T>(lhs[1] * rhs[2] - rhs[1] * lhs[2],
 
  257                          lhs[2] * rhs[0] - rhs[2] * lhs[0],
 
  258                          lhs[0] * rhs[1] - rhs[0] * lhs[1]);
 
  262     constexpr t_vec3<T> mix(
const t_vec3<T>& start, 
const t_vec3<T>& end, T r)
 
  264         T one_minus_r = 1 - r;
 
  265         return t_vec3<T>(start[0] * one_minus_r + end[0] * r,
 
  266                          start[1] * one_minus_r + end[1] * r,
 
  267                          start[2] * one_minus_r + end[2] * r);
 
  271     constexpr t_vec3<T> orthogonal(
const t_vec3<T>& v)
 
  274         auto abs_x = fabs(v.x);
 
  275         auto abs_y = fabs(v.y);
 
  276         auto abs_z = fabs(v.z);
 
  279             if (abs_x < abs_z) 
return {0.0, v.z, -v.y}; 
 
  281         else if (abs_y < abs_z)
 
  283             return {-v.z, 0.0, v.x}; 
 
  285         return {v.y, -v.x, 0.0}; 
 
  290 #if defined(__clang__) 
  291 #    pragma clang diagnostic pop 
  293 #if defined(__GNUC__) 
  294 #    pragma GCC diagnostic pop 
t_vec2 template class that a represents a 2D vector
Definition: vec2.h:36
t_vec3 template class that a represents a 3D vector
Definition: vec3.h:34