17# pragma GCC diagnostic push
18# pragma GCC diagnostic ignored "-Wpedantic"
21# pragma clang diagnostic push
22# pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
23# pragma clang diagnostic ignored "-Wnested-anon-types"
26#include <vsg/core/type_name.h>
60 constexpr t_vec2(
const t_vec2& v) :
62 constexpr t_vec2& operator=(
const t_vec2&) =
default;
63 constexpr t_vec2(value_type in_x, value_type in_y) :
67 constexpr explicit t_vec2(
const t_vec2<R>& v) :
68 value{
static_cast<T
>(v.x),
static_cast<T
>(v.y)} {}
70 constexpr std::size_t size()
const {
return 2; }
72 value_type& operator[](std::size_t i) {
return value[i]; }
73 value_type operator[](std::size_t i)
const {
return value[i]; }
76 t_vec2& operator=(
const t_vec2<R>& rhs)
78 value[0] =
static_cast<value_type
>(rhs[0]);
79 value[1] =
static_cast<value_type
>(rhs[1]);
83 T* data() {
return value; }
84 const T* data()
const {
return value; }
86 void set(value_type in_x, value_type in_y)
92 inline t_vec2& operator+=(
const t_vec2& rhs)
94 value[0] += rhs.value[0];
95 value[1] += rhs.value[1];
99 inline t_vec2& operator-=(
const t_vec2& rhs)
101 value[0] -= rhs.value[0];
102 value[1] -= rhs.value[1];
106 inline t_vec2& operator*=(value_type rhs)
113 inline t_vec2& operator*=(
const t_vec2& rhs)
115 value[0] *= rhs.value[0];
116 value[1] *= rhs.value[1];
120 inline t_vec2& operator/=(value_type rhs)
122 if constexpr (std::is_floating_point_v<value_type>)
124 value_type inv =
static_cast<value_type
>(1.0) / rhs;
136 explicit operator bool()
const noexcept {
return value[0] != 0.0 || value[1] != 0.0; }
149 VSG_type_name(vsg::vec2);
150 VSG_type_name(vsg::dvec2);
151 VSG_type_name(vsg::bvec2);
152 VSG_type_name(vsg::svec2);
153 VSG_type_name(vsg::ivec2);
154 VSG_type_name(vsg::ubvec2);
155 VSG_type_name(vsg::usvec2);
156 VSG_type_name(vsg::uivec2);
161 return lhs[0] == rhs[0] && lhs[1] == rhs[1];
165 constexpr bool operator!=(
const t_vec2<T>& lhs,
const t_vec2<T>& rhs)
167 return lhs[0] != rhs[0] || lhs[1] != rhs[1];
173 if (lhs[0] < rhs[0])
return true;
174 if (lhs[0] > rhs[0])
return false;
175 return lhs[1] < rhs[1];
181 return t_vec2<T>(lhs[0] - rhs[0], lhs[1] - rhs[1]);
193 return t_vec2<T>(lhs[0] + rhs[0], lhs[1] + rhs[1]);
199 return t_vec2<T>(lhs[0] * rhs, lhs[1] * rhs);
205 return t_vec2<T>(lhs[0] * rhs[0], lhs[1] * rhs[1]);
211 if constexpr (std::is_floating_point_v<T>)
213 T inv =
static_cast<T
>(1.0) / rhs;
214 return t_vec2<T>(lhs[0] * inv, lhs[1] * inv);
218 return t_vec2<T>(lhs[0] / rhs, lhs[1] / rhs);
225 return std::sqrt(v[0] * v[0] + v[1] * v[1]);
231 return v[0] * v[0] + v[1] * v[1];
237 return v / length(v);
243 return lhs[0] * rhs[0] + lhs[1] * rhs[1];
251 return (lhs[0] * rhs[1] - rhs[0] * lhs[1]);
257 T one_minus_r = 1 - r;
258 return t_vec2<T>(start[0] * one_minus_r + end[0] * r,
259 start[1] * one_minus_r + end[1] * r);
264#if defined(__clang__)
265# pragma clang diagnostic pop
268# pragma GCC diagnostic pop
t_vec2 template class that represents a 2D vector
Definition vec2.h:38