Vec.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/math/CommonIncludes.h>
  7. #include <type_traits>
  8. namespace anki
  9. {
  10. /// @addtogroup math
  11. /// @{
  12. /// Common code for all vectors
  13. template<typename T, U N, typename TSimd, typename TV>
  14. class TVec
  15. {
  16. public:
  17. using Scalar = T;
  18. using Simd = TSimd;
  19. static constexpr U SIZE = N;
  20. static constexpr Bool IS_INTEGER = std::is_integral<T>::value;
  21. /// @name Constructors
  22. /// @{
  23. TVec()
  24. {
  25. }
  26. TVec(const TVec& b)
  27. {
  28. for(U i = 0; i < N; i++)
  29. {
  30. m_arr[i] = b.m_arr[i];
  31. }
  32. }
  33. TVec(const T x_, const T y_)
  34. {
  35. static_assert(N == 2, "Wrong vector");
  36. x() = x_;
  37. y() = y_;
  38. }
  39. TVec(const T x_, const T y_, const T z_)
  40. {
  41. static_assert(N == 3, "Wrong vector");
  42. x() = x_;
  43. y() = y_;
  44. z() = z_;
  45. }
  46. TVec(const T x_, const T y_, const T z_, const T w_)
  47. {
  48. static_assert(N == 4, "Wrong vector");
  49. x() = x_;
  50. y() = y_;
  51. z() = z_;
  52. w() = w_;
  53. }
  54. explicit TVec(const T f)
  55. {
  56. for(U i = 0; i < N; ++i)
  57. {
  58. m_arr[i] = f;
  59. }
  60. }
  61. explicit TVec(const T arr[])
  62. {
  63. for(U i = 0; i < N; ++i)
  64. {
  65. m_arr[i] = arr[i];
  66. }
  67. }
  68. explicit TVec(const Simd& simd)
  69. {
  70. m_simd = simd;
  71. }
  72. /// @}
  73. /// @name Accessors
  74. /// @{
  75. T& x()
  76. {
  77. return m_arr[0];
  78. }
  79. T x() const
  80. {
  81. return m_arr[0];
  82. }
  83. T& y()
  84. {
  85. return m_arr[1];
  86. }
  87. T y() const
  88. {
  89. return m_arr[1];
  90. }
  91. T& z()
  92. {
  93. static_assert(N > 2, "Wrong vector");
  94. return m_arr[2];
  95. }
  96. T z() const
  97. {
  98. static_assert(N > 2, "Wrong vector");
  99. return m_arr[2];
  100. }
  101. T& w()
  102. {
  103. static_assert(N > 3, "Wrong vector");
  104. return m_arr[3];
  105. }
  106. T w() const
  107. {
  108. static_assert(N > 3, "Wrong vector");
  109. return m_arr[3];
  110. }
  111. TVec2<T> xx() const
  112. {
  113. return TVec2<T>(x(), x());
  114. }
  115. TVec2<T> yy() const
  116. {
  117. return TVec2<T>(y(), y());
  118. }
  119. TVec2<T> xy() const
  120. {
  121. return TVec2<T>(x(), y());
  122. }
  123. TVec2<T> yx() const
  124. {
  125. return TVec2<T>(y(), x());
  126. }
  127. TVec3<T> xxx() const
  128. {
  129. static_assert(N > 2, "Wrong vector");
  130. return TVec3<T>(x(), x(), x());
  131. }
  132. TVec3<T> xxy() const
  133. {
  134. static_assert(N > 2, "Wrong vector");
  135. return TVec3<T>(x(), x(), y());
  136. }
  137. TVec3<T> xxz() const
  138. {
  139. static_assert(N > 2, "Wrong vector");
  140. return TVec3<T>(x(), x(), z());
  141. }
  142. TVec3<T> xyx() const
  143. {
  144. static_assert(N > 2, "Wrong vector");
  145. return TVec3<T>(x(), y(), x());
  146. }
  147. TVec3<T> xyy() const
  148. {
  149. static_assert(N > 2, "Wrong vector");
  150. return TVec3<T>(x(), y(), y());
  151. }
  152. TVec3<T> xyz() const
  153. {
  154. static_assert(N > 2, "Wrong vector");
  155. return TVec3<T>(x(), y(), z());
  156. }
  157. TVec3<T> xzx() const
  158. {
  159. static_assert(N > 2, "Wrong vector");
  160. return TVec3<T>(x(), z(), x());
  161. }
  162. TVec3<T> xzy() const
  163. {
  164. static_assert(N > 2, "Wrong vector");
  165. return TVec3<T>(x(), z(), y());
  166. }
  167. TVec3<T> xzz() const
  168. {
  169. static_assert(N > 2, "Wrong vector");
  170. return TVec3<T>(x(), z(), z());
  171. }
  172. TVec3<T> yxx() const
  173. {
  174. static_assert(N > 2, "Wrong vector");
  175. return TVec3<T>(y(), x(), x());
  176. }
  177. TVec3<T> yxy() const
  178. {
  179. static_assert(N > 2, "Wrong vector");
  180. return TVec3<T>(y(), x(), y());
  181. }
  182. TVec3<T> yxz() const
  183. {
  184. static_assert(N > 2, "Wrong vector");
  185. return TVec3<T>(y(), x(), z());
  186. }
  187. TVec3<T> yyx() const
  188. {
  189. static_assert(N > 2, "Wrong vector");
  190. return TVec3<T>(y(), y(), x());
  191. }
  192. TVec3<T> yyy() const
  193. {
  194. static_assert(N > 2, "Wrong vector");
  195. return TVec3<T>(y(), y(), y());
  196. }
  197. TVec3<T> yyz() const
  198. {
  199. static_assert(N > 2, "Wrong vector");
  200. return TVec3<T>(y(), y(), z());
  201. }
  202. TVec3<T> yzx() const
  203. {
  204. static_assert(N > 2, "Wrong vector");
  205. return TVec3<T>(y(), z(), x());
  206. }
  207. TVec3<T> yzy() const
  208. {
  209. static_assert(N > 2, "Wrong vector");
  210. return TVec3<T>(y(), z(), y());
  211. }
  212. TVec3<T> yzz() const
  213. {
  214. static_assert(N > 2, "Wrong vector");
  215. return TVec3<T>(y(), z(), z());
  216. }
  217. TVec3<T> zxx() const
  218. {
  219. static_assert(N > 2, "Wrong vector");
  220. return TVec3<T>(z(), x(), x());
  221. }
  222. TVec3<T> zxy() const
  223. {
  224. static_assert(N > 2, "Wrong vector");
  225. return TVec3<T>(z(), x(), y());
  226. }
  227. TVec3<T> zxz() const
  228. {
  229. static_assert(N > 2, "Wrong vector");
  230. return TVec3<T>(z(), x(), z());
  231. }
  232. TVec3<T> zyx() const
  233. {
  234. static_assert(N > 2, "Wrong vector");
  235. return TVec3<T>(z(), y(), x());
  236. }
  237. TVec3<T> zyy() const
  238. {
  239. static_assert(N > 2, "Wrong vector");
  240. return TVec3<T>(z(), y(), y());
  241. }
  242. TVec3<T> zyz() const
  243. {
  244. static_assert(N > 2, "Wrong vector");
  245. return TVec3<T>(z(), y(), z());
  246. }
  247. TVec3<T> zzx() const
  248. {
  249. static_assert(N > 2, "Wrong vector");
  250. return TVec3<T>(z(), z(), x());
  251. }
  252. TVec3<T> zzy() const
  253. {
  254. static_assert(N > 2, "Wrong vector");
  255. return TVec3<T>(z(), z(), y());
  256. }
  257. TVec3<T> zzz() const
  258. {
  259. static_assert(N > 2, "Wrong vector");
  260. return TVec3<T>(z(), z(), z());
  261. }
  262. TVec4<T> xxxx() const
  263. {
  264. static_assert(N > 3, "Wrong vector");
  265. return TVec4<T>(x(), x(), x(), x());
  266. }
  267. TVec4<T> xxxy() const
  268. {
  269. static_assert(N > 3, "Wrong vector");
  270. return TVec4<T>(x(), x(), x(), y());
  271. }
  272. TVec4<T> xxxz() const
  273. {
  274. static_assert(N > 3, "Wrong vector");
  275. return TVec4<T>(x(), x(), x(), z());
  276. }
  277. TVec4<T> xxxw() const
  278. {
  279. static_assert(N > 3, "Wrong vector");
  280. return TVec4<T>(x(), x(), x(), w());
  281. }
  282. TVec4<T> xxyx() const
  283. {
  284. static_assert(N > 3, "Wrong vector");
  285. return TVec4<T>(x(), x(), y(), x());
  286. }
  287. TVec4<T> xxyy() const
  288. {
  289. static_assert(N > 3, "Wrong vector");
  290. return TVec4<T>(x(), x(), y(), y());
  291. }
  292. TVec4<T> xxyz() const
  293. {
  294. static_assert(N > 3, "Wrong vector");
  295. return TVec4<T>(x(), x(), y(), z());
  296. }
  297. TVec4<T> xxyw() const
  298. {
  299. static_assert(N > 3, "Wrong vector");
  300. return TVec4<T>(x(), x(), y(), w());
  301. }
  302. TVec4<T> xxzx() const
  303. {
  304. static_assert(N > 3, "Wrong vector");
  305. return TVec4<T>(x(), x(), z(), x());
  306. }
  307. TVec4<T> xxzy() const
  308. {
  309. static_assert(N > 3, "Wrong vector");
  310. return TVec4<T>(x(), x(), z(), y());
  311. }
  312. TVec4<T> xxzz() const
  313. {
  314. static_assert(N > 3, "Wrong vector");
  315. return TVec4<T>(x(), x(), z(), z());
  316. }
  317. TVec4<T> xxzw() const
  318. {
  319. static_assert(N > 3, "Wrong vector");
  320. return TVec4<T>(x(), x(), z(), w());
  321. }
  322. TVec4<T> xxwx() const
  323. {
  324. static_assert(N > 3, "Wrong vector");
  325. return TVec4<T>(x(), x(), w(), x());
  326. }
  327. TVec4<T> xxwy() const
  328. {
  329. static_assert(N > 3, "Wrong vector");
  330. return TVec4<T>(x(), x(), w(), y());
  331. }
  332. TVec4<T> xxwz() const
  333. {
  334. static_assert(N > 3, "Wrong vector");
  335. return TVec4<T>(x(), x(), w(), z());
  336. }
  337. TVec4<T> xxww() const
  338. {
  339. static_assert(N > 3, "Wrong vector");
  340. return TVec4<T>(x(), x(), w(), w());
  341. }
  342. TVec4<T> xyxx() const
  343. {
  344. static_assert(N > 3, "Wrong vector");
  345. return TVec4<T>(x(), y(), x(), x());
  346. }
  347. TVec4<T> xyxy() const
  348. {
  349. static_assert(N > 3, "Wrong vector");
  350. return TVec4<T>(x(), y(), x(), y());
  351. }
  352. TVec4<T> xyxz() const
  353. {
  354. static_assert(N > 3, "Wrong vector");
  355. return TVec4<T>(x(), y(), x(), z());
  356. }
  357. TVec4<T> xyxw() const
  358. {
  359. static_assert(N > 3, "Wrong vector");
  360. return TVec4<T>(x(), y(), x(), w());
  361. }
  362. TVec4<T> xyyx() const
  363. {
  364. static_assert(N > 3, "Wrong vector");
  365. return TVec4<T>(x(), y(), y(), x());
  366. }
  367. TVec4<T> xyyy() const
  368. {
  369. static_assert(N > 3, "Wrong vector");
  370. return TVec4<T>(x(), y(), y(), y());
  371. }
  372. TVec4<T> xyyz() const
  373. {
  374. static_assert(N > 3, "Wrong vector");
  375. return TVec4<T>(x(), y(), y(), z());
  376. }
  377. TVec4<T> xyyw() const
  378. {
  379. static_assert(N > 3, "Wrong vector");
  380. return TVec4<T>(x(), y(), y(), w());
  381. }
  382. TVec4<T> xyzx() const
  383. {
  384. static_assert(N > 3, "Wrong vector");
  385. return TVec4<T>(x(), y(), z(), x());
  386. }
  387. TVec4<T> xyzy() const
  388. {
  389. static_assert(N > 3, "Wrong vector");
  390. return TVec4<T>(x(), y(), z(), y());
  391. }
  392. TVec4<T> xyzz() const
  393. {
  394. static_assert(N > 3, "Wrong vector");
  395. return TVec4<T>(x(), y(), z(), z());
  396. }
  397. TVec4<T> xyzw() const
  398. {
  399. static_assert(N > 3, "Wrong vector");
  400. return TVec4<T>(x(), y(), z(), w());
  401. }
  402. TVec4<T> xywx() const
  403. {
  404. static_assert(N > 3, "Wrong vector");
  405. return TVec4<T>(x(), y(), w(), x());
  406. }
  407. TVec4<T> xywy() const
  408. {
  409. static_assert(N > 3, "Wrong vector");
  410. return TVec4<T>(x(), y(), w(), y());
  411. }
  412. TVec4<T> xywz() const
  413. {
  414. static_assert(N > 3, "Wrong vector");
  415. return TVec4<T>(x(), y(), w(), z());
  416. }
  417. TVec4<T> xyww() const
  418. {
  419. static_assert(N > 3, "Wrong vector");
  420. return TVec4<T>(x(), y(), w(), w());
  421. }
  422. TVec4<T> xzxx() const
  423. {
  424. static_assert(N > 3, "Wrong vector");
  425. return TVec4<T>(x(), z(), x(), x());
  426. }
  427. TVec4<T> xzxy() const
  428. {
  429. static_assert(N > 3, "Wrong vector");
  430. return TVec4<T>(x(), z(), x(), y());
  431. }
  432. TVec4<T> xzxz() const
  433. {
  434. static_assert(N > 3, "Wrong vector");
  435. return TVec4<T>(x(), z(), x(), z());
  436. }
  437. TVec4<T> xzxw() const
  438. {
  439. static_assert(N > 3, "Wrong vector");
  440. return TVec4<T>(x(), z(), x(), w());
  441. }
  442. TVec4<T> xzyx() const
  443. {
  444. static_assert(N > 3, "Wrong vector");
  445. return TVec4<T>(x(), z(), y(), x());
  446. }
  447. TVec4<T> xzyy() const
  448. {
  449. static_assert(N > 3, "Wrong vector");
  450. return TVec4<T>(x(), z(), y(), y());
  451. }
  452. TVec4<T> xzyz() const
  453. {
  454. static_assert(N > 3, "Wrong vector");
  455. return TVec4<T>(x(), z(), y(), z());
  456. }
  457. TVec4<T> xzyw() const
  458. {
  459. static_assert(N > 3, "Wrong vector");
  460. return TVec4<T>(x(), z(), y(), w());
  461. }
  462. TVec4<T> xzzx() const
  463. {
  464. static_assert(N > 3, "Wrong vector");
  465. return TVec4<T>(x(), z(), z(), x());
  466. }
  467. TVec4<T> xzzy() const
  468. {
  469. static_assert(N > 3, "Wrong vector");
  470. return TVec4<T>(x(), z(), z(), y());
  471. }
  472. TVec4<T> xzzz() const
  473. {
  474. static_assert(N > 3, "Wrong vector");
  475. return TVec4<T>(x(), z(), z(), z());
  476. }
  477. TVec4<T> xzzw() const
  478. {
  479. static_assert(N > 3, "Wrong vector");
  480. return TVec4<T>(x(), z(), z(), w());
  481. }
  482. TVec4<T> xzwx() const
  483. {
  484. static_assert(N > 3, "Wrong vector");
  485. return TVec4<T>(x(), z(), w(), x());
  486. }
  487. TVec4<T> xzwy() const
  488. {
  489. static_assert(N > 3, "Wrong vector");
  490. return TVec4<T>(x(), z(), w(), y());
  491. }
  492. TVec4<T> xzwz() const
  493. {
  494. static_assert(N > 3, "Wrong vector");
  495. return TVec4<T>(x(), z(), w(), z());
  496. }
  497. TVec4<T> xzww() const
  498. {
  499. static_assert(N > 3, "Wrong vector");
  500. return TVec4<T>(x(), z(), w(), w());
  501. }
  502. TVec4<T> xwxx() const
  503. {
  504. static_assert(N > 3, "Wrong vector");
  505. return TVec4<T>(x(), w(), x(), x());
  506. }
  507. TVec4<T> xwxy() const
  508. {
  509. static_assert(N > 3, "Wrong vector");
  510. return TVec4<T>(x(), w(), x(), y());
  511. }
  512. TVec4<T> xwxz() const
  513. {
  514. static_assert(N > 3, "Wrong vector");
  515. return TVec4<T>(x(), w(), x(), z());
  516. }
  517. TVec4<T> xwxw() const
  518. {
  519. static_assert(N > 3, "Wrong vector");
  520. return TVec4<T>(x(), w(), x(), w());
  521. }
  522. TVec4<T> xwyx() const
  523. {
  524. static_assert(N > 3, "Wrong vector");
  525. return TVec4<T>(x(), w(), y(), x());
  526. }
  527. TVec4<T> xwyy() const
  528. {
  529. static_assert(N > 3, "Wrong vector");
  530. return TVec4<T>(x(), w(), y(), y());
  531. }
  532. TVec4<T> xwyz() const
  533. {
  534. static_assert(N > 3, "Wrong vector");
  535. return TVec4<T>(x(), w(), y(), z());
  536. }
  537. TVec4<T> xwyw() const
  538. {
  539. static_assert(N > 3, "Wrong vector");
  540. return TVec4<T>(x(), w(), y(), w());
  541. }
  542. TVec4<T> xwzx() const
  543. {
  544. static_assert(N > 3, "Wrong vector");
  545. return TVec4<T>(x(), w(), z(), x());
  546. }
  547. TVec4<T> xwzy() const
  548. {
  549. static_assert(N > 3, "Wrong vector");
  550. return TVec4<T>(x(), w(), z(), y());
  551. }
  552. TVec4<T> xwzz() const
  553. {
  554. static_assert(N > 3, "Wrong vector");
  555. return TVec4<T>(x(), w(), z(), z());
  556. }
  557. TVec4<T> xwzw() const
  558. {
  559. static_assert(N > 3, "Wrong vector");
  560. return TVec4<T>(x(), w(), z(), w());
  561. }
  562. TVec4<T> xwwx() const
  563. {
  564. static_assert(N > 3, "Wrong vector");
  565. return TVec4<T>(x(), w(), w(), x());
  566. }
  567. TVec4<T> xwwy() const
  568. {
  569. static_assert(N > 3, "Wrong vector");
  570. return TVec4<T>(x(), w(), w(), y());
  571. }
  572. TVec4<T> xwwz() const
  573. {
  574. static_assert(N > 3, "Wrong vector");
  575. return TVec4<T>(x(), w(), w(), z());
  576. }
  577. TVec4<T> xwww() const
  578. {
  579. static_assert(N > 3, "Wrong vector");
  580. return TVec4<T>(x(), w(), w(), w());
  581. }
  582. TVec4<T> yxxx() const
  583. {
  584. static_assert(N > 3, "Wrong vector");
  585. return TVec4<T>(y(), x(), x(), x());
  586. }
  587. TVec4<T> yxxy() const
  588. {
  589. static_assert(N > 3, "Wrong vector");
  590. return TVec4<T>(y(), x(), x(), y());
  591. }
  592. TVec4<T> yxxz() const
  593. {
  594. static_assert(N > 3, "Wrong vector");
  595. return TVec4<T>(y(), x(), x(), z());
  596. }
  597. TVec4<T> yxxw() const
  598. {
  599. static_assert(N > 3, "Wrong vector");
  600. return TVec4<T>(y(), x(), x(), w());
  601. }
  602. TVec4<T> yxyx() const
  603. {
  604. static_assert(N > 3, "Wrong vector");
  605. return TVec4<T>(y(), x(), y(), x());
  606. }
  607. TVec4<T> yxyy() const
  608. {
  609. static_assert(N > 3, "Wrong vector");
  610. return TVec4<T>(y(), x(), y(), y());
  611. }
  612. TVec4<T> yxyz() const
  613. {
  614. static_assert(N > 3, "Wrong vector");
  615. return TVec4<T>(y(), x(), y(), z());
  616. }
  617. TVec4<T> yxyw() const
  618. {
  619. static_assert(N > 3, "Wrong vector");
  620. return TVec4<T>(y(), x(), y(), w());
  621. }
  622. TVec4<T> yxzx() const
  623. {
  624. static_assert(N > 3, "Wrong vector");
  625. return TVec4<T>(y(), x(), z(), x());
  626. }
  627. TVec4<T> yxzy() const
  628. {
  629. static_assert(N > 3, "Wrong vector");
  630. return TVec4<T>(y(), x(), z(), y());
  631. }
  632. TVec4<T> yxzz() const
  633. {
  634. static_assert(N > 3, "Wrong vector");
  635. return TVec4<T>(y(), x(), z(), z());
  636. }
  637. TVec4<T> yxzw() const
  638. {
  639. static_assert(N > 3, "Wrong vector");
  640. return TVec4<T>(y(), x(), z(), w());
  641. }
  642. TVec4<T> yxwx() const
  643. {
  644. static_assert(N > 3, "Wrong vector");
  645. return TVec4<T>(y(), x(), w(), x());
  646. }
  647. TVec4<T> yxwy() const
  648. {
  649. static_assert(N > 3, "Wrong vector");
  650. return TVec4<T>(y(), x(), w(), y());
  651. }
  652. TVec4<T> yxwz() const
  653. {
  654. static_assert(N > 3, "Wrong vector");
  655. return TVec4<T>(y(), x(), w(), z());
  656. }
  657. TVec4<T> yxww() const
  658. {
  659. static_assert(N > 3, "Wrong vector");
  660. return TVec4<T>(y(), x(), w(), w());
  661. }
  662. TVec4<T> yyxx() const
  663. {
  664. static_assert(N > 3, "Wrong vector");
  665. return TVec4<T>(y(), y(), x(), x());
  666. }
  667. TVec4<T> yyxy() const
  668. {
  669. static_assert(N > 3, "Wrong vector");
  670. return TVec4<T>(y(), y(), x(), y());
  671. }
  672. TVec4<T> yyxz() const
  673. {
  674. static_assert(N > 3, "Wrong vector");
  675. return TVec4<T>(y(), y(), x(), z());
  676. }
  677. TVec4<T> yyxw() const
  678. {
  679. static_assert(N > 3, "Wrong vector");
  680. return TVec4<T>(y(), y(), x(), w());
  681. }
  682. TVec4<T> yyyx() const
  683. {
  684. static_assert(N > 3, "Wrong vector");
  685. return TVec4<T>(y(), y(), y(), x());
  686. }
  687. TVec4<T> yyyy() const
  688. {
  689. static_assert(N > 3, "Wrong vector");
  690. return TVec4<T>(y(), y(), y(), y());
  691. }
  692. TVec4<T> yyyz() const
  693. {
  694. static_assert(N > 3, "Wrong vector");
  695. return TVec4<T>(y(), y(), y(), z());
  696. }
  697. TVec4<T> yyyw() const
  698. {
  699. static_assert(N > 3, "Wrong vector");
  700. return TVec4<T>(y(), y(), y(), w());
  701. }
  702. TVec4<T> yyzx() const
  703. {
  704. static_assert(N > 3, "Wrong vector");
  705. return TVec4<T>(y(), y(), z(), x());
  706. }
  707. TVec4<T> yyzy() const
  708. {
  709. static_assert(N > 3, "Wrong vector");
  710. return TVec4<T>(y(), y(), z(), y());
  711. }
  712. TVec4<T> yyzz() const
  713. {
  714. static_assert(N > 3, "Wrong vector");
  715. return TVec4<T>(y(), y(), z(), z());
  716. }
  717. TVec4<T> yyzw() const
  718. {
  719. static_assert(N > 3, "Wrong vector");
  720. return TVec4<T>(y(), y(), z(), w());
  721. }
  722. TVec4<T> yywx() const
  723. {
  724. static_assert(N > 3, "Wrong vector");
  725. return TVec4<T>(y(), y(), w(), x());
  726. }
  727. TVec4<T> yywy() const
  728. {
  729. static_assert(N > 3, "Wrong vector");
  730. return TVec4<T>(y(), y(), w(), y());
  731. }
  732. TVec4<T> yywz() const
  733. {
  734. static_assert(N > 3, "Wrong vector");
  735. return TVec4<T>(y(), y(), w(), z());
  736. }
  737. TVec4<T> yyww() const
  738. {
  739. static_assert(N > 3, "Wrong vector");
  740. return TVec4<T>(y(), y(), w(), w());
  741. }
  742. TVec4<T> yzxx() const
  743. {
  744. static_assert(N > 3, "Wrong vector");
  745. return TVec4<T>(y(), z(), x(), x());
  746. }
  747. TVec4<T> yzxy() const
  748. {
  749. static_assert(N > 3, "Wrong vector");
  750. return TVec4<T>(y(), z(), x(), y());
  751. }
  752. TVec4<T> yzxz() const
  753. {
  754. static_assert(N > 3, "Wrong vector");
  755. return TVec4<T>(y(), z(), x(), z());
  756. }
  757. TVec4<T> yzxw() const
  758. {
  759. static_assert(N > 3, "Wrong vector");
  760. return TVec4<T>(y(), z(), x(), w());
  761. }
  762. TVec4<T> yzyx() const
  763. {
  764. static_assert(N > 3, "Wrong vector");
  765. return TVec4<T>(y(), z(), y(), x());
  766. }
  767. TVec4<T> yzyy() const
  768. {
  769. static_assert(N > 3, "Wrong vector");
  770. return TVec4<T>(y(), z(), y(), y());
  771. }
  772. TVec4<T> yzyz() const
  773. {
  774. static_assert(N > 3, "Wrong vector");
  775. return TVec4<T>(y(), z(), y(), z());
  776. }
  777. TVec4<T> yzyw() const
  778. {
  779. static_assert(N > 3, "Wrong vector");
  780. return TVec4<T>(y(), z(), y(), w());
  781. }
  782. TVec4<T> yzzx() const
  783. {
  784. static_assert(N > 3, "Wrong vector");
  785. return TVec4<T>(y(), z(), z(), x());
  786. }
  787. TVec4<T> yzzy() const
  788. {
  789. static_assert(N > 3, "Wrong vector");
  790. return TVec4<T>(y(), z(), z(), y());
  791. }
  792. TVec4<T> yzzz() const
  793. {
  794. static_assert(N > 3, "Wrong vector");
  795. return TVec4<T>(y(), z(), z(), z());
  796. }
  797. TVec4<T> yzzw() const
  798. {
  799. static_assert(N > 3, "Wrong vector");
  800. return TVec4<T>(y(), z(), z(), w());
  801. }
  802. TVec4<T> yzwx() const
  803. {
  804. static_assert(N > 3, "Wrong vector");
  805. return TVec4<T>(y(), z(), w(), x());
  806. }
  807. TVec4<T> yzwy() const
  808. {
  809. static_assert(N > 3, "Wrong vector");
  810. return TVec4<T>(y(), z(), w(), y());
  811. }
  812. TVec4<T> yzwz() const
  813. {
  814. static_assert(N > 3, "Wrong vector");
  815. return TVec4<T>(y(), z(), w(), z());
  816. }
  817. TVec4<T> yzww() const
  818. {
  819. static_assert(N > 3, "Wrong vector");
  820. return TVec4<T>(y(), z(), w(), w());
  821. }
  822. TVec4<T> ywxx() const
  823. {
  824. static_assert(N > 3, "Wrong vector");
  825. return TVec4<T>(y(), w(), x(), x());
  826. }
  827. TVec4<T> ywxy() const
  828. {
  829. static_assert(N > 3, "Wrong vector");
  830. return TVec4<T>(y(), w(), x(), y());
  831. }
  832. TVec4<T> ywxz() const
  833. {
  834. static_assert(N > 3, "Wrong vector");
  835. return TVec4<T>(y(), w(), x(), z());
  836. }
  837. TVec4<T> ywxw() const
  838. {
  839. static_assert(N > 3, "Wrong vector");
  840. return TVec4<T>(y(), w(), x(), w());
  841. }
  842. TVec4<T> ywyx() const
  843. {
  844. static_assert(N > 3, "Wrong vector");
  845. return TVec4<T>(y(), w(), y(), x());
  846. }
  847. TVec4<T> ywyy() const
  848. {
  849. static_assert(N > 3, "Wrong vector");
  850. return TVec4<T>(y(), w(), y(), y());
  851. }
  852. TVec4<T> ywyz() const
  853. {
  854. static_assert(N > 3, "Wrong vector");
  855. return TVec4<T>(y(), w(), y(), z());
  856. }
  857. TVec4<T> ywyw() const
  858. {
  859. static_assert(N > 3, "Wrong vector");
  860. return TVec4<T>(y(), w(), y(), w());
  861. }
  862. TVec4<T> ywzx() const
  863. {
  864. static_assert(N > 3, "Wrong vector");
  865. return TVec4<T>(y(), w(), z(), x());
  866. }
  867. TVec4<T> ywzy() const
  868. {
  869. static_assert(N > 3, "Wrong vector");
  870. return TVec4<T>(y(), w(), z(), y());
  871. }
  872. TVec4<T> ywzz() const
  873. {
  874. static_assert(N > 3, "Wrong vector");
  875. return TVec4<T>(y(), w(), z(), z());
  876. }
  877. TVec4<T> ywzw() const
  878. {
  879. static_assert(N > 3, "Wrong vector");
  880. return TVec4<T>(y(), w(), z(), w());
  881. }
  882. TVec4<T> ywwx() const
  883. {
  884. static_assert(N > 3, "Wrong vector");
  885. return TVec4<T>(y(), w(), w(), x());
  886. }
  887. TVec4<T> ywwy() const
  888. {
  889. static_assert(N > 3, "Wrong vector");
  890. return TVec4<T>(y(), w(), w(), y());
  891. }
  892. TVec4<T> ywwz() const
  893. {
  894. static_assert(N > 3, "Wrong vector");
  895. return TVec4<T>(y(), w(), w(), z());
  896. }
  897. TVec4<T> ywww() const
  898. {
  899. static_assert(N > 3, "Wrong vector");
  900. return TVec4<T>(y(), w(), w(), w());
  901. }
  902. TVec4<T> zxxx() const
  903. {
  904. static_assert(N > 3, "Wrong vector");
  905. return TVec4<T>(z(), x(), x(), x());
  906. }
  907. TVec4<T> zxxy() const
  908. {
  909. static_assert(N > 3, "Wrong vector");
  910. return TVec4<T>(z(), x(), x(), y());
  911. }
  912. TVec4<T> zxxz() const
  913. {
  914. static_assert(N > 3, "Wrong vector");
  915. return TVec4<T>(z(), x(), x(), z());
  916. }
  917. TVec4<T> zxxw() const
  918. {
  919. static_assert(N > 3, "Wrong vector");
  920. return TVec4<T>(z(), x(), x(), w());
  921. }
  922. TVec4<T> zxyx() const
  923. {
  924. static_assert(N > 3, "Wrong vector");
  925. return TVec4<T>(z(), x(), y(), x());
  926. }
  927. TVec4<T> zxyy() const
  928. {
  929. static_assert(N > 3, "Wrong vector");
  930. return TVec4<T>(z(), x(), y(), y());
  931. }
  932. TVec4<T> zxyz() const
  933. {
  934. static_assert(N > 3, "Wrong vector");
  935. return TVec4<T>(z(), x(), y(), z());
  936. }
  937. TVec4<T> zxyw() const
  938. {
  939. static_assert(N > 3, "Wrong vector");
  940. return TVec4<T>(z(), x(), y(), w());
  941. }
  942. TVec4<T> zxzx() const
  943. {
  944. static_assert(N > 3, "Wrong vector");
  945. return TVec4<T>(z(), x(), z(), x());
  946. }
  947. TVec4<T> zxzy() const
  948. {
  949. static_assert(N > 3, "Wrong vector");
  950. return TVec4<T>(z(), x(), z(), y());
  951. }
  952. TVec4<T> zxzz() const
  953. {
  954. static_assert(N > 3, "Wrong vector");
  955. return TVec4<T>(z(), x(), z(), z());
  956. }
  957. TVec4<T> zxzw() const
  958. {
  959. static_assert(N > 3, "Wrong vector");
  960. return TVec4<T>(z(), x(), z(), w());
  961. }
  962. TVec4<T> zxwx() const
  963. {
  964. static_assert(N > 3, "Wrong vector");
  965. return TVec4<T>(z(), x(), w(), x());
  966. }
  967. TVec4<T> zxwy() const
  968. {
  969. static_assert(N > 3, "Wrong vector");
  970. return TVec4<T>(z(), x(), w(), y());
  971. }
  972. TVec4<T> zxwz() const
  973. {
  974. static_assert(N > 3, "Wrong vector");
  975. return TVec4<T>(z(), x(), w(), z());
  976. }
  977. TVec4<T> zxww() const
  978. {
  979. static_assert(N > 3, "Wrong vector");
  980. return TVec4<T>(z(), x(), w(), w());
  981. }
  982. TVec4<T> zyxx() const
  983. {
  984. static_assert(N > 3, "Wrong vector");
  985. return TVec4<T>(z(), y(), x(), x());
  986. }
  987. TVec4<T> zyxy() const
  988. {
  989. static_assert(N > 3, "Wrong vector");
  990. return TVec4<T>(z(), y(), x(), y());
  991. }
  992. TVec4<T> zyxz() const
  993. {
  994. static_assert(N > 3, "Wrong vector");
  995. return TVec4<T>(z(), y(), x(), z());
  996. }
  997. TVec4<T> zyxw() const
  998. {
  999. static_assert(N > 3, "Wrong vector");
  1000. return TVec4<T>(z(), y(), x(), w());
  1001. }
  1002. TVec4<T> zyyx() const
  1003. {
  1004. static_assert(N > 3, "Wrong vector");
  1005. return TVec4<T>(z(), y(), y(), x());
  1006. }
  1007. TVec4<T> zyyy() const
  1008. {
  1009. static_assert(N > 3, "Wrong vector");
  1010. return TVec4<T>(z(), y(), y(), y());
  1011. }
  1012. TVec4<T> zyyz() const
  1013. {
  1014. static_assert(N > 3, "Wrong vector");
  1015. return TVec4<T>(z(), y(), y(), z());
  1016. }
  1017. TVec4<T> zyyw() const
  1018. {
  1019. static_assert(N > 3, "Wrong vector");
  1020. return TVec4<T>(z(), y(), y(), w());
  1021. }
  1022. TVec4<T> zyzx() const
  1023. {
  1024. static_assert(N > 3, "Wrong vector");
  1025. return TVec4<T>(z(), y(), z(), x());
  1026. }
  1027. TVec4<T> zyzy() const
  1028. {
  1029. static_assert(N > 3, "Wrong vector");
  1030. return TVec4<T>(z(), y(), z(), y());
  1031. }
  1032. TVec4<T> zyzz() const
  1033. {
  1034. static_assert(N > 3, "Wrong vector");
  1035. return TVec4<T>(z(), y(), z(), z());
  1036. }
  1037. TVec4<T> zyzw() const
  1038. {
  1039. static_assert(N > 3, "Wrong vector");
  1040. return TVec4<T>(z(), y(), z(), w());
  1041. }
  1042. TVec4<T> zywx() const
  1043. {
  1044. static_assert(N > 3, "Wrong vector");
  1045. return TVec4<T>(z(), y(), w(), x());
  1046. }
  1047. TVec4<T> zywy() const
  1048. {
  1049. static_assert(N > 3, "Wrong vector");
  1050. return TVec4<T>(z(), y(), w(), y());
  1051. }
  1052. TVec4<T> zywz() const
  1053. {
  1054. static_assert(N > 3, "Wrong vector");
  1055. return TVec4<T>(z(), y(), w(), z());
  1056. }
  1057. TVec4<T> zyww() const
  1058. {
  1059. static_assert(N > 3, "Wrong vector");
  1060. return TVec4<T>(z(), y(), w(), w());
  1061. }
  1062. TVec4<T> zzxx() const
  1063. {
  1064. static_assert(N > 3, "Wrong vector");
  1065. return TVec4<T>(z(), z(), x(), x());
  1066. }
  1067. TVec4<T> zzxy() const
  1068. {
  1069. static_assert(N > 3, "Wrong vector");
  1070. return TVec4<T>(z(), z(), x(), y());
  1071. }
  1072. TVec4<T> zzxz() const
  1073. {
  1074. static_assert(N > 3, "Wrong vector");
  1075. return TVec4<T>(z(), z(), x(), z());
  1076. }
  1077. TVec4<T> zzxw() const
  1078. {
  1079. static_assert(N > 3, "Wrong vector");
  1080. return TVec4<T>(z(), z(), x(), w());
  1081. }
  1082. TVec4<T> zzyx() const
  1083. {
  1084. static_assert(N > 3, "Wrong vector");
  1085. return TVec4<T>(z(), z(), y(), x());
  1086. }
  1087. TVec4<T> zzyy() const
  1088. {
  1089. static_assert(N > 3, "Wrong vector");
  1090. return TVec4<T>(z(), z(), y(), y());
  1091. }
  1092. TVec4<T> zzyz() const
  1093. {
  1094. static_assert(N > 3, "Wrong vector");
  1095. return TVec4<T>(z(), z(), y(), z());
  1096. }
  1097. TVec4<T> zzyw() const
  1098. {
  1099. static_assert(N > 3, "Wrong vector");
  1100. return TVec4<T>(z(), z(), y(), w());
  1101. }
  1102. TVec4<T> zzzx() const
  1103. {
  1104. static_assert(N > 3, "Wrong vector");
  1105. return TVec4<T>(z(), z(), z(), x());
  1106. }
  1107. TVec4<T> zzzy() const
  1108. {
  1109. static_assert(N > 3, "Wrong vector");
  1110. return TVec4<T>(z(), z(), z(), y());
  1111. }
  1112. TVec4<T> zzzz() const
  1113. {
  1114. static_assert(N > 3, "Wrong vector");
  1115. return TVec4<T>(z(), z(), z(), z());
  1116. }
  1117. TVec4<T> zzzw() const
  1118. {
  1119. static_assert(N > 3, "Wrong vector");
  1120. return TVec4<T>(z(), z(), z(), w());
  1121. }
  1122. TVec4<T> zzwx() const
  1123. {
  1124. static_assert(N > 3, "Wrong vector");
  1125. return TVec4<T>(z(), z(), w(), x());
  1126. }
  1127. TVec4<T> zzwy() const
  1128. {
  1129. static_assert(N > 3, "Wrong vector");
  1130. return TVec4<T>(z(), z(), w(), y());
  1131. }
  1132. TVec4<T> zzwz() const
  1133. {
  1134. static_assert(N > 3, "Wrong vector");
  1135. return TVec4<T>(z(), z(), w(), z());
  1136. }
  1137. TVec4<T> zzww() const
  1138. {
  1139. static_assert(N > 3, "Wrong vector");
  1140. return TVec4<T>(z(), z(), w(), w());
  1141. }
  1142. TVec4<T> zwxx() const
  1143. {
  1144. static_assert(N > 3, "Wrong vector");
  1145. return TVec4<T>(z(), w(), x(), x());
  1146. }
  1147. TVec4<T> zwxy() const
  1148. {
  1149. static_assert(N > 3, "Wrong vector");
  1150. return TVec4<T>(z(), w(), x(), y());
  1151. }
  1152. TVec4<T> zwxz() const
  1153. {
  1154. static_assert(N > 3, "Wrong vector");
  1155. return TVec4<T>(z(), w(), x(), z());
  1156. }
  1157. TVec4<T> zwxw() const
  1158. {
  1159. static_assert(N > 3, "Wrong vector");
  1160. return TVec4<T>(z(), w(), x(), w());
  1161. }
  1162. TVec4<T> zwyx() const
  1163. {
  1164. static_assert(N > 3, "Wrong vector");
  1165. return TVec4<T>(z(), w(), y(), x());
  1166. }
  1167. TVec4<T> zwyy() const
  1168. {
  1169. static_assert(N > 3, "Wrong vector");
  1170. return TVec4<T>(z(), w(), y(), y());
  1171. }
  1172. TVec4<T> zwyz() const
  1173. {
  1174. static_assert(N > 3, "Wrong vector");
  1175. return TVec4<T>(z(), w(), y(), z());
  1176. }
  1177. TVec4<T> zwyw() const
  1178. {
  1179. static_assert(N > 3, "Wrong vector");
  1180. return TVec4<T>(z(), w(), y(), w());
  1181. }
  1182. TVec4<T> zwzx() const
  1183. {
  1184. static_assert(N > 3, "Wrong vector");
  1185. return TVec4<T>(z(), w(), z(), x());
  1186. }
  1187. TVec4<T> zwzy() const
  1188. {
  1189. static_assert(N > 3, "Wrong vector");
  1190. return TVec4<T>(z(), w(), z(), y());
  1191. }
  1192. TVec4<T> zwzz() const
  1193. {
  1194. static_assert(N > 3, "Wrong vector");
  1195. return TVec4<T>(z(), w(), z(), z());
  1196. }
  1197. TVec4<T> zwzw() const
  1198. {
  1199. static_assert(N > 3, "Wrong vector");
  1200. return TVec4<T>(z(), w(), z(), w());
  1201. }
  1202. TVec4<T> zwwx() const
  1203. {
  1204. static_assert(N > 3, "Wrong vector");
  1205. return TVec4<T>(z(), w(), w(), x());
  1206. }
  1207. TVec4<T> zwwy() const
  1208. {
  1209. static_assert(N > 3, "Wrong vector");
  1210. return TVec4<T>(z(), w(), w(), y());
  1211. }
  1212. TVec4<T> zwwz() const
  1213. {
  1214. static_assert(N > 3, "Wrong vector");
  1215. return TVec4<T>(z(), w(), w(), z());
  1216. }
  1217. TVec4<T> zwww() const
  1218. {
  1219. static_assert(N > 3, "Wrong vector");
  1220. return TVec4<T>(z(), w(), w(), w());
  1221. }
  1222. TVec4<T> wxxx() const
  1223. {
  1224. static_assert(N > 3, "Wrong vector");
  1225. return TVec4<T>(w(), x(), x(), x());
  1226. }
  1227. TVec4<T> wxxy() const
  1228. {
  1229. static_assert(N > 3, "Wrong vector");
  1230. return TVec4<T>(w(), x(), x(), y());
  1231. }
  1232. TVec4<T> wxxz() const
  1233. {
  1234. static_assert(N > 3, "Wrong vector");
  1235. return TVec4<T>(w(), x(), x(), z());
  1236. }
  1237. TVec4<T> wxxw() const
  1238. {
  1239. static_assert(N > 3, "Wrong vector");
  1240. return TVec4<T>(w(), x(), x(), w());
  1241. }
  1242. TVec4<T> wxyx() const
  1243. {
  1244. static_assert(N > 3, "Wrong vector");
  1245. return TVec4<T>(w(), x(), y(), x());
  1246. }
  1247. TVec4<T> wxyy() const
  1248. {
  1249. static_assert(N > 3, "Wrong vector");
  1250. return TVec4<T>(w(), x(), y(), y());
  1251. }
  1252. TVec4<T> wxyz() const
  1253. {
  1254. static_assert(N > 3, "Wrong vector");
  1255. return TVec4<T>(w(), x(), y(), z());
  1256. }
  1257. TVec4<T> wxyw() const
  1258. {
  1259. static_assert(N > 3, "Wrong vector");
  1260. return TVec4<T>(w(), x(), y(), w());
  1261. }
  1262. TVec4<T> wxzx() const
  1263. {
  1264. static_assert(N > 3, "Wrong vector");
  1265. return TVec4<T>(w(), x(), z(), x());
  1266. }
  1267. TVec4<T> wxzy() const
  1268. {
  1269. static_assert(N > 3, "Wrong vector");
  1270. return TVec4<T>(w(), x(), z(), y());
  1271. }
  1272. TVec4<T> wxzz() const
  1273. {
  1274. static_assert(N > 3, "Wrong vector");
  1275. return TVec4<T>(w(), x(), z(), z());
  1276. }
  1277. TVec4<T> wxzw() const
  1278. {
  1279. static_assert(N > 3, "Wrong vector");
  1280. return TVec4<T>(w(), x(), z(), w());
  1281. }
  1282. TVec4<T> wxwx() const
  1283. {
  1284. static_assert(N > 3, "Wrong vector");
  1285. return TVec4<T>(w(), x(), w(), x());
  1286. }
  1287. TVec4<T> wxwy() const
  1288. {
  1289. static_assert(N > 3, "Wrong vector");
  1290. return TVec4<T>(w(), x(), w(), y());
  1291. }
  1292. TVec4<T> wxwz() const
  1293. {
  1294. static_assert(N > 3, "Wrong vector");
  1295. return TVec4<T>(w(), x(), w(), z());
  1296. }
  1297. TVec4<T> wxww() const
  1298. {
  1299. static_assert(N > 3, "Wrong vector");
  1300. return TVec4<T>(w(), x(), w(), w());
  1301. }
  1302. TVec4<T> wyxx() const
  1303. {
  1304. static_assert(N > 3, "Wrong vector");
  1305. return TVec4<T>(w(), y(), x(), x());
  1306. }
  1307. TVec4<T> wyxy() const
  1308. {
  1309. static_assert(N > 3, "Wrong vector");
  1310. return TVec4<T>(w(), y(), x(), y());
  1311. }
  1312. TVec4<T> wyxz() const
  1313. {
  1314. static_assert(N > 3, "Wrong vector");
  1315. return TVec4<T>(w(), y(), x(), z());
  1316. }
  1317. TVec4<T> wyxw() const
  1318. {
  1319. static_assert(N > 3, "Wrong vector");
  1320. return TVec4<T>(w(), y(), x(), w());
  1321. }
  1322. TVec4<T> wyyx() const
  1323. {
  1324. static_assert(N > 3, "Wrong vector");
  1325. return TVec4<T>(w(), y(), y(), x());
  1326. }
  1327. TVec4<T> wyyy() const
  1328. {
  1329. static_assert(N > 3, "Wrong vector");
  1330. return TVec4<T>(w(), y(), y(), y());
  1331. }
  1332. TVec4<T> wyyz() const
  1333. {
  1334. static_assert(N > 3, "Wrong vector");
  1335. return TVec4<T>(w(), y(), y(), z());
  1336. }
  1337. TVec4<T> wyyw() const
  1338. {
  1339. static_assert(N > 3, "Wrong vector");
  1340. return TVec4<T>(w(), y(), y(), w());
  1341. }
  1342. TVec4<T> wyzx() const
  1343. {
  1344. static_assert(N > 3, "Wrong vector");
  1345. return TVec4<T>(w(), y(), z(), x());
  1346. }
  1347. TVec4<T> wyzy() const
  1348. {
  1349. static_assert(N > 3, "Wrong vector");
  1350. return TVec4<T>(w(), y(), z(), y());
  1351. }
  1352. TVec4<T> wyzz() const
  1353. {
  1354. static_assert(N > 3, "Wrong vector");
  1355. return TVec4<T>(w(), y(), z(), z());
  1356. }
  1357. TVec4<T> wyzw() const
  1358. {
  1359. static_assert(N > 3, "Wrong vector");
  1360. return TVec4<T>(w(), y(), z(), w());
  1361. }
  1362. TVec4<T> wywx() const
  1363. {
  1364. static_assert(N > 3, "Wrong vector");
  1365. return TVec4<T>(w(), y(), w(), x());
  1366. }
  1367. TVec4<T> wywy() const
  1368. {
  1369. static_assert(N > 3, "Wrong vector");
  1370. return TVec4<T>(w(), y(), w(), y());
  1371. }
  1372. TVec4<T> wywz() const
  1373. {
  1374. static_assert(N > 3, "Wrong vector");
  1375. return TVec4<T>(w(), y(), w(), z());
  1376. }
  1377. TVec4<T> wyww() const
  1378. {
  1379. static_assert(N > 3, "Wrong vector");
  1380. return TVec4<T>(w(), y(), w(), w());
  1381. }
  1382. TVec4<T> wzxx() const
  1383. {
  1384. static_assert(N > 3, "Wrong vector");
  1385. return TVec4<T>(w(), z(), x(), x());
  1386. }
  1387. TVec4<T> wzxy() const
  1388. {
  1389. static_assert(N > 3, "Wrong vector");
  1390. return TVec4<T>(w(), z(), x(), y());
  1391. }
  1392. TVec4<T> wzxz() const
  1393. {
  1394. static_assert(N > 3, "Wrong vector");
  1395. return TVec4<T>(w(), z(), x(), z());
  1396. }
  1397. TVec4<T> wzxw() const
  1398. {
  1399. static_assert(N > 3, "Wrong vector");
  1400. return TVec4<T>(w(), z(), x(), w());
  1401. }
  1402. TVec4<T> wzyx() const
  1403. {
  1404. static_assert(N > 3, "Wrong vector");
  1405. return TVec4<T>(w(), z(), y(), x());
  1406. }
  1407. TVec4<T> wzyy() const
  1408. {
  1409. static_assert(N > 3, "Wrong vector");
  1410. return TVec4<T>(w(), z(), y(), y());
  1411. }
  1412. TVec4<T> wzyz() const
  1413. {
  1414. static_assert(N > 3, "Wrong vector");
  1415. return TVec4<T>(w(), z(), y(), z());
  1416. }
  1417. TVec4<T> wzyw() const
  1418. {
  1419. static_assert(N > 3, "Wrong vector");
  1420. return TVec4<T>(w(), z(), y(), w());
  1421. }
  1422. TVec4<T> wzzx() const
  1423. {
  1424. static_assert(N > 3, "Wrong vector");
  1425. return TVec4<T>(w(), z(), z(), x());
  1426. }
  1427. TVec4<T> wzzy() const
  1428. {
  1429. static_assert(N > 3, "Wrong vector");
  1430. return TVec4<T>(w(), z(), z(), y());
  1431. }
  1432. TVec4<T> wzzz() const
  1433. {
  1434. static_assert(N > 3, "Wrong vector");
  1435. return TVec4<T>(w(), z(), z(), z());
  1436. }
  1437. TVec4<T> wzzw() const
  1438. {
  1439. static_assert(N > 3, "Wrong vector");
  1440. return TVec4<T>(w(), z(), z(), w());
  1441. }
  1442. TVec4<T> wzwx() const
  1443. {
  1444. static_assert(N > 3, "Wrong vector");
  1445. return TVec4<T>(w(), z(), w(), x());
  1446. }
  1447. TVec4<T> wzwy() const
  1448. {
  1449. static_assert(N > 3, "Wrong vector");
  1450. return TVec4<T>(w(), z(), w(), y());
  1451. }
  1452. TVec4<T> wzwz() const
  1453. {
  1454. static_assert(N > 3, "Wrong vector");
  1455. return TVec4<T>(w(), z(), w(), z());
  1456. }
  1457. TVec4<T> wzww() const
  1458. {
  1459. static_assert(N > 3, "Wrong vector");
  1460. return TVec4<T>(w(), z(), w(), w());
  1461. }
  1462. TVec4<T> wwxx() const
  1463. {
  1464. static_assert(N > 3, "Wrong vector");
  1465. return TVec4<T>(w(), w(), x(), x());
  1466. }
  1467. TVec4<T> wwxy() const
  1468. {
  1469. static_assert(N > 3, "Wrong vector");
  1470. return TVec4<T>(w(), w(), x(), y());
  1471. }
  1472. TVec4<T> wwxz() const
  1473. {
  1474. static_assert(N > 3, "Wrong vector");
  1475. return TVec4<T>(w(), w(), x(), z());
  1476. }
  1477. TVec4<T> wwxw() const
  1478. {
  1479. static_assert(N > 3, "Wrong vector");
  1480. return TVec4<T>(w(), w(), x(), w());
  1481. }
  1482. TVec4<T> wwyx() const
  1483. {
  1484. static_assert(N > 3, "Wrong vector");
  1485. return TVec4<T>(w(), w(), y(), x());
  1486. }
  1487. TVec4<T> wwyy() const
  1488. {
  1489. static_assert(N > 3, "Wrong vector");
  1490. return TVec4<T>(w(), w(), y(), y());
  1491. }
  1492. TVec4<T> wwyz() const
  1493. {
  1494. static_assert(N > 3, "Wrong vector");
  1495. return TVec4<T>(w(), w(), y(), z());
  1496. }
  1497. TVec4<T> wwyw() const
  1498. {
  1499. static_assert(N > 3, "Wrong vector");
  1500. return TVec4<T>(w(), w(), y(), w());
  1501. }
  1502. TVec4<T> wwzx() const
  1503. {
  1504. static_assert(N > 3, "Wrong vector");
  1505. return TVec4<T>(w(), w(), z(), x());
  1506. }
  1507. TVec4<T> wwzy() const
  1508. {
  1509. static_assert(N > 3, "Wrong vector");
  1510. return TVec4<T>(w(), w(), z(), y());
  1511. }
  1512. TVec4<T> wwzz() const
  1513. {
  1514. static_assert(N > 3, "Wrong vector");
  1515. return TVec4<T>(w(), w(), z(), z());
  1516. }
  1517. TVec4<T> wwzw() const
  1518. {
  1519. static_assert(N > 3, "Wrong vector");
  1520. return TVec4<T>(w(), w(), z(), w());
  1521. }
  1522. TVec4<T> wwwx() const
  1523. {
  1524. static_assert(N > 3, "Wrong vector");
  1525. return TVec4<T>(w(), w(), w(), x());
  1526. }
  1527. TVec4<T> wwwy() const
  1528. {
  1529. static_assert(N > 3, "Wrong vector");
  1530. return TVec4<T>(w(), w(), w(), y());
  1531. }
  1532. TVec4<T> wwwz() const
  1533. {
  1534. static_assert(N > 3, "Wrong vector");
  1535. return TVec4<T>(w(), w(), w(), z());
  1536. }
  1537. TVec4<T> wwww() const
  1538. {
  1539. static_assert(N > 3, "Wrong vector");
  1540. return TVec4<T>(w(), w(), w(), w());
  1541. }
  1542. TVec4<T> xyz1() const
  1543. {
  1544. static_assert(N > 2, "Wrong vector");
  1545. return TVec4<T>(x(), y(), z(), static_cast<T>(1));
  1546. }
  1547. TVec4<T> xyz0() const
  1548. {
  1549. static_assert(N > 2, "Wrong vector");
  1550. return TVec4<T>(x(), y(), z(), static_cast<T>(0));
  1551. }
  1552. T& operator[](const U i)
  1553. {
  1554. return m_arr[i];
  1555. }
  1556. T operator[](const U i) const
  1557. {
  1558. return m_arr[i];
  1559. }
  1560. TSimd& getSimd()
  1561. {
  1562. return m_simd;
  1563. }
  1564. const TSimd& getSimd() const
  1565. {
  1566. return m_simd;
  1567. }
  1568. /// @}
  1569. /// @name Operators with same type
  1570. /// @{
  1571. TVec& operator=(const TVec& b)
  1572. {
  1573. for(U i = 0; i < N; i++)
  1574. {
  1575. m_arr[i] = b.m_arr[i];
  1576. }
  1577. return *this;
  1578. }
  1579. TV& operator=(const TV& b)
  1580. {
  1581. for(U i = 0; i < N; i++)
  1582. {
  1583. m_arr[i] = b.m_arr[i];
  1584. }
  1585. return static_cast<TV&>(*this);
  1586. }
  1587. TV operator+(const TV& b) const
  1588. {
  1589. TV out;
  1590. for(U i = 0; i < N; i++)
  1591. {
  1592. out.m_arr[i] = m_arr[i] + b.m_arr[i];
  1593. }
  1594. return out;
  1595. }
  1596. TV& operator+=(const TV& b)
  1597. {
  1598. for(U i = 0; i < N; i++)
  1599. {
  1600. m_arr[i] += b.m_arr[i];
  1601. }
  1602. return static_cast<TV&>(*this);
  1603. }
  1604. TV operator-(const TV& b) const
  1605. {
  1606. TV out;
  1607. for(U i = 0; i < N; i++)
  1608. {
  1609. out.m_arr[i] = m_arr[i] - b.m_arr[i];
  1610. }
  1611. return out;
  1612. }
  1613. TV& operator-=(const TV& b)
  1614. {
  1615. for(U i = 0; i < N; i++)
  1616. {
  1617. m_arr[i] -= b.m_arr[i];
  1618. }
  1619. return static_cast<TV&>(*this);
  1620. }
  1621. TV operator*(const TV& b) const
  1622. {
  1623. TV out;
  1624. for(U i = 0; i < N; i++)
  1625. {
  1626. out.m_arr[i] = m_arr[i] * b.m_arr[i];
  1627. }
  1628. return out;
  1629. }
  1630. TV& operator*=(const TV& b)
  1631. {
  1632. for(U i = 0; i < N; i++)
  1633. {
  1634. m_arr[i] *= b.m_arr[i];
  1635. }
  1636. return static_cast<TV&>(*this);
  1637. }
  1638. TV operator/(const TV& b) const
  1639. {
  1640. TV out;
  1641. for(U i = 0; i < N; i++)
  1642. {
  1643. ANKI_ASSERT(b.m_arr[i] != 0.0);
  1644. out.m_arr[i] = m_arr[i] / b.m_arr[i];
  1645. }
  1646. return out;
  1647. }
  1648. TV& operator/=(const TV& b)
  1649. {
  1650. for(U i = 0; i < N; i++)
  1651. {
  1652. ANKI_ASSERT(b.m_arr[i] != 0.0);
  1653. m_arr[i] /= b.m_arr[i];
  1654. }
  1655. return static_cast<TV&>(*this);
  1656. }
  1657. TV operator-() const
  1658. {
  1659. TV out;
  1660. for(U i = 0; i < N; i++)
  1661. {
  1662. out.m_arr[i] = -m_arr[i];
  1663. }
  1664. return out;
  1665. }
  1666. Bool operator==(const TV& b) const
  1667. {
  1668. for(U i = 0; i < N; i++)
  1669. {
  1670. if(!isZero<T>(m_arr[i] - b.m_arr[i]))
  1671. {
  1672. return false;
  1673. }
  1674. }
  1675. return true;
  1676. }
  1677. Bool operator!=(const TV& b) const
  1678. {
  1679. return !operator==(b);
  1680. }
  1681. Bool operator<(const TV& b) const
  1682. {
  1683. for(U i = 0; i < N; i++)
  1684. {
  1685. if(m_arr[i] >= b.m_arr[i])
  1686. {
  1687. return false;
  1688. }
  1689. }
  1690. return true;
  1691. }
  1692. Bool operator<=(const TV& b) const
  1693. {
  1694. for(U i = 0; i < N; i++)
  1695. {
  1696. if(m_arr[i] > b.m_arr[i])
  1697. {
  1698. return false;
  1699. }
  1700. }
  1701. return true;
  1702. }
  1703. Bool operator>(const TV& b) const
  1704. {
  1705. for(U i = 0; i < N; i++)
  1706. {
  1707. if(m_arr[i] <= b.m_arr[i])
  1708. {
  1709. return false;
  1710. }
  1711. }
  1712. return true;
  1713. }
  1714. Bool operator>=(const TV& b) const
  1715. {
  1716. for(U i = 0; i < N; i++)
  1717. {
  1718. if(m_arr[i] < b.m_arr[i])
  1719. {
  1720. return false;
  1721. }
  1722. }
  1723. return true;
  1724. }
  1725. /// @}
  1726. /// @name Operators with T
  1727. /// @{
  1728. TV operator+(const T f) const
  1729. {
  1730. return (*this) + TV(f);
  1731. }
  1732. TV& operator+=(const T f)
  1733. {
  1734. (*this) += TV(f);
  1735. return static_cast<TV&>(*this);
  1736. }
  1737. TV operator-(const T f) const
  1738. {
  1739. return (*this) - TV(f);
  1740. }
  1741. TV& operator-=(const T f)
  1742. {
  1743. (*this) -= TV(f);
  1744. return static_cast<TV&>(*this);
  1745. }
  1746. TV operator*(const T f) const
  1747. {
  1748. return (*this) * TV(f);
  1749. }
  1750. TV& operator*=(const T f)
  1751. {
  1752. (*this) *= TV(f);
  1753. return static_cast<TV&>(*this);
  1754. }
  1755. TV operator/(const T f) const
  1756. {
  1757. return (*this) / TV(f);
  1758. }
  1759. TV& operator/=(const T f)
  1760. {
  1761. (*this) /= TV(f);
  1762. return static_cast<TV&>(*this);
  1763. }
  1764. /// @}
  1765. /// @name Other
  1766. /// @{
  1767. T dot(const TV& b) const
  1768. {
  1769. T out = 0.0;
  1770. for(U i = 0; i < N; i++)
  1771. {
  1772. out += m_arr[i] * b.m_arr[i];
  1773. }
  1774. return out;
  1775. }
  1776. T getLengthSquared() const
  1777. {
  1778. T out = 0.0;
  1779. for(U i = 0; i < N; i++)
  1780. {
  1781. out += m_arr[i] * m_arr[i];
  1782. }
  1783. return out;
  1784. }
  1785. T getLength() const
  1786. {
  1787. return sqrt<T>(getLengthSquared());
  1788. }
  1789. T getDistanceSquared(const TV& b) const
  1790. {
  1791. return ((*this) - b).getLengthSquared();
  1792. }
  1793. T getDistance(const TV& b) const
  1794. {
  1795. return sqrt<T>(getDistance(b));
  1796. }
  1797. void normalize()
  1798. {
  1799. (*this) /= getLength();
  1800. }
  1801. TV getNormalized() const
  1802. {
  1803. return (*this) / getLength();
  1804. }
  1805. /// Return lerp(this, v1, t)
  1806. TV lerp(const TV& v1, T t) const
  1807. {
  1808. return ((*this) * (1.0 - t)) + (v1 * t);
  1809. }
  1810. TV getAbs() const
  1811. {
  1812. TV out;
  1813. for(U i = 0; i < N; ++i)
  1814. {
  1815. out[i] = fabs<T>(m_arr[i]);
  1816. }
  1817. return out;
  1818. }
  1819. template<typename TAlloc>
  1820. String toString(TAlloc alloc) const
  1821. {
  1822. ANKI_ASSERT(0 && "TODO");
  1823. return String();
  1824. }
  1825. /// @}
  1826. protected:
  1827. /// @name Data
  1828. /// @{
  1829. union
  1830. {
  1831. Array<T, N> m_arr;
  1832. TSimd m_simd;
  1833. };
  1834. /// @}
  1835. };
  1836. /// @}
  1837. } // end namespace anki