1 /// @ref core 2 /// @file glm/detail/type_vec2.hpp 3 4 #pragma once 5 6 #include "type_vec.hpp" 7 #if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 8 # if GLM_HAS_UNRESTRICTED_UNIONS 9 # include "_swizzle.hpp" 10 # else 11 # include "_swizzle_func.hpp" 12 # endif 13 #endif //GLM_SWIZZLE 14 #include <cstddef> 15 16 namespace glm 17 { 18 template <typename T, precision P = defaultp> 19 struct tvec2 20 { 21 // -- Implementation detail -- 22 23 typedef T value_type; 24 typedef tvec2<T, P> type; 25 typedef tvec2<bool, P> bool_type; 26 27 // -- Data -- 28 29 # if GLM_HAS_ONLY_XYZW 30 T x, y; 31 32 # elif GLM_HAS_ALIGNED_TYPE 33 # if GLM_COMPILER & GLM_COMPILER_GCC 34 # pragma GCC diagnostic push 35 # pragma GCC diagnostic ignored "-Wpedantic" 36 # endif 37 # if GLM_COMPILER & GLM_COMPILER_CLANG 38 # pragma clang diagnostic push 39 # pragma clang diagnostic ignored "-Wgnu-anonymous-struct" 40 # pragma clang diagnostic ignored "-Wnested-anon-types" 41 # endif 42 43 union 44 { 45 struct{ T x, y; }; 46 struct{ T r, g; }; 47 struct{ T s, t; }; 48 49 # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 50 _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, x, y) 51 _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, r, g) 52 _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, s, t) 53 _GLM_SWIZZLE2_3_MEMBERS(T, P, glm::tvec3, x, y) 54 _GLM_SWIZZLE2_3_MEMBERS(T, P, glm::tvec3, r, g) 55 _GLM_SWIZZLE2_3_MEMBERS(T, P, glm::tvec3, s, t) 56 _GLM_SWIZZLE2_4_MEMBERS(T, P, glm::tvec4, x, y) 57 _GLM_SWIZZLE2_4_MEMBERS(T, P, glm::tvec4, r, g) 58 _GLM_SWIZZLE2_4_MEMBERS(T, P, glm::tvec4, s, t) 59 # endif//GLM_SWIZZLE 60 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 union {T y, g, t;}; 72 73 # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 74 GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, P, tvec2, tvec2, tvec3, tvec4) 75 # endif//GLM_SWIZZLE 76 # endif 77 78 // -- Component accesses -- 79 80 /// Return the count of components of the vector 81 typedef length_t length_type; lengthglm::tvec282 GLM_FUNC_DECL static length_type length(){return 2;} 83 84 GLM_FUNC_DECL T & operator[](length_type i); 85 GLM_FUNC_DECL T const & operator[](length_type i) const; 86 87 // -- Implicit basic constructors -- 88 89 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2() GLM_DEFAULT_CTOR; 90 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(tvec2<T, P> const& v) GLM_DEFAULT; 91 template <precision Q> 92 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(tvec2<T, Q> const& v); 93 94 // -- Explicit basic constructors -- 95 96 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tvec2(ctor); 97 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tvec2(T scalar); 98 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(T s1, T s2); 99 100 // -- Conversion constructors -- 101 102 /// Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 103 template <typename A, typename B> 104 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(A x, B y); 105 template <typename A, typename B> 106 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(tvec1<A, P> const & v1, tvec1<B, P> const & v2); 107 108 // -- Conversion vector constructors -- 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 tvec2(tvec3<U, Q> const & v); 113 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 114 template <typename U, precision Q> 115 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec2(tvec4<U, Q> const & v); 116 117 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 118 template <typename U, precision Q> 119 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec2(tvec2<U, Q> const & v); 120 121 // -- Swizzle constructors -- 122 # if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) 123 template <int E0, int E1> tvec2glm::tvec2124 GLM_FUNC_DECL tvec2(detail::_swizzle<2, T, P, glm::tvec2, E0, E1,-1,-2> const& that) 125 { 126 *this = that(); 127 } 128 # endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) 129 130 // -- Unary arithmetic operators -- 131 132 GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<T, P> const & v) GLM_DEFAULT; 133 134 template <typename U> 135 GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<U, P> const & v); 136 template <typename U> 137 GLM_FUNC_DECL tvec2<T, P>& operator+=(U scalar); 138 template <typename U> 139 GLM_FUNC_DECL tvec2<T, P>& operator+=(tvec1<U, P> const & v); 140 template <typename U> 141 GLM_FUNC_DECL tvec2<T, P>& operator+=(tvec2<U, P> const & v); 142 template <typename U> 143 GLM_FUNC_DECL tvec2<T, P>& operator-=(U scalar); 144 template <typename U> 145 GLM_FUNC_DECL tvec2<T, P>& operator-=(tvec1<U, P> const & v); 146 template <typename U> 147 GLM_FUNC_DECL tvec2<T, P>& operator-=(tvec2<U, P> const & v); 148 template <typename U> 149 GLM_FUNC_DECL tvec2<T, P>& operator*=(U scalar); 150 template <typename U> 151 GLM_FUNC_DECL tvec2<T, P>& operator*=(tvec1<U, P> const & v); 152 template <typename U> 153 GLM_FUNC_DECL tvec2<T, P>& operator*=(tvec2<U, P> const & v); 154 template <typename U> 155 GLM_FUNC_DECL tvec2<T, P>& operator/=(U scalar); 156 template <typename U> 157 GLM_FUNC_DECL tvec2<T, P>& operator/=(tvec1<U, P> const & v); 158 template <typename U> 159 GLM_FUNC_DECL tvec2<T, P>& operator/=(tvec2<U, P> const & v); 160 161 // -- Increment and decrement operators -- 162 163 GLM_FUNC_DECL tvec2<T, P> & operator++(); 164 GLM_FUNC_DECL tvec2<T, P> & operator--(); 165 GLM_FUNC_DECL tvec2<T, P> operator++(int); 166 GLM_FUNC_DECL tvec2<T, P> operator--(int); 167 168 // -- Unary bit operators -- 169 170 template <typename U> 171 GLM_FUNC_DECL tvec2<T, P> & operator%=(U scalar); 172 template <typename U> 173 GLM_FUNC_DECL tvec2<T, P> & operator%=(tvec1<U, P> const & v); 174 template <typename U> 175 GLM_FUNC_DECL tvec2<T, P> & operator%=(tvec2<U, P> const & v); 176 template <typename U> 177 GLM_FUNC_DECL tvec2<T, P> & operator&=(U scalar); 178 template <typename U> 179 GLM_FUNC_DECL tvec2<T, P> & operator&=(tvec1<U, P> const & v); 180 template <typename U> 181 GLM_FUNC_DECL tvec2<T, P> & operator&=(tvec2<U, P> const & v); 182 template <typename U> 183 GLM_FUNC_DECL tvec2<T, P> & operator|=(U scalar); 184 template <typename U> 185 GLM_FUNC_DECL tvec2<T, P> & operator|=(tvec1<U, P> const & v); 186 template <typename U> 187 GLM_FUNC_DECL tvec2<T, P> & operator|=(tvec2<U, P> const & v); 188 template <typename U> 189 GLM_FUNC_DECL tvec2<T, P> & operator^=(U scalar); 190 template <typename U> 191 GLM_FUNC_DECL tvec2<T, P> & operator^=(tvec1<U, P> const & v); 192 template <typename U> 193 GLM_FUNC_DECL tvec2<T, P> & operator^=(tvec2<U, P> const & v); 194 template <typename U> 195 GLM_FUNC_DECL tvec2<T, P> & operator<<=(U scalar); 196 template <typename U> 197 GLM_FUNC_DECL tvec2<T, P> & operator<<=(tvec1<U, P> const & v); 198 template <typename U> 199 GLM_FUNC_DECL tvec2<T, P> & operator<<=(tvec2<U, P> const & v); 200 template <typename U> 201 GLM_FUNC_DECL tvec2<T, P> & operator>>=(U scalar); 202 template <typename U> 203 GLM_FUNC_DECL tvec2<T, P> & operator>>=(tvec1<U, P> const & v); 204 template <typename U> 205 GLM_FUNC_DECL tvec2<T, P> & operator>>=(tvec2<U, P> const & v); 206 }; 207 208 // -- Unary operators -- 209 210 template <typename T, precision P> 211 GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v); 212 213 template <typename T, precision P> 214 GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v); 215 216 // -- Binary operators -- 217 218 template <typename T, precision P> 219 GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v, T scalar); 220 221 template <typename T, precision P> 222 GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 223 224 template <typename T, precision P> 225 GLM_FUNC_DECL tvec2<T, P> operator+(T scalar, tvec2<T, P> const & v); 226 227 template <typename T, precision P> 228 GLM_FUNC_DECL tvec2<T, P> operator+(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 229 230 template <typename T, precision P> 231 GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 232 233 template <typename T, precision P> 234 GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v, T scalar); 235 236 template <typename T, precision P> 237 GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 238 239 template <typename T, precision P> 240 GLM_FUNC_DECL tvec2<T, P> operator-(T scalar, tvec2<T, P> const & v); 241 242 template <typename T, precision P> 243 GLM_FUNC_DECL tvec2<T, P> operator-(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 244 245 template <typename T, precision P> 246 GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 247 248 template <typename T, precision P> 249 GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v, T scalar); 250 251 template <typename T, precision P> 252 GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 253 254 template <typename T, precision P> 255 GLM_FUNC_DECL tvec2<T, P> operator*(T scalar, tvec2<T, P> const & v); 256 257 template <typename T, precision P> 258 GLM_FUNC_DECL tvec2<T, P> operator*(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 259 260 template <typename T, precision P> 261 GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 262 263 template <typename T, precision P> 264 GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v, T scalar); 265 266 template <typename T, precision P> 267 GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 268 269 template <typename T, precision P> 270 GLM_FUNC_DECL tvec2<T, P> operator/(T scalar, tvec2<T, P> const & v); 271 272 template <typename T, precision P> 273 GLM_FUNC_DECL tvec2<T, P> operator/(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 274 275 template <typename T, precision P> 276 GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 277 278 template <typename T, precision P> 279 GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v, T scalar); 280 281 template <typename T, precision P> 282 GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 283 284 template <typename T, precision P> 285 GLM_FUNC_DECL tvec2<T, P> operator%(T scalar, tvec2<T, P> const & v); 286 287 template <typename T, precision P> 288 GLM_FUNC_DECL tvec2<T, P> operator%(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 289 290 template <typename T, precision P> 291 GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 292 293 template <typename T, precision P> 294 GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v, T scalar); 295 296 template <typename T, precision P> 297 GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 298 299 template <typename T, precision P> 300 GLM_FUNC_DECL tvec2<T, P> operator&(T scalar, tvec2<T, P> const & v); 301 302 template <typename T, precision P> 303 GLM_FUNC_DECL tvec2<T, P> operator&(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 304 305 template <typename T, precision P> 306 GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 307 308 template <typename T, precision P> 309 GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v, T scalar); 310 311 template <typename T, precision P> 312 GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 313 314 template <typename T, precision P> 315 GLM_FUNC_DECL tvec2<T, P> operator|(T scalar, tvec2<T, P> const & v); 316 317 template <typename T, precision P> 318 GLM_FUNC_DECL tvec2<T, P> operator|(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 319 320 template <typename T, precision P> 321 GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 322 323 template <typename T, precision P> 324 GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v, T scalar); 325 326 template <typename T, precision P> 327 GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 328 329 template <typename T, precision P> 330 GLM_FUNC_DECL tvec2<T, P> operator^(T scalar, tvec2<T, P> const & v); 331 332 template <typename T, precision P> 333 GLM_FUNC_DECL tvec2<T, P> operator^(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 334 335 template <typename T, precision P> 336 GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 337 338 template <typename T, precision P> 339 GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v, T scalar); 340 341 template <typename T, precision P> 342 GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 343 344 template <typename T, precision P> 345 GLM_FUNC_DECL tvec2<T, P> operator<<(T scalar, tvec2<T, P> const & v); 346 347 template <typename T, precision P> 348 GLM_FUNC_DECL tvec2<T, P> operator<<(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 349 350 template <typename T, precision P> 351 GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 352 353 template <typename T, precision P> 354 GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v, T scalar); 355 356 template <typename T, precision P> 357 GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v1, tvec1<T, P> const & v2); 358 359 template <typename T, precision P> 360 GLM_FUNC_DECL tvec2<T, P> operator>>(T scalar, tvec2<T, P> const & v); 361 362 template <typename T, precision P> 363 GLM_FUNC_DECL tvec2<T, P> operator>>(tvec1<T, P> const & v1, tvec2<T, P> const & v2); 364 365 template <typename T, precision P> 366 GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 367 368 template <typename T, precision P> 369 GLM_FUNC_DECL tvec2<T, P> operator~(tvec2<T, P> const & v); 370 371 // -- Boolean operators -- 372 373 template <typename T, precision P> 374 GLM_FUNC_DECL bool operator==(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 375 376 template <typename T, precision P> 377 GLM_FUNC_DECL bool operator!=(tvec2<T, P> const & v1, tvec2<T, P> const & v2); 378 379 template <precision P> 380 GLM_FUNC_DECL tvec2<bool, P> operator&&(tvec2<bool, P> const & v1, tvec2<bool, P> const & v2); 381 382 template <precision P> 383 GLM_FUNC_DECL tvec2<bool, P> operator||(tvec2<bool, P> const & v1, tvec2<bool, P> const & v2); 384 }//namespace glm 385 386 #ifndef GLM_EXTERNAL_TEMPLATE 387 #include "type_vec2.inl" 388 #endif//GLM_EXTERNAL_TEMPLATE 389