28 inline __both__
bool operator==(
const vec_t<T,2> &a,
const vec_t<T,2> &b)
29 {
return (a.x==b.x) & (a.y==b.y); }
32 inline __both__
bool operator==(
const vec_t<T,3> &a,
const vec_t<T,3> &b)
33 {
return (a.x==b.x) & (a.y==b.y) & (a.z==b.z); }
36 inline __both__
bool operator==(
const vec_t<T,4> &a,
const vec_t<T,4> &b)
37 {
return (a.x==b.x) & (a.y==b.y) & (a.z==b.z) & (a.w==b.w); }
40 inline __both__
bool operator==(
const vec_t<T,2> &a,
const vec_t<T,2> &b)
41 {
return a.x==b.x && a.y==b.y; }
44 inline __both__
bool operator==(
const vec_t<T,3> &a,
const vec_t<T,3> &b)
45 {
return a.x==b.x && a.y==b.y && a.z==b.z; }
48 inline __both__
bool operator==(
const vec_t<T,4> &a,
const vec_t<T,4> &b)
49 {
return a.x==b.x && a.y==b.y && a.z==b.z && a.w==b.w; }
56 template<
typename T,
int N>
57 inline __both__
bool operator!=(
const vec_t<T,N> &a,
const vec_t<T,N> &b)
70 inline __both__
auto nt(
const vec_t<T,2> &a)
71 -> vec_t<
decltype(!a.x),2>
72 {
return { !a.x, !a.y }; }
75 inline __both__
auto nt(
const vec_t<T,3> &a)
76 -> vec_t<
decltype(!a.x),3>
77 {
return { !a.x, !a.y, !a.z }; }
80 inline __both__
auto nt(
const vec_t<T,4> &a)
81 -> vec_t<
decltype(!a.x),4>
82 {
return { !a.x, !a.y, !a.z, !a.w }; }
89 inline __both__
auto eq(
const vec_t<T,2> &a,
const vec_t<T,2> &b)
90 -> vec_t<
decltype(a.x==b.x),2>
91 {
return { a.x==b.x, a.y==b.y }; }
94 inline __both__
auto eq(
const vec_t<T,3> &a,
const vec_t<T,3> &b)
95 -> vec_t<
decltype(a.x==b.x),3>
96 {
return { a.x==b.x, a.y==b.y, a.z==b.z }; }
99 inline __both__
auto eq(
const vec_t<T,4> &a,
const vec_t<T,4> &b)
100 -> vec_t<
decltype(a.x==b.x),4>
101 {
return { a.x==b.x, a.y==b.y, a.z==b.z, a.w==b.w }; }
107 template<
typename T,
int N>
108 inline __both__
auto neq(
const vec_t<T,N> &a,
const vec_t<T,N> &b)
109 ->
decltype(nt(eq(a,b)))
110 {
return nt(eq(a,b)); }
118 template<
typename T,
int N>
119 inline __both__
bool any(
const vec_t<T,N> &a)
120 {
for (
int i=0;i<N;++i)
if (a[i])
return true;
return false; }
122 template<
typename T,
int N>
123 inline __both__
bool all(
const vec_t<T,N> &a)
124 {
for (
int i=0;i<N;++i)
if (!a[i])
return false;
return true; }
135 inline __both__ vec_t<T,2> select(
const vec_t<bool,2> &mask,
138 {
return { mask.x?a.x:b.x, mask.y?a.y:b.y }; }
141 inline __both__ vec_t<T,3> select(
const vec_t<bool,3> &mask,
144 {
return { mask.x?a.x:b.x, mask.y?a.y:b.y, mask.z?a.z:b.z }; }
147 inline __both__ vec_t<T,4> select(
const vec_t<bool,4> &mask,
150 {
return { mask.x?a.x:b.x, mask.y?a.y:b.y, mask.z?a.z:b.z }; }
152 template<
typename T,
int N>
153 inline __both__ vec_t<T,N> select(
const vec_t<bool,N> &mask,
158 for (
int i=0; i<N; ++i)
159 res[i] = mask[i]?a[i]:b[i];