1/// @ref core 2/// @file glm/detail/type_vec1.inl 3 4namespace glm 5{ 6 // -- Implicit basic constructors -- 7 8# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) 9 template <typename T, precision P> 10 GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tvec1<T, P>::tvec1() 11# ifndef GLM_FORCE_NO_CTOR_INIT 12 : x(0) 13# endif 14 {} 15# endif//!GLM_HAS_DEFAULTED_FUNCTIONS 16 17# if !GLM_HAS_DEFAULTED_FUNCTIONS 18 template <typename T, precision P> 19 GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tvec1<T, P>::tvec1(tvec1<T, P> const & v) 20 : x(v.x) 21 {} 22# endif//!GLM_HAS_DEFAULTED_FUNCTIONS 23 24 template <typename T, precision P> 25 template <precision Q> 26 GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tvec1<T, P>::tvec1(tvec1<T, Q> const & v) 27 : x(v.x) 28 {} 29 30 // -- Explicit basic constructors -- 31 32 template <typename T, precision P> 33 GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tvec1<T, P>::tvec1(ctor) 34 {} 35 36 template <typename T, precision P> 37 GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tvec1<T, P>::tvec1(T scalar) 38 : x(scalar) 39 {} 40 41 // -- Conversion vector constructors -- 42 43 template <typename T, precision P> 44 template <typename U, precision Q> 45 GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tvec1<T, P>::tvec1(tvec1<U, Q> const & v) 46 : x(static_cast<T>(v.x)) 47 {} 48 49 template <typename T, precision P> 50 template <typename U, precision Q> 51 GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tvec1<T, P>::tvec1(tvec2<U, Q> const & v) 52 : x(static_cast<T>(v.x)) 53 {} 54 55 template <typename T, precision P> 56 template <typename U, precision Q> 57 GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tvec1<T, P>::tvec1(tvec3<U, Q> const & v) 58 : x(static_cast<T>(v.x)) 59 {} 60 61 template <typename T, precision P> 62 template <typename U, precision Q> 63 GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tvec1<T, P>::tvec1(tvec4<U, Q> const & v) 64 : x(static_cast<T>(v.x)) 65 {} 66 67 // -- Component accesses -- 68 69 template <typename T, precision P> 70 GLM_FUNC_QUALIFIER T & tvec1<T, P>::operator[](typename tvec1<T, P>::length_type i) 71 { 72 assert(i >= 0 && i < this->length()); 73 return (&x)[i]; 74 } 75 76 template <typename T, precision P> 77 GLM_FUNC_QUALIFIER T const & tvec1<T, P>::operator[](typename tvec1<T, P>::length_type i) const 78 { 79 assert(i >= 0 && i < this->length()); 80 return (&x)[i]; 81 } 82 83 // -- Unary arithmetic operators -- 84 85# if !GLM_HAS_DEFAULTED_FUNCTIONS 86 template <typename T, precision P> 87 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator=(tvec1<T, P> const & v) 88 { 89 this->x = v.x; 90 return *this; 91 } 92# endif//!GLM_HAS_DEFAULTED_FUNCTIONS 93 94 template <typename T, precision P> 95 template <typename U> 96 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator=(tvec1<U, P> const & v) 97 { 98 this->x = static_cast<T>(v.x); 99 return *this; 100 } 101 102 template <typename T, precision P> 103 template <typename U> 104 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator+=(U scalar) 105 { 106 this->x += static_cast<T>(scalar); 107 return *this; 108 } 109 110 template <typename T, precision P> 111 template <typename U> 112 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator+=(tvec1<U, P> const & v) 113 { 114 this->x += static_cast<T>(v.x); 115 return *this; 116 } 117 118 template <typename T, precision P> 119 template <typename U> 120 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator-=(U scalar) 121 { 122 this->x -= static_cast<T>(scalar); 123 return *this; 124 } 125 126 template <typename T, precision P> 127 template <typename U> 128 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator-=(tvec1<U, P> const & v) 129 { 130 this->x -= static_cast<T>(v.x); 131 return *this; 132 } 133 134 template <typename T, precision P> 135 template <typename U> 136 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator*=(U scalar) 137 { 138 this->x *= static_cast<T>(scalar); 139 return *this; 140 } 141 142 template <typename T, precision P> 143 template <typename U> 144 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator*=(tvec1<U, P> const & v) 145 { 146 this->x *= static_cast<T>(v.x); 147 return *this; 148 } 149 150 template <typename T, precision P> 151 template <typename U> 152 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator/=(U scalar) 153 { 154 this->x /= static_cast<T>(scalar); 155 return *this; 156 } 157 158 template <typename T, precision P> 159 template <typename U> 160 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator/=(tvec1<U, P> const & v) 161 { 162 this->x /= static_cast<T>(v.x); 163 return *this; 164 } 165 166 // -- Increment and decrement operators -- 167 168 template <typename T, precision P> 169 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator++() 170 { 171 ++this->x; 172 return *this; 173 } 174 175 template <typename T, precision P> 176 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator--() 177 { 178 --this->x; 179 return *this; 180 } 181 182 template <typename T, precision P> 183 GLM_FUNC_QUALIFIER tvec1<T, P> tvec1<T, P>::operator++(int) 184 { 185 tvec1<T, P> Result(*this); 186 ++*this; 187 return Result; 188 } 189 190 template <typename T, precision P> 191 GLM_FUNC_QUALIFIER tvec1<T, P> tvec1<T, P>::operator--(int) 192 { 193 tvec1<T, P> Result(*this); 194 --*this; 195 return Result; 196 } 197 198 // -- Unary bit operators -- 199 200 template <typename T, precision P> 201 template <typename U> 202 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator%=(U scalar) 203 { 204 this->x %= static_cast<T>(scalar); 205 return *this; 206 } 207 208 template <typename T, precision P> 209 template <typename U> 210 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator%=(tvec1<U, P> const & v) 211 { 212 this->x %= static_cast<T>(v.x); 213 return *this; 214 } 215 216 template <typename T, precision P> 217 template <typename U> 218 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator&=(U scalar) 219 { 220 this->x &= static_cast<T>(scalar); 221 return *this; 222 } 223 224 template <typename T, precision P> 225 template <typename U> 226 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator&=(tvec1<U, P> const & v) 227 { 228 this->x &= static_cast<T>(v.x); 229 return *this; 230 } 231 232 template <typename T, precision P> 233 template <typename U> 234 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator|=(U scalar) 235 { 236 this->x |= static_cast<T>(scalar); 237 return *this; 238 } 239 240 template <typename T, precision P> 241 template <typename U> 242 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator|=(tvec1<U, P> const & v) 243 { 244 this->x |= U(v.x); 245 return *this; 246 } 247 248 template <typename T, precision P> 249 template <typename U> 250 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator^=(U scalar) 251 { 252 this->x ^= static_cast<T>(scalar); 253 return *this; 254 } 255 256 template <typename T, precision P> 257 template <typename U> 258 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator^=(tvec1<U, P> const & v) 259 { 260 this->x ^= static_cast<T>(v.x); 261 return *this; 262 } 263 264 template <typename T, precision P> 265 template <typename U> 266 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator<<=(U scalar) 267 { 268 this->x <<= static_cast<T>(scalar); 269 return *this; 270 } 271 272 template <typename T, precision P> 273 template <typename U> 274 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator<<=(tvec1<U, P> const & v) 275 { 276 this->x <<= static_cast<T>(v.x); 277 return *this; 278 } 279 280 template <typename T, precision P> 281 template <typename U> 282 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator>>=(U scalar) 283 { 284 this->x >>= static_cast<T>(scalar); 285 return *this; 286 } 287 288 template <typename T, precision P> 289 template <typename U> 290 GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator>>=(tvec1<U, P> const & v) 291 { 292 this->x >>= static_cast<T>(v.x); 293 return *this; 294 } 295 296 // -- Unary constant operators -- 297 298 template <typename T, precision P> 299 GLM_FUNC_QUALIFIER tvec1<T, P> operator+(tvec1<T, P> const & v) 300 { 301 return v; 302 } 303 304 template <typename T, precision P> 305 GLM_FUNC_QUALIFIER tvec1<T, P> operator-(tvec1<T, P> const & v) 306 { 307 return tvec1<T, P>( 308 -v.x); 309 } 310 311 // -- Binary arithmetic operators -- 312 313 template <typename T, precision P> 314 GLM_FUNC_QUALIFIER tvec1<T, P> operator+(tvec1<T, P> const & v, T scalar) 315 { 316 return tvec1<T, P>( 317 v.x + scalar); 318 } 319 320 template <typename T, precision P> 321 GLM_FUNC_QUALIFIER tvec1<T, P> operator+(T scalar, tvec1<T, P> const & v) 322 { 323 return tvec1<T, P>( 324 scalar + v.x); 325 } 326 327 template <typename T, precision P> 328 GLM_FUNC_QUALIFIER tvec1<T, P> operator+(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 329 { 330 return tvec1<T, P>( 331 v1.x + v2.x); 332 } 333 334 //operator- 335 template <typename T, precision P> 336 GLM_FUNC_QUALIFIER tvec1<T, P> operator-(tvec1<T, P> const & v, T scalar) 337 { 338 return tvec1<T, P>( 339 v.x - scalar); 340 } 341 342 template <typename T, precision P> 343 GLM_FUNC_QUALIFIER tvec1<T, P> operator-(T scalar, tvec1<T, P> const & v) 344 { 345 return tvec1<T, P>( 346 scalar - v.x); 347 } 348 349 template <typename T, precision P> 350 GLM_FUNC_QUALIFIER tvec1<T, P> operator-(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 351 { 352 return tvec1<T, P>( 353 v1.x - v2.x); 354 } 355 356 template <typename T, precision P> 357 GLM_FUNC_QUALIFIER tvec1<T, P> operator*(tvec1<T, P> const & v, T scalar) 358 { 359 return tvec1<T, P>( 360 v.x * scalar); 361 } 362 363 template <typename T, precision P> 364 GLM_FUNC_QUALIFIER tvec1<T, P> operator*(T scalar, tvec1<T, P> const & v) 365 { 366 return tvec1<T, P>( 367 scalar * v.x); 368 } 369 370 template <typename T, precision P> 371 GLM_FUNC_QUALIFIER tvec1<T, P> operator*(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 372 { 373 return tvec1<T, P>( 374 v1.x * v2.x); 375 } 376 377 template <typename T, precision P> 378 GLM_FUNC_QUALIFIER tvec1<T, P> operator/(tvec1<T, P> const & v, T scalar) 379 { 380 return tvec1<T, P>( 381 v.x / scalar); 382 } 383 384 template <typename T, precision P> 385 GLM_FUNC_QUALIFIER tvec1<T, P> operator/(T scalar, tvec1<T, P> const & v) 386 { 387 return tvec1<T, P>( 388 scalar / v.x); 389 } 390 391 template <typename T, precision P> 392 GLM_FUNC_QUALIFIER tvec1<T, P> operator/(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 393 { 394 return tvec1<T, P>( 395 v1.x / v2.x); 396 } 397 398 // -- Binary bit operators -- 399 400 template <typename T, precision P> 401 GLM_FUNC_QUALIFIER tvec1<T, P> operator%(tvec1<T, P> const & v, T scalar) 402 { 403 return tvec1<T, P>( 404 v.x % scalar); 405 } 406 407 template <typename T, precision P> 408 GLM_FUNC_QUALIFIER tvec1<T, P> operator%(T scalar, tvec1<T, P> const & v) 409 { 410 return tvec1<T, P>( 411 scalar % v.x); 412 } 413 414 template <typename T, precision P> 415 GLM_FUNC_QUALIFIER tvec1<T, P> operator%(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 416 { 417 return tvec1<T, P>( 418 v1.x % v2.x); 419 } 420 421 template <typename T, precision P> 422 GLM_FUNC_QUALIFIER tvec1<T, P> operator&(tvec1<T, P> const & v, T scalar) 423 { 424 return tvec1<T, P>( 425 v.x & scalar); 426 } 427 428 template <typename T, precision P> 429 GLM_FUNC_QUALIFIER tvec1<T, P> operator&(T scalar, tvec1<T, P> const & v) 430 { 431 return tvec1<T, P>( 432 scalar & v.x); 433 } 434 435 template <typename T, precision P> 436 GLM_FUNC_QUALIFIER tvec1<T, P> operator&(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 437 { 438 return tvec1<T, P>( 439 v1.x & v2.x); 440 } 441 442 template <typename T, precision P> 443 GLM_FUNC_QUALIFIER tvec1<T, P> operator|(tvec1<T, P> const & v, T scalar) 444 { 445 return tvec1<T, P>( 446 v.x | scalar); 447 } 448 449 template <typename T, precision P> 450 GLM_FUNC_QUALIFIER tvec1<T, P> operator|(T scalar, tvec1<T, P> const & v) 451 { 452 return tvec1<T, P>( 453 scalar | v.x); 454 } 455 456 template <typename T, precision P> 457 GLM_FUNC_QUALIFIER tvec1<T, P> operator|(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 458 { 459 return tvec1<T, P>( 460 v1.x | v2.x); 461 } 462 463 template <typename T, precision P> 464 GLM_FUNC_QUALIFIER tvec1<T, P> operator^(tvec1<T, P> const & v, T scalar) 465 { 466 return tvec1<T, P>( 467 v.x ^ scalar); 468 } 469 470 template <typename T, precision P> 471 GLM_FUNC_QUALIFIER tvec1<T, P> operator^(T scalar, tvec1<T, P> const & v) 472 { 473 return tvec1<T, P>( 474 scalar ^ v.x); 475 } 476 477 template <typename T, precision P> 478 GLM_FUNC_QUALIFIER tvec1<T, P> operator^(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 479 { 480 return tvec1<T, P>( 481 v1.x ^ v2.x); 482 } 483 484 template <typename T, precision P> 485 GLM_FUNC_QUALIFIER tvec1<T, P> operator<<(tvec1<T, P> const & v, T scalar) 486 { 487 return tvec1<T, P>( 488 v.x << scalar); 489 } 490 491 template <typename T, precision P> 492 GLM_FUNC_QUALIFIER tvec1<T, P> operator<<(T scalar, tvec1<T, P> const & v) 493 { 494 return tvec1<T, P>( 495 scalar << v.x); 496 } 497 498 template <typename T, precision P> 499 GLM_FUNC_QUALIFIER tvec1<T, P> operator<<(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 500 { 501 return tvec1<T, P>( 502 v1.x << v2.x); 503 } 504 505 template <typename T, precision P> 506 GLM_FUNC_QUALIFIER tvec1<T, P> operator>>(tvec1<T, P> const & v, T scalar) 507 { 508 return tvec1<T, P>( 509 v.x >> scalar); 510 } 511 512 template <typename T, precision P> 513 GLM_FUNC_QUALIFIER tvec1<T, P> operator>>(T scalar, tvec1<T, P> const & v) 514 { 515 return tvec1<T, P>( 516 scalar >> v.x); 517 } 518 519 template <typename T, precision P> 520 GLM_FUNC_QUALIFIER tvec1<T, P> operator>>(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 521 { 522 return tvec1<T, P>( 523 v1.x >> v2.x); 524 } 525 526 template <typename T, precision P> 527 GLM_FUNC_QUALIFIER tvec1<T, P> operator~(tvec1<T, P> const & v) 528 { 529 return tvec1<T, P>( 530 ~v.x); 531 } 532 533 // -- Boolean operators -- 534 535 template <typename T, precision P> 536 GLM_FUNC_QUALIFIER bool operator==(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 537 { 538 return (v1.x == v2.x); 539 } 540 541 template <typename T, precision P> 542 GLM_FUNC_QUALIFIER bool operator!=(tvec1<T, P> const & v1, tvec1<T, P> const & v2) 543 { 544 return (v1.x != v2.x); 545 } 546 547 template <precision P> 548 GLM_FUNC_QUALIFIER tvec1<bool, P> operator&&(tvec1<bool, P> const & v1, tvec1<bool, P> const & v2) 549 { 550 return tvec1<bool, P>(v1.x && v2.x); 551 } 552 553 template <precision P> 554 GLM_FUNC_QUALIFIER tvec1<bool, P> operator||(tvec1<bool, P> const & v1, tvec1<bool, P> const & v2) 555 { 556 return tvec1<bool, P>(v1.x || v2.x); 557 } 558}//namespace glm 559