1 /// @ref core 2 /// @file glm/detail/type_vec1.hpp 3 4 #pragma once 5 6 #include "../fwd.hpp" 7 #include "type_vec.hpp" 8 #if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 9 # if GLM_HAS_UNRESTRICTED_UNIONS 10 # include "_swizzle.hpp" 11 # else 12 # include "_swizzle_func.hpp" 13 # endif 14 #endif //GLM_SWIZZLE 15 #include <cstddef> 16 17 namespace glm 18 { 19 template <typename T, precision P = defaultp> 20 struct tvec1 21 { 22 // -- Implementation detail -- 23 24 typedef T value_type; 25 typedef tvec1<T, P> type; 26 typedef tvec1<bool, P> bool_type; 27 28 // -- Data -- 29 30 # if GLM_HAS_ONLY_XYZW 31 T x; 32 33 # elif GLM_HAS_ALIGNED_TYPE 34 # if GLM_COMPILER & GLM_COMPILER_GCC 35 # pragma GCC diagnostic push 36 # pragma GCC diagnostic ignored "-Wpedantic" 37 # endif 38 # if GLM_COMPILER & GLM_COMPILER_CLANG 39 # pragma clang diagnostic push 40 # pragma clang diagnostic ignored "-Wgnu-anonymous-struct" 41 # pragma clang diagnostic ignored "-Wnested-anon-types" 42 # endif 43 44 union 45 { 46 T x; 47 T r; 48 T s; 49 /* 50 # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 51 _GLM_SWIZZLE1_2_MEMBERS(T, P, tvec2, x) 52 _GLM_SWIZZLE1_2_MEMBERS(T, P, tvec2, r) 53 _GLM_SWIZZLE1_2_MEMBERS(T, P, tvec2, s) 54 _GLM_SWIZZLE1_3_MEMBERS(T, P, tvec3, x) 55 _GLM_SWIZZLE1_3_MEMBERS(T, P, tvec3, r) 56 _GLM_SWIZZLE1_3_MEMBERS(T, P, tvec3, s) 57 _GLM_SWIZZLE1_4_MEMBERS(T, P, tvec4, x) 58 _GLM_SWIZZLE1_4_MEMBERS(T, P, tvec4, r) 59 _GLM_SWIZZLE1_4_MEMBERS(T, P, tvec4, s) 60 # endif//GLM_SWIZZLE*/ 61 }; 62 63 # if GLM_COMPILER & GLM_COMPILER_CLANG 64 # pragma clang diagnostic pop 65 # endif 66 # if GLM_COMPILER & GLM_COMPILER_GCC 67 # pragma GCC diagnostic pop 68 # endif 69 # else 70 union {T x, r, s;}; 71 /* 72 # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 73 GLM_SWIZZLE_GEN_VEC_FROM_VEC1(T, P, tvec2, tvec2, tvec3, tvec4) 74 # endif//GLM_SWIZZLE*/ 75 # endif 76 77 // -- Component accesses -- 78 79 /// Return the count of components of the vector 80 typedef length_t length_type; lengthglm::tvec181 GLM_FUNC_DECL static length_type length(){return 1;} 82 83 GLM_FUNC_DECL T & operator[](length_type i); 84 GLM_FUNC_DECL T const & operator[](length_type i) const; 85 86 // -- Implicit basic constructors -- 87 88 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec1() GLM_DEFAULT_CTOR; 89 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec1(tvec1<T, P> const & v) GLM_DEFAULT; 90 template <precision Q> 91 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec1(tvec1<T, Q> const & v); 92 93 // -- Explicit basic constructors -- 94 95 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tvec1(ctor); 96 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tvec1(T scalar); 97 98 // -- Conversion vector constructors -- 99 100 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 101 template <typename U, precision Q> 102 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec1(tvec2<U, Q> const & v); 103 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 104 template <typename U, precision Q> 105 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec1(tvec3<U, Q> const & v); 106 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 107 template <typename U, precision Q> 108 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec1(tvec4<U, Q> const & v); 109 110 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 111 template <typename U, precision Q> 112 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec1(tvec1<U, Q> const & v); 113 114 // -- Swizzle constructors -- 115 /* 116 # if(GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)) 117 template <int E0> 118 GLM_FUNC_DECL tvec1(detail::_swizzle<1, T, P, tvec1, E0, -1,-2,-3> const & that) 119 { 120 *this = that(); 121 } 122 # endif//(GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)) 123 */ 124 // -- Unary arithmetic operators -- 125 126 GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<T, P> const & v) GLM_DEFAULT; 127 128 template <typename U> 129 GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<U, P> const & v); 130 template <typename U> 131 GLM_FUNC_DECL tvec1<T, P> & operator+=(U scalar); 132 template <typename U> 133 GLM_FUNC_DECL tvec1<T, P> & operator+=(tvec1<U, P> const & v); 134 template <typename U> 135 GLM_FUNC_DECL tvec1<T, P> & operator-=(U scalar); 136 template <typename U> 137 GLM_FUNC_DECL tvec1<T, P> & operator-=(tvec1<U, P> const & v); 138 template <typename U> 139 GLM_FUNC_DECL tvec1<T, P> & operator*=(U scalar); 140 template <typename U> 141 GLM_FUNC_DECL tvec1<T, P> & operator*=(tvec1<U, P> const & v); 142 template <typename U> 143 GLM_FUNC_DECL tvec1<T, P> & operator/=(U scalar); 144 template <typename U> 145 GLM_FUNC_DECL tvec1<T, P> & operator/=(tvec1<U, P> const & v); 146 147 // -- Increment and decrement operators -- 148 149 GLM_FUNC_DECL tvec1<T, P> & operator++(); 150 GLM_FUNC_DECL tvec1<T, P> & operator--(); 151 GLM_FUNC_DECL tvec1<T, P> operator++(int); 152 GLM_FUNC_DECL tvec1<T, P> operator--(int); 153 154 // -- Unary bit operators -- 155 156 template <typename U> 157 GLM_FUNC_DECL tvec1<T, P> & operator%=(U scalar); 158 template <typename U> 159 GLM_FUNC_DECL tvec1<T, P> & operator%=(tvec1<U, P> const & v); 160 template <typename U> 161 GLM_FUNC_DECL tvec1<T, P> & operator&=(U scalar); 162 template <typename U> 163 GLM_FUNC_DECL tvec1<T, P> & operator&=(tvec1<U, P> const & v); 164 template <typename U> 165 GLM_FUNC_DECL tvec1<T, P> & operator|=(U scalar); 166 template <typename U> 167 GLM_FUNC_DECL tvec1<T, P> & operator|=(tvec1<U, P> const & v); 168 template <typename U> 169 GLM_FUNC_DECL tvec1<T, P> & operator^=(U scalar); 170 template <typename U> 171 GLM_FUNC_DECL tvec1<T, P> & operator^=(tvec1<U, P> const & v); 172 template <typename U> 173 GLM_FUNC_DECL tvec1<T, P> & operator<<=(U scalar); 174 template <typename U> 175 GLM_FUNC_DECL tvec1<T, P> & operator<<=(tvec1<U, P> const & v); 176 template <typename U> 177 GLM_FUNC_DECL tvec1<T, P> & operator>>=(U scalar); 178 template <typename U> 179 GLM_FUNC_DECL tvec1<T, P> & operator>>=(tvec1<U, P> const & v); 180 }; 181 182 // -- Unary operators -- 183 184 template <typename T, precision P> 185 GLM_FUNC_DECL tvec1<T, P> operator+(tvec1<T, P> const & v); 186 187 template <typename T, precision P> 188 GLM_FUNC_DECL tvec1<T, P> operator-(tvec1<T, P> const & v); 189 190 // -- Binary operators -- 191 192 template <typename T, precision P> 193 GLM_FUNC_DECL tvec1<T, P> operator+(tvec1<T, P> const & v, T scalar); 194 195 template <typename T, precision P> 196 GLM_FUNC_DECL tvec1<T, P> operator+(T scalar, tvec1<T, P> const & v); 197 198 template <typename T, precision P> 199 GLM_FUNC_DECL tvec1<T, P> operator+(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 200 201 template <typename T, precision P> 202 GLM_FUNC_DECL tvec1<T, P> operator-(tvec1<T, P> const & v, T scalar); 203 204 template <typename T, precision P> 205 GLM_FUNC_DECL tvec1<T, P> operator-(T scalar, tvec1<T, P> const & v); 206 207 template <typename T, precision P> 208 GLM_FUNC_DECL tvec1<T, P> operator- (tvec1<T, P> const & v1, tvec1<T, P> const & v2); 209 210 template <typename T, precision P> 211 GLM_FUNC_DECL tvec1<T, P> operator*(tvec1<T, P> const & v, T scalar); 212 213 template <typename T, precision P> 214 GLM_FUNC_DECL tvec1<T, P> operator*(T scalar, tvec1<T, P> const & v); 215 216 template <typename T, precision P> 217 GLM_FUNC_DECL tvec1<T, P> operator*(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 218 219 template <typename T, precision P> 220 GLM_FUNC_DECL tvec1<T, P> operator/(tvec1<T, P> const & v, T scalar); 221 222 template <typename T, precision P> 223 GLM_FUNC_DECL tvec1<T, P> operator/(T scalar, tvec1<T, P> const & v); 224 225 template <typename T, precision P> 226 GLM_FUNC_DECL tvec1<T, P> operator/(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 227 228 template <typename T, precision P> 229 GLM_FUNC_DECL tvec1<T, P> operator%(tvec1<T, P> const & v, T scalar); 230 231 template <typename T, precision P> 232 GLM_FUNC_DECL tvec1<T, P> operator%(T scalar, tvec1<T, P> const & v); 233 234 template <typename T, precision P> 235 GLM_FUNC_DECL tvec1<T, P> operator%(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 236 237 template <typename T, precision P> 238 GLM_FUNC_DECL tvec1<T, P> operator&(tvec1<T, P> const & v, T scalar); 239 240 template <typename T, precision P> 241 GLM_FUNC_DECL tvec1<T, P> operator&(T scalar, tvec1<T, P> const & v); 242 243 template <typename T, precision P> 244 GLM_FUNC_DECL tvec1<T, P> operator&(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 245 246 template <typename T, precision P> 247 GLM_FUNC_DECL tvec1<T, P> operator|(tvec1<T, P> const & v, T scalar); 248 249 template <typename T, precision P> 250 GLM_FUNC_DECL tvec1<T, P> operator|(T scalar, tvec1<T, P> const & v); 251 252 template <typename T, precision P> 253 GLM_FUNC_DECL tvec1<T, P> operator|(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 254 255 template <typename T, precision P> 256 GLM_FUNC_DECL tvec1<T, P> operator^(tvec1<T, P> const & v, T scalar); 257 258 template <typename T, precision P> 259 GLM_FUNC_DECL tvec1<T, P> operator^(T scalar, tvec1<T, P> const & v); 260 261 template <typename T, precision P> 262 GLM_FUNC_DECL tvec1<T, P> operator^(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 263 264 template <typename T, precision P> 265 GLM_FUNC_DECL tvec1<T, P> operator<<(tvec1<T, P> const & v, T scalar); 266 267 template <typename T, precision P> 268 GLM_FUNC_DECL tvec1<T, P> operator<<(T scalar, tvec1<T, P> const & v); 269 270 template <typename T, precision P> 271 GLM_FUNC_DECL tvec1<T, P> operator<<(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 272 273 template <typename T, precision P> 274 GLM_FUNC_DECL tvec1<T, P> operator>>(tvec1<T, P> const & v, T scalar); 275 276 template <typename T, precision P> 277 GLM_FUNC_DECL tvec1<T, P> operator>>(T scalar, tvec1<T, P> const & v); 278 279 template <typename T, precision P> 280 GLM_FUNC_DECL tvec1<T, P> operator>>(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 281 282 template <typename T, precision P> 283 GLM_FUNC_DECL tvec1<T, P> operator~(tvec1<T, P> const & v); 284 285 // -- Boolean operators -- 286 287 template <typename T, precision P> 288 GLM_FUNC_DECL bool operator==(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 289 290 template <typename T, precision P> 291 GLM_FUNC_DECL bool operator!=(tvec1<T, P> const & v1, tvec1<T, P> const & v2); 292 293 template <precision P> 294 GLM_FUNC_DECL tvec1<bool, P> operator&&(tvec1<bool, P> const & v1, tvec1<bool, P> const & v2); 295 296 template <precision P> 297 GLM_FUNC_DECL tvec1<bool, P> operator||(tvec1<bool, P> const & v1, tvec1<bool, P> const & v2); 298 }//namespace glm 299 300 #ifndef GLM_EXTERNAL_TEMPLATE 301 #include "type_vec1.inl" 302 #endif//GLM_EXTERNAL_TEMPLATE 303