/glm/core/type_vec1.inl

https://bitbucket.org/ggerganov/test_opengl · C++ Header · 928 lines · 775 code · 96 blank · 57 comment · 2 complexity · e30cc8a928cabdfc4d1c587116c3921c MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref core
  24. /// @file glm/core/type_vec1.inl
  25. /// @date 2008-08-25 / 2011-06-15
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. namespace glm{
  29. namespace detail
  30. {
  31. template <typename T>
  32. GLM_FUNC_QUALIFIER typename tvec1<T>::size_type tvec1<T>::length() const
  33. {
  34. return 1;
  35. }
  36. //////////////////////////////////////
  37. // Accesses
  38. template <typename T>
  39. GLM_FUNC_QUALIFIER typename tvec1<T>::value_type & tvec1<T>::operator[]
  40. (
  41. size_type i
  42. )
  43. {
  44. assert(i < this->length());
  45. return (&x)[i];
  46. }
  47. template <typename T>
  48. GLM_FUNC_QUALIFIER typename tvec1<T>::value_type const & tvec1<T>::operator[]
  49. (
  50. size_type i
  51. ) const
  52. {
  53. assert(i < this->length());
  54. return (&x)[i];
  55. }
  56. //////////////////////////////////////
  57. // Implicit basic constructors
  58. template <typename T>
  59. GLM_FUNC_QUALIFIER tvec1<T>::tvec1() :
  60. x(value_type(0))
  61. {}
  62. template <typename T>
  63. GLM_FUNC_QUALIFIER tvec1<T>::tvec1
  64. (
  65. ctor
  66. )
  67. {}
  68. template <typename T>
  69. GLM_FUNC_QUALIFIER tvec1<T>::tvec1
  70. (
  71. tvec1<T> const & v
  72. ) :
  73. x(v.x)
  74. {}
  75. //////////////////////////////////////
  76. // Explicit basic constructors
  77. template <typename T>
  78. GLM_FUNC_QUALIFIER tvec1<T>::tvec1
  79. (
  80. value_type const & s
  81. ) :
  82. x(s)
  83. {}
  84. //////////////////////////////////////
  85. // Swizzle constructors
  86. template <typename T>
  87. GLM_FUNC_QUALIFIER tvec1<T>::tvec1
  88. (
  89. tref1<T> const & r
  90. ) :
  91. x(r.x)
  92. {}
  93. //////////////////////////////////////
  94. // Convertion scalar constructors
  95. template <typename T>
  96. template <typename U>
  97. GLM_FUNC_QUALIFIER tvec1<T>::tvec1
  98. (
  99. U const & s
  100. ) :
  101. x(value_type(s))
  102. {}
  103. //////////////////////////////////////
  104. // Convertion vector constructors
  105. template <typename T>
  106. template <typename U>
  107. GLM_FUNC_QUALIFIER tvec1<T>::tvec1
  108. (
  109. tvec2<U> const & v
  110. ) :
  111. x(value_type(v.x))
  112. {}
  113. template <typename T>
  114. template <typename U>
  115. GLM_FUNC_QUALIFIER tvec1<T>::tvec1
  116. (
  117. tvec3<U> const & v
  118. ) :
  119. x(value_type(v.x))
  120. {}
  121. template <typename T>
  122. template <typename U>
  123. GLM_FUNC_QUALIFIER tvec1<T>::tvec1
  124. (
  125. tvec4<U> const & v
  126. ) :
  127. x(value_type(v.x))
  128. {}
  129. //////////////////////////////////////
  130. // Unary arithmetic operators
  131. template <typename T>
  132. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator=
  133. (
  134. tvec1<T> const & v
  135. )
  136. {
  137. this->x = v.x;
  138. return *this;
  139. }
  140. template <typename T>
  141. template <typename U>
  142. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator=
  143. (
  144. tvec1<U> const & v
  145. )
  146. {
  147. this->x = T(v.x);
  148. return *this;
  149. }
  150. template <typename T>
  151. template <typename U>
  152. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator+=
  153. (
  154. U const & s
  155. )
  156. {
  157. this->x += T(s);
  158. return *this;
  159. }
  160. template <typename T>
  161. template <typename U>
  162. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator+=
  163. (
  164. tvec1<U> const & v
  165. )
  166. {
  167. this->x += T(v.x);
  168. return *this;
  169. }
  170. template <typename T>
  171. template <typename U>
  172. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator-=
  173. (
  174. U const & s
  175. )
  176. {
  177. this->x -= T(s);
  178. return *this;
  179. }
  180. template <typename T>
  181. template <typename U>
  182. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator-=
  183. (
  184. tvec1<U> const & v
  185. )
  186. {
  187. this->x -= T(v.x);
  188. return *this;
  189. }
  190. template <typename T>
  191. template <typename U>
  192. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator*=
  193. (
  194. U const & s
  195. )
  196. {
  197. this->x *= T(s);
  198. return *this;
  199. }
  200. template <typename T>
  201. template <typename U>
  202. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator*=
  203. (
  204. tvec1<U> const & v
  205. )
  206. {
  207. this->x *= T(v.x);
  208. return *this;
  209. }
  210. template <typename T>
  211. template <typename U>
  212. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator/=
  213. (
  214. U const & s
  215. )
  216. {
  217. this->x /= T(s);
  218. return *this;
  219. }
  220. template <typename T>
  221. template <typename U>
  222. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator/=
  223. (
  224. tvec1<U> const & v
  225. )
  226. {
  227. this->x /= T(v.x);
  228. return *this;
  229. }
  230. template <typename T>
  231. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator++()
  232. {
  233. ++this->x;
  234. return *this;
  235. }
  236. template <typename T>
  237. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator--()
  238. {
  239. --this->x;
  240. return *this;
  241. }
  242. //////////////////////////////////////
  243. // Boolean operators
  244. template <typename T>
  245. GLM_FUNC_QUALIFIER bool operator==
  246. (
  247. tvec1<T> const & v1,
  248. tvec1<T> const & v2
  249. )
  250. {
  251. return (v1.x == v2.x);
  252. }
  253. template <typename T>
  254. GLM_FUNC_QUALIFIER bool operator!=
  255. (
  256. tvec1<T> const & v1,
  257. tvec1<T> const & v2
  258. )
  259. {
  260. return (v1.x != v2.x);
  261. }
  262. //////////////////////////////////////
  263. // Unary bit operators
  264. template <typename T>
  265. template <typename U>
  266. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator%=
  267. (
  268. U const & s
  269. )
  270. {
  271. this->x %= T(s);
  272. return *this;
  273. }
  274. template <typename T>
  275. template <typename U>
  276. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator%=
  277. (
  278. tvec1<U> const & v
  279. )
  280. {
  281. this->x %= T(v.x);
  282. return *this;
  283. }
  284. template <typename T>
  285. template <typename U>
  286. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator&=
  287. (
  288. U const & s
  289. )
  290. {
  291. this->x &= T(s);
  292. return *this;
  293. }
  294. template <typename T>
  295. template <typename U>
  296. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator&=
  297. (
  298. tvec1<U> const & v
  299. )
  300. {
  301. this->x &= T(v.x);
  302. return *this;
  303. }
  304. template <typename T>
  305. template <typename U>
  306. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator|=
  307. (
  308. U const & s
  309. )
  310. {
  311. this->x |= T(s);
  312. return *this;
  313. }
  314. template <typename T>
  315. template <typename U>
  316. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator|=
  317. (
  318. tvec1<U> const & v
  319. )
  320. {
  321. this->x |= U(v.x);
  322. return *this;
  323. }
  324. template <typename T>
  325. template <typename U>
  326. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator^=
  327. (
  328. U const & s
  329. )
  330. {
  331. this->x ^= T(s);
  332. return *this;
  333. }
  334. template <typename T>
  335. template <typename U>
  336. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator^=
  337. (
  338. tvec1<U> const & v
  339. )
  340. {
  341. this->x ^= T(v.x);
  342. return *this;
  343. }
  344. template <typename T>
  345. template <typename U>
  346. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator<<=
  347. (
  348. U const & s
  349. )
  350. {
  351. this->x <<= T(s);
  352. return *this;
  353. }
  354. template <typename T>
  355. template <typename U>
  356. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator<<=
  357. (
  358. tvec1<U> const & v
  359. )
  360. {
  361. this->x <<= T(v.x);
  362. return *this;
  363. }
  364. template <typename T>
  365. template <typename U>
  366. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator>>=
  367. (
  368. U const & s
  369. )
  370. {
  371. this->x >>= T(s);
  372. return *this;
  373. }
  374. template <typename T>
  375. template <typename U>
  376. GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator>>=
  377. (
  378. tvec1<U> const & v
  379. )
  380. {
  381. this->x >>= T(v.x);
  382. return *this;
  383. }
  384. //////////////////////////////////////
  385. // Swizzle operators
  386. template <typename T>
  387. GLM_FUNC_QUALIFIER T
  388. tvec1<T>::swizzle(comp x) const
  389. {
  390. return (*this)[x];
  391. }
  392. template <typename T>
  393. GLM_FUNC_QUALIFIER tvec2<T>
  394. tvec1<T>::swizzle
  395. (
  396. comp x,
  397. comp y
  398. ) const
  399. {
  400. return tvec2<T>(
  401. (*this)[x],
  402. (*this)[y]);
  403. }
  404. template <typename T>
  405. GLM_FUNC_QUALIFIER tvec3<T>
  406. tvec1<T>::swizzle
  407. (
  408. comp x,
  409. comp y,
  410. comp z
  411. ) const
  412. {
  413. return tvec3<T>(
  414. (*this)[x],
  415. (*this)[y],
  416. (*this)[z]);
  417. }
  418. template <typename T>
  419. GLM_FUNC_QUALIFIER tvec4<T>
  420. tvec1<T>::swizzle
  421. (
  422. comp x,
  423. comp y,
  424. comp z,
  425. comp w
  426. ) const
  427. {
  428. return tvec4<T>(
  429. (*this)[x],
  430. (*this)[y],
  431. (*this)[z],
  432. (*this)[w]);
  433. }
  434. template <typename T>
  435. GLM_FUNC_QUALIFIER tref1<T>
  436. tvec1<T>::swizzle
  437. (
  438. comp x
  439. )
  440. {
  441. return tref1<T>(
  442. (*this)[x]);
  443. }
  444. //////////////////////////////////////
  445. // Binary arithmetic operators
  446. template <typename T>
  447. GLM_FUNC_QUALIFIER tvec1<T> operator+
  448. (
  449. tvec1<T> const & v,
  450. typename tvec1<T>::value_type const & s
  451. )
  452. {
  453. return tvec1<T>(
  454. v.x + s);
  455. }
  456. template <typename T>
  457. GLM_FUNC_QUALIFIER tvec1<T> operator+
  458. (
  459. typename tvec1<T>::value_type const & s,
  460. tvec1<T> const & v
  461. )
  462. {
  463. return tvec1<T>(
  464. s + v.x);
  465. }
  466. template <typename T>
  467. GLM_FUNC_QUALIFIER tvec1<T> operator+
  468. (
  469. tvec1<T> const & v1,
  470. tvec1<T> const & v2
  471. )
  472. {
  473. return tvec1<T>(
  474. v1.x + v2.x);
  475. }
  476. //operator-
  477. template <typename T>
  478. GLM_FUNC_QUALIFIER tvec1<T> operator-
  479. (
  480. tvec1<T> const & v,
  481. typename tvec1<T>::value_type const & s
  482. )
  483. {
  484. return tvec1<T>(
  485. v.x - s);
  486. }
  487. template <typename T>
  488. GLM_FUNC_QUALIFIER tvec1<T> operator-
  489. (
  490. typename tvec1<T>::value_type const & s,
  491. tvec1<T> const & v
  492. )
  493. {
  494. return tvec1<T>(
  495. s - v.x);
  496. }
  497. template <typename T>
  498. GLM_FUNC_QUALIFIER tvec1<T> operator-
  499. (
  500. tvec1<T> const & v1,
  501. tvec1<T> const & v2
  502. )
  503. {
  504. return tvec1<T>(
  505. v1.x - v2.x);
  506. }
  507. //operator*
  508. template <typename T>
  509. GLM_FUNC_QUALIFIER tvec1<T> operator*
  510. (
  511. tvec1<T> const & v,
  512. typename tvec1<T>::value_type const & s
  513. )
  514. {
  515. return tvec1<T>(
  516. v.x * s);
  517. }
  518. template <typename T>
  519. GLM_FUNC_QUALIFIER tvec1<T> operator*
  520. (
  521. typename tvec1<T>::value_type const & s,
  522. tvec1<T> const & v
  523. )
  524. {
  525. return tvec1<T>(
  526. s * v.x);
  527. }
  528. template <typename T>
  529. GLM_FUNC_QUALIFIER tvec1<T> operator*
  530. (
  531. tvec1<T> const & v1,
  532. tvec1<T> const & v2
  533. )
  534. {
  535. return tvec1<T>(
  536. v1.x * v2.x);
  537. }
  538. //operator/
  539. template <typename T>
  540. GLM_FUNC_QUALIFIER tvec1<T> operator/
  541. (
  542. tvec1<T> const & v,
  543. typename tvec1<T>::value_type const & s
  544. )
  545. {
  546. return tvec1<T>(
  547. v.x / s);
  548. }
  549. template <typename T>
  550. GLM_FUNC_QUALIFIER tvec1<T> operator/
  551. (
  552. typename tvec1<T>::value_type const & s,
  553. tvec1<T> const & v
  554. )
  555. {
  556. return tvec1<T>(
  557. s / v.x);
  558. }
  559. template <typename T>
  560. GLM_FUNC_QUALIFIER tvec1<T> operator/
  561. (
  562. tvec1<T> const & v1,
  563. tvec1<T> const & v2
  564. )
  565. {
  566. return tvec1<T>(
  567. v1.x / v2.x);
  568. }
  569. // Unary constant operators
  570. template <typename T>
  571. GLM_FUNC_QUALIFIER tvec1<T> operator-
  572. (
  573. tvec1<T> const & v
  574. )
  575. {
  576. return tvec1<T>(
  577. -v.x);
  578. }
  579. template <typename T>
  580. GLM_FUNC_QUALIFIER tvec1<T> operator++
  581. (
  582. tvec1<T> const & v,
  583. int
  584. )
  585. {
  586. return tvec1<T>(
  587. v.x + T(1));
  588. }
  589. template <typename T>
  590. GLM_FUNC_QUALIFIER tvec1<T> operator--
  591. (
  592. tvec1<T> const & v,
  593. int
  594. )
  595. {
  596. return tvec1<T>(
  597. v.x - T(1));
  598. }
  599. //////////////////////////////////////
  600. // Binary bit operators
  601. template <typename T>
  602. GLM_FUNC_QUALIFIER tvec1<T> operator%
  603. (
  604. tvec1<T> const & v,
  605. typename tvec1<T>::value_type const & s
  606. )
  607. {
  608. return tvec1<T>(
  609. v.x % s);
  610. }
  611. template <typename T>
  612. GLM_FUNC_QUALIFIER tvec1<T> operator%
  613. (
  614. typename tvec1<T>::value_type const & s,
  615. tvec1<T> const & v
  616. )
  617. {
  618. return tvec1<T>(
  619. s % v.x);
  620. }
  621. template <typename T>
  622. GLM_FUNC_QUALIFIER tvec1<T> operator%
  623. (
  624. tvec1<T> const & v1,
  625. tvec1<T> const & v2
  626. )
  627. {
  628. return tvec1<T>(
  629. v1.x % v2.x);
  630. }
  631. template <typename T>
  632. GLM_FUNC_QUALIFIER tvec1<T> operator&
  633. (
  634. tvec1<T> const & v,
  635. typename tvec1<T>::value_type const & s
  636. )
  637. {
  638. return tvec1<T>(
  639. v.x & s);
  640. }
  641. template <typename T>
  642. GLM_FUNC_QUALIFIER tvec1<T> operator&
  643. (
  644. typename tvec1<T>::value_type const & s,
  645. tvec1<T> const & v
  646. )
  647. {
  648. return tvec1<T>(
  649. s & v.x);
  650. }
  651. template <typename T>
  652. GLM_FUNC_QUALIFIER tvec1<T> operator&
  653. (
  654. tvec1<T> const & v1,
  655. tvec1<T> const & v2
  656. )
  657. {
  658. return tvec1<T>(
  659. v1.x & v2.x);
  660. }
  661. template <typename T>
  662. GLM_FUNC_QUALIFIER tvec1<T> operator|
  663. (
  664. tvec1<T> const & v,
  665. typename tvec1<T>::value_type const & s
  666. )
  667. {
  668. return tvec1<T>(
  669. v.x | s);
  670. }
  671. template <typename T>
  672. GLM_FUNC_QUALIFIER tvec1<T> operator|
  673. (
  674. typename tvec1<T>::value_type const & s,
  675. tvec1<T> const & v
  676. )
  677. {
  678. return tvec1<T>(
  679. s | v.x);
  680. }
  681. template <typename T>
  682. GLM_FUNC_QUALIFIER tvec1<T> operator|
  683. (
  684. tvec1<T> const & v1,
  685. tvec1<T> const & v2
  686. )
  687. {
  688. return tvec1<T>(
  689. v1.x | v2.x);
  690. }
  691. template <typename T>
  692. GLM_FUNC_QUALIFIER tvec1<T> operator^
  693. (
  694. tvec1<T> const & v,
  695. typename tvec1<T>::value_type const & s
  696. )
  697. {
  698. return tvec1<T>(
  699. v.x ^ s);
  700. }
  701. template <typename T>
  702. GLM_FUNC_QUALIFIER tvec1<T> operator^
  703. (
  704. typename tvec1<T>::value_type const & s,
  705. tvec1<T> const & v
  706. )
  707. {
  708. return tvec1<T>(
  709. s ^ v.x);
  710. }
  711. template <typename T>
  712. GLM_FUNC_QUALIFIER tvec1<T> operator^
  713. (
  714. tvec1<T> const & v1,
  715. tvec1<T> const & v2
  716. )
  717. {
  718. return tvec1<T>(
  719. v1.x ^ v2.x);
  720. }
  721. template <typename T>
  722. GLM_FUNC_QUALIFIER tvec1<T> operator<<
  723. (
  724. tvec1<T> const & v,
  725. typename tvec1<T>::value_type const & s
  726. )
  727. {
  728. return tvec1<T>(
  729. v.x << s);
  730. }
  731. template <typename T>
  732. GLM_FUNC_QUALIFIER tvec1<T> operator<<
  733. (
  734. typename tvec1<T>::value_type const & s,
  735. tvec1<T> const & v
  736. )
  737. {
  738. return tvec1<T>(
  739. s << v.x);
  740. }
  741. template <typename T>
  742. GLM_FUNC_QUALIFIER tvec1<T> operator<<
  743. (
  744. tvec1<T> const & v1,
  745. tvec1<T> const & v2
  746. )
  747. {
  748. return tvec1<T>(
  749. v1.x << v2.x);
  750. }
  751. template <typename T>
  752. GLM_FUNC_QUALIFIER tvec1<T> operator>>
  753. (
  754. tvec1<T> const & v,
  755. typename tvec1<T>::value_type const & s
  756. )
  757. {
  758. return tvec1<T>(
  759. v.x >> s);
  760. }
  761. template <typename T>
  762. GLM_FUNC_QUALIFIER tvec1<T> operator>>
  763. (
  764. typename tvec1<T>::value_type const & s,
  765. tvec1<T> const & v
  766. )
  767. {
  768. return tvec1<T>(
  769. s >> v.x);
  770. }
  771. template <typename T>
  772. GLM_FUNC_QUALIFIER tvec1<T> operator>>
  773. (
  774. tvec1<T> const & v1,
  775. tvec1<T> const & v2
  776. )
  777. {
  778. return tvec1<T>(
  779. v1.x >> v2.x);
  780. }
  781. template <typename T>
  782. GLM_FUNC_QUALIFIER tvec1<T> operator~
  783. (
  784. tvec1<T> const & v
  785. )
  786. {
  787. return tvec1<T>(
  788. ~v.x);
  789. }
  790. //////////////////////////////////////
  791. // tref definition
  792. template <typename T>
  793. GLM_FUNC_QUALIFIER tref1<T>::tref1
  794. (
  795. T & x
  796. ) :
  797. x(x)
  798. {}
  799. template <typename T>
  800. GLM_FUNC_QUALIFIER tref1<T>::tref1
  801. (
  802. tref1<T> const & r
  803. ) :
  804. x(r.x)
  805. {}
  806. template <typename T>
  807. GLM_FUNC_QUALIFIER tref1<T>::tref1
  808. (
  809. tvec1<T> const & v
  810. ) :
  811. x(v.x)
  812. {}
  813. template <typename T>
  814. GLM_FUNC_QUALIFIER tref1<T> & tref1<T>::operator=
  815. (
  816. tref1<T> const & r
  817. )
  818. {
  819. x = r.x;
  820. return *this;
  821. }
  822. template <typename T>
  823. GLM_FUNC_QUALIFIER tref1<T> & tref1<T>::operator=
  824. (
  825. tvec1<T> const & v
  826. )
  827. {
  828. x = v.x;
  829. return *this;
  830. }
  831. }//namespace detail
  832. }//namespace glm