lvecBase4_src.I 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. // Filename: lvecBase4_src.I
  2. // Created by: drose (08Mar00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. ////////////////////////////////////////////////////////////////////
  15. // Function: LVecBase4::Default Constructor
  16. // Access: Public
  17. // Description:
  18. ////////////////////////////////////////////////////////////////////
  19. INLINE_LINMATH FLOATNAME(LVecBase4)::
  20. FLOATNAME(LVecBase4)() {
  21. }
  22. ////////////////////////////////////////////////////////////////////
  23. // Function: LVecBase4::Copy Constructor
  24. // Access: Public
  25. // Description:
  26. ////////////////////////////////////////////////////////////////////
  27. INLINE_LINMATH FLOATNAME(LVecBase4)::
  28. FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) &copy) {
  29. TAU_PROFILE("LVecBase4::LVecBase4(LVecBase4 &)", " ", TAU_USER);
  30. _v.v._0 = copy._v.v._0;
  31. _v.v._1 = copy._v.v._1;
  32. _v.v._2 = copy._v.v._2;
  33. _v.v._3 = copy._v.v._3;
  34. // (*this) = copy;
  35. }
  36. ////////////////////////////////////////////////////////////////////
  37. // Function: LVecBase4::Copy Assignment Operator
  38. // Access: Public
  39. // Description:
  40. ////////////////////////////////////////////////////////////////////
  41. INLINE_LINMATH FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4)::
  42. operator = (const FLOATNAME(LVecBase4) &copy) {
  43. TAU_PROFILE("void LVecBase4::operator = (LVecBase4 &)", " ", TAU_USER);
  44. _v.v._0 = copy._v.v._0;
  45. _v.v._1 = copy._v.v._1;
  46. _v.v._2 = copy._v.v._2;
  47. _v.v._3 = copy._v.v._3;
  48. // set(copy[0], copy[1], copy[2], copy[3]);
  49. return *this;
  50. }
  51. ////////////////////////////////////////////////////////////////////
  52. // Function: LVecBase4::Fill Assignment Operator
  53. // Access: Public
  54. // Description:
  55. ////////////////////////////////////////////////////////////////////
  56. INLINE_LINMATH FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4)::
  57. operator = (FLOATTYPE fill_value) {
  58. fill(fill_value);
  59. return *this;
  60. }
  61. ////////////////////////////////////////////////////////////////////
  62. // Function: LVecBase4::Constructor
  63. // Access: Public
  64. // Description:
  65. ////////////////////////////////////////////////////////////////////
  66. INLINE_LINMATH FLOATNAME(LVecBase4)::
  67. FLOATNAME(LVecBase4)(FLOATTYPE fill_value) {
  68. fill(fill_value);
  69. }
  70. ////////////////////////////////////////////////////////////////////
  71. // Function: LVecBase4::Constructor
  72. // Access: Public
  73. // Description:
  74. ////////////////////////////////////////////////////////////////////
  75. INLINE_LINMATH FLOATNAME(LVecBase4)::
  76. FLOATNAME(LVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) {
  77. TAU_PROFILE("void LVecBase4::operator = (FLOATTYPE, ...)", " ", TAU_USER);
  78. _v.v._0 = x;
  79. _v.v._1 = y;
  80. _v.v._2 = z;
  81. _v.v._3 = w;
  82. // set(x, y, z, w);
  83. }
  84. ////////////////////////////////////////////////////////////////////
  85. // Function: LVecBase4::Destructor
  86. // Access: Public
  87. // Description:
  88. ////////////////////////////////////////////////////////////////////
  89. INLINE_LINMATH FLOATNAME(LVecBase4)::
  90. ~FLOATNAME(LVecBase4)() {
  91. }
  92. ////////////////////////////////////////////////////////////////////
  93. // Function: LVecBase4::zero Named Constructor
  94. // Access: Public
  95. // Description: Returns a zero-length vector.
  96. ////////////////////////////////////////////////////////////////////
  97. INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4)::
  98. zero() {
  99. return _zero;
  100. }
  101. ////////////////////////////////////////////////////////////////////
  102. // Function: LVecBase4::unit_x Named Constructor
  103. // Access: Public
  104. // Description: Returns a unit X vector.
  105. ////////////////////////////////////////////////////////////////////
  106. INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4)::
  107. unit_x() {
  108. return _unit_x;
  109. }
  110. ////////////////////////////////////////////////////////////////////
  111. // Function: LVecBase4::unit_y Named Constructor
  112. // Access: Public
  113. // Description: Returns a unit Y vector.
  114. ////////////////////////////////////////////////////////////////////
  115. INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4)::
  116. unit_y() {
  117. return _unit_y;
  118. }
  119. ////////////////////////////////////////////////////////////////////
  120. // Function: LVecBase4::unit_z Named Constructor
  121. // Access: Public
  122. // Description: Returns a unit Z vector.
  123. ////////////////////////////////////////////////////////////////////
  124. INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4)::
  125. unit_z() {
  126. return _unit_z;
  127. }
  128. ////////////////////////////////////////////////////////////////////
  129. // Function: LVecBase4::unit_w Named Constructor
  130. // Access: Public
  131. // Description: Returns a unit W vector.
  132. ////////////////////////////////////////////////////////////////////
  133. INLINE_LINMATH const FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4)::
  134. unit_w() {
  135. return _unit_w;
  136. }
  137. ////////////////////////////////////////////////////////////////////
  138. // Function: LVecBase4::Indexing Operator
  139. // Access: Public
  140. // Description:
  141. ////////////////////////////////////////////////////////////////////
  142. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
  143. operator [](int i) const {
  144. nassertr(i >= 0 && i < 4, 0.0);
  145. return _v.data[i];
  146. }
  147. ////////////////////////////////////////////////////////////////////
  148. // Function: LVecBase4::Indexing Operator
  149. // Access: Public
  150. // Description:
  151. ////////////////////////////////////////////////////////////////////
  152. INLINE_LINMATH FLOATTYPE &FLOATNAME(LVecBase4)::
  153. operator [](int i) {
  154. nassertr(i >= 0 && i < 4, _v.data[0]);
  155. return _v.data[i];
  156. }
  157. #ifdef HAVE_PYTHON
  158. ////////////////////////////////////////////////////////////////////
  159. // Function: LVecBase4::__setitem__
  160. // Access: Public
  161. // Description:
  162. ////////////////////////////////////////////////////////////////////
  163. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  164. __setitem__(int i, FLOATTYPE v) {
  165. nassertv(i >= 0 && i < 4);
  166. _v.data[i] = v;
  167. }
  168. #endif // HAVE_PYTHON
  169. ////////////////////////////////////////////////////////////////////
  170. // Function: LVecBase4::size
  171. // Access: Public, Static
  172. // Description: Returns 4: the number of components of a LVecBase4.
  173. ////////////////////////////////////////////////////////////////////
  174. INLINE_LINMATH int FLOATNAME(LVecBase4)::
  175. size() {
  176. return 4;
  177. }
  178. ////////////////////////////////////////////////////////////////////
  179. // Function: LVecBase4::is_nan
  180. // Access: Public
  181. // Description: Returns true if any component of the vector is
  182. // not-a-number, false otherwise.
  183. ////////////////////////////////////////////////////////////////////
  184. INLINE_LINMATH bool FLOATNAME(LVecBase4)::
  185. is_nan() const {
  186. TAU_PROFILE("bool LVecBase4::is_nan()", " ", TAU_USER);
  187. return cnan(_v.v._0) || cnan(_v.v._1) || cnan(_v.v._2) || cnan(_v.v._3);
  188. }
  189. ////////////////////////////////////////////////////////////////////
  190. // Function: LVecBase4::get_cell
  191. // Access: Public
  192. // Description:
  193. ////////////////////////////////////////////////////////////////////
  194. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
  195. get_cell(int i) const {
  196. nassertr(i >= 0 && i < 4, 0.0);
  197. return _v.data[i];
  198. }
  199. ////////////////////////////////////////////////////////////////////
  200. // Function: LVecBase4::get_x
  201. // Access: Public
  202. // Description:
  203. ////////////////////////////////////////////////////////////////////
  204. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
  205. get_x() const {
  206. return _v.v._0;
  207. }
  208. ////////////////////////////////////////////////////////////////////
  209. // Function: LVecBase4::get_y
  210. // Access: Public
  211. // Description:
  212. ////////////////////////////////////////////////////////////////////
  213. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
  214. get_y() const {
  215. return _v.v._1;
  216. }
  217. ////////////////////////////////////////////////////////////////////
  218. // Function: LVecBase4::get_z
  219. // Access: Public
  220. // Description:
  221. ////////////////////////////////////////////////////////////////////
  222. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
  223. get_z() const {
  224. return _v.v._2;
  225. }
  226. ////////////////////////////////////////////////////////////////////
  227. // Function: LVecBase4::get_w
  228. // Access: Public
  229. // Description:
  230. ////////////////////////////////////////////////////////////////////
  231. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
  232. get_w() const {
  233. return _v.v._3;
  234. }
  235. ////////////////////////////////////////////////////////////////////
  236. // Function: LVecBase4::set_cell
  237. // Access: Public
  238. // Description:
  239. ////////////////////////////////////////////////////////////////////
  240. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  241. set_cell(int i, FLOATTYPE value) {
  242. nassertv(i >= 0 && i < 4);
  243. _v.data[i] = value;
  244. }
  245. ////////////////////////////////////////////////////////////////////
  246. // Function: LVecBase4::set_x
  247. // Access: Public
  248. // Description:
  249. ////////////////////////////////////////////////////////////////////
  250. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  251. set_x(FLOATTYPE value) {
  252. _v.v._0 = value;
  253. }
  254. ////////////////////////////////////////////////////////////////////
  255. // Function: LVecBase4::set_y
  256. // Access: Public
  257. // Description:
  258. ////////////////////////////////////////////////////////////////////
  259. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  260. set_y(FLOATTYPE value) {
  261. _v.v._1 = value;
  262. }
  263. ////////////////////////////////////////////////////////////////////
  264. // Function: LVecBase4::set_z
  265. // Access: Public
  266. // Description:
  267. ////////////////////////////////////////////////////////////////////
  268. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  269. set_z(FLOATTYPE value) {
  270. _v.v._2 = value;
  271. }
  272. ////////////////////////////////////////////////////////////////////
  273. // Function: LVecBase4::set_w
  274. // Access: Public
  275. // Description:
  276. ////////////////////////////////////////////////////////////////////
  277. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  278. set_w(FLOATTYPE value) {
  279. _v.v._3 = value;
  280. }
  281. ////////////////////////////////////////////////////////////////////
  282. // Function: LVecBase4::add_to_cell
  283. // Access: Public
  284. // Description:
  285. ////////////////////////////////////////////////////////////////////
  286. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  287. add_to_cell(int i, FLOATTYPE value) {
  288. nassertv(i >= 0 && i < 4);
  289. _v.data[i] += value;
  290. }
  291. ////////////////////////////////////////////////////////////////////
  292. // Function: LVecBase4::add_x
  293. // Access: Public
  294. // Description:
  295. ////////////////////////////////////////////////////////////////////
  296. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  297. add_x(FLOATTYPE value) {
  298. _v.v._0 += value;
  299. }
  300. ////////////////////////////////////////////////////////////////////
  301. // Function: LVecBase4::add_y
  302. // Access: Public
  303. // Description:
  304. ////////////////////////////////////////////////////////////////////
  305. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  306. add_y(FLOATTYPE value) {
  307. _v.v._1 += value;
  308. }
  309. ////////////////////////////////////////////////////////////////////
  310. // Function: LVecBase4::add_z
  311. // Access: Public
  312. // Description:
  313. ////////////////////////////////////////////////////////////////////
  314. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  315. add_z(FLOATTYPE value) {
  316. _v.v._2 += value;
  317. }
  318. ////////////////////////////////////////////////////////////////////
  319. // Function: LVecBase4::add_w
  320. // Access: Public
  321. // Description:
  322. ////////////////////////////////////////////////////////////////////
  323. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  324. add_w(FLOATTYPE value) {
  325. _v.v._3 += value;
  326. }
  327. ////////////////////////////////////////////////////////////////////
  328. // Function: LVecBase4::get_data
  329. // Access: Public
  330. // Description: Returns the address of the first of the four data
  331. // elements in the vector. The remaining elements
  332. // occupy the next positions consecutively in memory.
  333. ////////////////////////////////////////////////////////////////////
  334. INLINE_LINMATH const FLOATTYPE *FLOATNAME(LVecBase4)::
  335. get_data() const {
  336. return _v.data;
  337. }
  338. ////////////////////////////////////////////////////////////////////
  339. // Function: LVecBase4::get_num_components
  340. // Access: Public
  341. // Description: Returns the number of elements in the vector, four.
  342. ////////////////////////////////////////////////////////////////////
  343. INLINE_LINMATH int FLOATNAME(LVecBase4)::
  344. get_num_components() const {
  345. return 4;
  346. }
  347. ////////////////////////////////////////////////////////////////////
  348. // Function: LVecBase4::begin
  349. // Access: Public
  350. // Description: Returns an iterator that may be used to traverse the
  351. // elements of the matrix, STL-style.
  352. ////////////////////////////////////////////////////////////////////
  353. INLINE_LINMATH FLOATNAME(LVecBase4)::iterator FLOATNAME(LVecBase4)::
  354. begin() {
  355. return _v.data;
  356. }
  357. ////////////////////////////////////////////////////////////////////
  358. // Function: LVecBase4::end
  359. // Access: Public
  360. // Description: Returns an iterator that may be used to traverse the
  361. // elements of the matrix, STL-style.
  362. ////////////////////////////////////////////////////////////////////
  363. INLINE_LINMATH FLOATNAME(LVecBase4)::iterator FLOATNAME(LVecBase4)::
  364. end() {
  365. return begin() + get_num_components();
  366. }
  367. ////////////////////////////////////////////////////////////////////
  368. // Function: LVecBase4::begin
  369. // Access: Public
  370. // Description: Returns an iterator that may be used to traverse the
  371. // elements of the matrix, STL-style.
  372. ////////////////////////////////////////////////////////////////////
  373. INLINE_LINMATH FLOATNAME(LVecBase4)::const_iterator FLOATNAME(LVecBase4)::
  374. begin() const {
  375. return _v.data;
  376. }
  377. ////////////////////////////////////////////////////////////////////
  378. // Function: LVecBase4::end
  379. // Access: Public
  380. // Description: Returns an iterator that may be used to traverse the
  381. // elements of the matrix, STL-style.
  382. ////////////////////////////////////////////////////////////////////
  383. INLINE_LINMATH FLOATNAME(LVecBase4)::const_iterator FLOATNAME(LVecBase4)::
  384. end() const {
  385. return begin() + get_num_components();
  386. }
  387. ////////////////////////////////////////////////////////////////////
  388. // Function: LVecBase4::fill
  389. // Access: Public
  390. // Description: Sets each element of the vector to the indicated
  391. // fill_value. This is particularly useful for
  392. // initializing to zero.
  393. ////////////////////////////////////////////////////////////////////
  394. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  395. fill(FLOATTYPE fill_value) {
  396. TAU_PROFILE("void LVecBase4::fill()", " ", TAU_USER);
  397. _v.v._0 = fill_value;
  398. _v.v._1 = fill_value;
  399. _v.v._2 = fill_value;
  400. _v.v._3 = fill_value;
  401. }
  402. ////////////////////////////////////////////////////////////////////
  403. // Function: LVecBase4::set
  404. // Access: Public
  405. // Description:
  406. ////////////////////////////////////////////////////////////////////
  407. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  408. set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) {
  409. TAU_PROFILE("void LVecBase4::set()", " ", TAU_USER);
  410. _v.v._0 = x;
  411. _v.v._1 = y;
  412. _v.v._2 = z;
  413. _v.v._3 = w;
  414. }
  415. ////////////////////////////////////////////////////////////////////
  416. // Function: LVecBase4::length
  417. // Access: Public
  418. // Description: Returns the length of the vector, by the Pythagorean
  419. // theorem.
  420. ////////////////////////////////////////////////////////////////////
  421. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
  422. length() const {
  423. return csqrt((*this).dot(*this));
  424. }
  425. ////////////////////////////////////////////////////////////////////
  426. // Function: LVecBase4::length_squared
  427. // Access: Public
  428. // Description: Returns the square of the vector's length, cheap and
  429. // easy.
  430. ////////////////////////////////////////////////////////////////////
  431. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
  432. length_squared() const {
  433. return (*this).dot(*this);
  434. }
  435. ////////////////////////////////////////////////////////////////////
  436. // Function: LVecBase4::normalize
  437. // Access: Public
  438. // Description: Normalizes the vector in place. Returns true if the
  439. // vector was normalized, false if it was a zero-length
  440. // vector.
  441. ////////////////////////////////////////////////////////////////////
  442. INLINE_LINMATH bool FLOATNAME(LVecBase4)::
  443. normalize() {
  444. FLOATTYPE l2 = length_squared();
  445. if (l2 == (FLOATTYPE)0.0f) {
  446. set(0.0f, 0.0f, 0.0f, 0.0f);
  447. return false;
  448. } else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) {
  449. (*this) /= csqrt(l2);
  450. }
  451. return true;
  452. }
  453. ////////////////////////////////////////////////////////////////////
  454. // Function: LVecBase4::dot
  455. // Access: Public
  456. // Description:
  457. ////////////////////////////////////////////////////////////////////
  458. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
  459. dot(const FLOATNAME(LVecBase4) &other) const {
  460. TAU_PROFILE("FLOATTYPE LVecBase4::dot()", " ", TAU_USER);
  461. return
  462. _v.v._0 * other._v.v._0 + _v.v._1 * other._v.v._1 +
  463. _v.v._2 * other._v.v._2 + _v.v._3 * other._v.v._3;
  464. }
  465. ////////////////////////////////////////////////////////////////////
  466. // Function: LVecBase4::project
  467. // Access: Published
  468. // Description: Returns a new vector representing the projection of
  469. // this vector onto another one. The resulting vector
  470. // will be a scalar multiple of onto.
  471. ////////////////////////////////////////////////////////////////////
  472. INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
  473. project(const FLOATNAME(LVecBase4) &onto) const {
  474. return onto * (dot(onto) / onto.length_squared());
  475. }
  476. ////////////////////////////////////////////////////////////////////
  477. // Function: LVecBase4::operator <
  478. // Access: Public
  479. // Description: This performs a lexicographical comparison. It's of
  480. // questionable mathematical meaning, but sometimes has
  481. // a practical purpose for sorting unique vectors,
  482. // especially in an STL container. Also see
  483. // compare_to().
  484. ////////////////////////////////////////////////////////////////////
  485. INLINE_LINMATH bool FLOATNAME(LVecBase4)::
  486. operator < (const FLOATNAME(LVecBase4) &other) const {
  487. TAU_PROFILE("bool LVecBase4::operator <(const LVecBase4 &)", " ", TAU_USER);
  488. return (compare_to(other) < 0);
  489. }
  490. ////////////////////////////////////////////////////////////////////
  491. // Function: LVecBase4::operator ==
  492. // Access: Public
  493. // Description:
  494. ////////////////////////////////////////////////////////////////////
  495. INLINE_LINMATH bool FLOATNAME(LVecBase4)::
  496. operator == (const FLOATNAME(LVecBase4) &other) const {
  497. TAU_PROFILE("bool LVecBase4::operator ==(const LVecBase4 &)", " ", TAU_USER);
  498. return (_v.v._0 == other._v.v._0 &&
  499. _v.v._1 == other._v.v._1 &&
  500. _v.v._2 == other._v.v._2 &&
  501. _v.v._3 == other._v.v._3);
  502. }
  503. ////////////////////////////////////////////////////////////////////
  504. // Function: LVecBase4::operator !=
  505. // Access: Public
  506. // Description:
  507. ////////////////////////////////////////////////////////////////////
  508. INLINE_LINMATH bool FLOATNAME(LVecBase4)::
  509. operator != (const FLOATNAME(LVecBase4) &other) const {
  510. return !operator == (other);
  511. }
  512. ////////////////////////////////////////////////////////////////////
  513. // Function: LVecBase4::compare_to
  514. // Access: Public
  515. // Description: This flavor of compare_to uses a default threshold
  516. // value based on the numeric type.
  517. ////////////////////////////////////////////////////////////////////
  518. INLINE_LINMATH int FLOATNAME(LVecBase4)::
  519. compare_to(const FLOATNAME(LVecBase4) &other) const {
  520. TAU_PROFILE("int LVecBase4::compare_to(const LVecBase4 &)", " ", TAU_USER);
  521. return compare_to(other, NEARLY_ZERO(FLOATTYPE));
  522. }
  523. ////////////////////////////////////////////////////////////////////
  524. // Function: LVecBase4::compare_to
  525. // Access: Public
  526. // Description: Sorts vectors lexicographically, componentwise.
  527. // Returns a number less than 0 if this vector sorts
  528. // before the other one, greater than zero if it sorts
  529. // after, 0 if they are equivalent (within the indicated
  530. // tolerance).
  531. ////////////////////////////////////////////////////////////////////
  532. INLINE_LINMATH int FLOATNAME(LVecBase4)::
  533. compare_to(const FLOATNAME(LVecBase4) &other, FLOATTYPE threshold) const {
  534. TAU_PROFILE("int LVecBase4::compare_to(const LVecBase4 &, FLOATTYPE)", " ", TAU_USER);
  535. if (!IS_THRESHOLD_COMPEQ(_v.v._0, other._v.v._0, threshold)) {
  536. return (_v.v._0 < other._v.v._0) ? -1 : 1;
  537. }
  538. if (!IS_THRESHOLD_COMPEQ(_v.v._1, other._v.v._1, threshold)) {
  539. return (_v.v._1 < other._v.v._1) ? -1 : 1;
  540. }
  541. if (!IS_THRESHOLD_COMPEQ(_v.v._2, other._v.v._2, threshold)) {
  542. return (_v.v._2 < other._v.v._2) ? -1 : 1;
  543. }
  544. if (!IS_THRESHOLD_COMPEQ(_v.v._3, other._v.v._3, threshold)) {
  545. return (_v.v._3 < other._v.v._3) ? -1 : 1;
  546. }
  547. return 0;
  548. }
  549. ////////////////////////////////////////////////////////////////////
  550. // Function: LVecBase4::get_hash
  551. // Access: Public
  552. // Description: Returns a suitable hash for phash_map.
  553. ////////////////////////////////////////////////////////////////////
  554. INLINE_LINMATH size_t FLOATNAME(LVecBase4)::
  555. get_hash() const {
  556. TAU_PROFILE("size_t LVecBase4::get_hash()", " ", TAU_USER);
  557. return add_hash(0);
  558. }
  559. ////////////////////////////////////////////////////////////////////
  560. // Function: LVecBase4::get_hash
  561. // Access: Public
  562. // Description: Returns a suitable hash for phash_map.
  563. ////////////////////////////////////////////////////////////////////
  564. INLINE_LINMATH size_t FLOATNAME(LVecBase4)::
  565. get_hash(FLOATTYPE threshold) const {
  566. TAU_PROFILE("size_t LVecBase4::get_hash(FLOATTYPE)", " ", TAU_USER);
  567. return add_hash(0, threshold);
  568. }
  569. ////////////////////////////////////////////////////////////////////
  570. // Function: LVecBase4::add_hash
  571. // Access: Public
  572. // Description: Adds the vector into the running hash.
  573. ////////////////////////////////////////////////////////////////////
  574. INLINE_LINMATH size_t FLOATNAME(LVecBase4)::
  575. add_hash(size_t hash) const {
  576. TAU_PROFILE("size_t LVecBase4::add_hash(size_t)", " ", TAU_USER);
  577. return add_hash(hash, NEARLY_ZERO(FLOATTYPE));
  578. }
  579. ////////////////////////////////////////////////////////////////////
  580. // Function: LVecBase4::add_hash
  581. // Access: Public
  582. // Description: Adds the vector into the running hash.
  583. ////////////////////////////////////////////////////////////////////
  584. INLINE_LINMATH size_t FLOATNAME(LVecBase4)::
  585. add_hash(size_t hash, FLOATTYPE threshold) const {
  586. TAU_PROFILE("LVecBase4::add_hash(size_t, FLOATTYPE)", " ", TAU_USER);
  587. float_hash fhasher(threshold);
  588. hash = fhasher.add_hash(hash, _v.v._0);
  589. hash = fhasher.add_hash(hash, _v.v._1);
  590. hash = fhasher.add_hash(hash, _v.v._2);
  591. hash = fhasher.add_hash(hash, _v.v._3);
  592. return hash;
  593. }
  594. ////////////////////////////////////////////////////////////////////
  595. // Function: LVecBase4::unary -
  596. // Access: Public
  597. // Description:
  598. ////////////////////////////////////////////////////////////////////
  599. INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
  600. operator - () const {
  601. return FLOATNAME(LVecBase4)(-_v.v._0, -_v.v._1, -_v.v._2, -_v.v._3);
  602. }
  603. ////////////////////////////////////////////////////////////////////
  604. // Function: LVecBase4::vector + vector
  605. // Access: Public
  606. // Description:
  607. ////////////////////////////////////////////////////////////////////
  608. INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
  609. operator + (const FLOATNAME(LVecBase4) &other) const {
  610. return FLOATNAME(LVecBase4)(_v.v._0 + other._v.v._0,
  611. _v.v._1 + other._v.v._1,
  612. _v.v._2 + other._v.v._2,
  613. _v.v._3 + other._v.v._3);
  614. }
  615. ////////////////////////////////////////////////////////////////////
  616. // Function: LVecBase4::vector - vector
  617. // Access: Public
  618. // Description:
  619. ////////////////////////////////////////////////////////////////////
  620. INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
  621. operator - (const FLOATNAME(LVecBase4) &other) const {
  622. return FLOATNAME(LVecBase4)(_v.v._0 - other._v.v._0,
  623. _v.v._1 - other._v.v._1,
  624. _v.v._2 - other._v.v._2,
  625. _v.v._3 - other._v.v._3);
  626. }
  627. ////////////////////////////////////////////////////////////////////
  628. // Function: LVecBase4::vector * scalar
  629. // Access: Public
  630. // Description:
  631. ////////////////////////////////////////////////////////////////////
  632. INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
  633. operator * (FLOATTYPE scalar) const {
  634. return FLOATNAME(LVecBase4)(_v.v._0 * scalar,
  635. _v.v._1 * scalar,
  636. _v.v._2 * scalar,
  637. _v.v._3 * scalar);
  638. }
  639. ////////////////////////////////////////////////////////////////////
  640. // Function: LVecBase4::vector / scalar
  641. // Access: Public
  642. // Description:
  643. ////////////////////////////////////////////////////////////////////
  644. INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
  645. operator / (FLOATTYPE scalar) const {
  646. FLOATTYPE recip_scalar = 1.0f/scalar;
  647. return FLOATNAME(LVecBase4)(_v.v._0 * recip_scalar,
  648. _v.v._1 * recip_scalar,
  649. _v.v._2 * recip_scalar,
  650. _v.v._3 * recip_scalar);
  651. }
  652. ////////////////////////////////////////////////////////////////////
  653. // Function: LVecBase4::operator +=
  654. // Access: Public
  655. // Description:
  656. ////////////////////////////////////////////////////////////////////
  657. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  658. operator += (const FLOATNAME(LVecBase4) &other) {
  659. _v.v._0 += other._v.v._0;
  660. _v.v._1 += other._v.v._1;
  661. _v.v._2 += other._v.v._2;
  662. _v.v._3 += other._v.v._3;
  663. }
  664. ////////////////////////////////////////////////////////////////////
  665. // Function: LVecBase4::operator -=
  666. // Access: Public
  667. // Description:
  668. ////////////////////////////////////////////////////////////////////
  669. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  670. operator -= (const FLOATNAME(LVecBase4) &other) {
  671. _v.v._0 -= other._v.v._0;
  672. _v.v._1 -= other._v.v._1;
  673. _v.v._2 -= other._v.v._2;
  674. _v.v._3 -= other._v.v._3;
  675. }
  676. ////////////////////////////////////////////////////////////////////
  677. // Function: LVecBase4::operator *=
  678. // Access: Public
  679. // Description:
  680. ////////////////////////////////////////////////////////////////////
  681. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  682. operator *= (FLOATTYPE scalar) {
  683. _v.v._0 *= scalar;
  684. _v.v._1 *= scalar;
  685. _v.v._2 *= scalar;
  686. _v.v._3 *= scalar;
  687. }
  688. ////////////////////////////////////////////////////////////////////
  689. // Function: LVecBase4::operator /=
  690. // Access: Public
  691. // Description:
  692. ////////////////////////////////////////////////////////////////////
  693. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  694. operator /= (FLOATTYPE scalar) {
  695. FLOATTYPE recip_scalar = 1.0f/scalar;
  696. _v.v._0 *= recip_scalar;
  697. _v.v._1 *= recip_scalar;
  698. _v.v._2 *= recip_scalar;
  699. _v.v._3 *= recip_scalar;
  700. }
  701. ////////////////////////////////////////////////////////////////////
  702. // Function: LVecBase4::fmax
  703. // Access: Public
  704. // Description:
  705. ////////////////////////////////////////////////////////////////////
  706. INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
  707. fmax(const FLOATNAME(LVecBase4) &other) {
  708. TAU_PROFILE("LVecBase4::fmax()", " ", TAU_USER);
  709. return FLOATNAME(LVecBase4)(_v.v._0 > other._v.v._0 ? _v.v._0 : other._v.v._0,
  710. _v.v._1 > other._v.v._1 ? _v.v._1 : other._v.v._1,
  711. _v.v._2 > other._v.v._2 ? _v.v._2 : other._v.v._2,
  712. _v.v._3 > other._v.v._3 ? _v.v._3 : other._v.v._3);
  713. }
  714. ////////////////////////////////////////////////////////////////////
  715. // Function: LVecBase4::fmin
  716. // Access: Public
  717. // Description:
  718. ////////////////////////////////////////////////////////////////////
  719. INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
  720. fmin(const FLOATNAME(LVecBase4) &other) {
  721. TAU_PROFILE("LVecBase4::fmin()", " ", TAU_USER);
  722. return FLOATNAME(LVecBase4)(_v.v._0 < other._v.v._0 ? _v.v._0 : other._v.v._0,
  723. _v.v._1 < other._v.v._1 ? _v.v._1 : other._v.v._1,
  724. _v.v._2 < other._v.v._2 ? _v.v._2 : other._v.v._2,
  725. _v.v._3 < other._v.v._3 ? _v.v._3 : other._v.v._3);
  726. }
  727. ////////////////////////////////////////////////////////////////////
  728. // Function: LVecBase4::almost_equal
  729. // Access: Public
  730. // Description: Returns true if two vectors are memberwise equal
  731. // within a specified tolerance.
  732. ////////////////////////////////////////////////////////////////////
  733. INLINE_LINMATH bool FLOATNAME(LVecBase4)::
  734. almost_equal(const FLOATNAME(LVecBase4) &other, FLOATTYPE threshold) const {
  735. TAU_PROFILE("bool LVecBase4::almost_equal(LVecBase4 &, FLOATTYPE)", " ", TAU_USER);
  736. return (IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold) &&
  737. IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold) &&
  738. IS_THRESHOLD_EQUAL(_v.v._2, other._v.v._2, threshold) &&
  739. IS_THRESHOLD_EQUAL(_v.v._3, other._v.v._3, threshold));
  740. }
  741. ////////////////////////////////////////////////////////////////////
  742. // Function: LVecBase4::almost_equal
  743. // Access: Public
  744. // Description: Returns true if two vectors are memberwise equal
  745. // within a default tolerance based on the numeric type.
  746. ////////////////////////////////////////////////////////////////////
  747. INLINE_LINMATH bool FLOATNAME(LVecBase4)::
  748. almost_equal(const FLOATNAME(LVecBase4) &other) const {
  749. TAU_PROFILE("bool LVecBase4::almost_equal(LVecBase4 &)", " ", TAU_USER);
  750. return almost_equal(other, NEARLY_ZERO(FLOATTYPE));
  751. }
  752. ////////////////////////////////////////////////////////////////////
  753. // Function: LVecBase4::output
  754. // Access: Public
  755. // Description:
  756. ////////////////////////////////////////////////////////////////////
  757. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  758. output(ostream &out) const {
  759. out << MAYBE_ZERO(_v.v._0) << " "
  760. << MAYBE_ZERO(_v.v._1) << " "
  761. << MAYBE_ZERO(_v.v._2) << " "
  762. << MAYBE_ZERO(_v.v._3);
  763. }
  764. #ifdef HAVE_PYTHON
  765. ////////////////////////////////////////////////////////////////////
  766. // Function: LVecBase4::python_repr
  767. // Access: Published
  768. // Description:
  769. ////////////////////////////////////////////////////////////////////
  770. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  771. python_repr(ostream &out, const string &class_name) const {
  772. out << class_name << "("
  773. << MAYBE_ZERO(_v.v._0) << ", "
  774. << MAYBE_ZERO(_v.v._1) << ", "
  775. << MAYBE_ZERO(_v.v._2) << ", "
  776. << MAYBE_ZERO(_v.v._3) << ")";
  777. }
  778. #endif // HAVE_PYTHON
  779. ////////////////////////////////////////////////////////////////////
  780. // Function: LVecBase4::generate_hash
  781. // Access: Public
  782. // Description: Adds the vector to the indicated hash generator.
  783. ////////////////////////////////////////////////////////////////////
  784. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  785. generate_hash(ChecksumHashGenerator &hashgen) const {
  786. TAU_PROFILE("LVecBase4::generate_hash(ChecksumHashGenerator &)", " ", TAU_USER);
  787. generate_hash(hashgen, NEARLY_ZERO(FLOATTYPE));
  788. }
  789. ////////////////////////////////////////////////////////////////////
  790. // Function: LVecBase4::generate_hash
  791. // Access: Public
  792. // Description: Adds the vector to the indicated hash generator.
  793. ////////////////////////////////////////////////////////////////////
  794. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  795. generate_hash(ChecksumHashGenerator &hashgen, FLOATTYPE threshold) const {
  796. TAU_PROFILE("LVecBase4::generate_hash(ChecksumHashGenerator &, FLOATTYPE)", " ", TAU_USER);
  797. hashgen.add_fp(_v.v._0, threshold);
  798. hashgen.add_fp(_v.v._1, threshold);
  799. hashgen.add_fp(_v.v._2, threshold);
  800. hashgen.add_fp(_v.v._3, threshold);
  801. }
  802. ////////////////////////////////////////////////////////////////////
  803. // Function: LVecBase4::write_datagram
  804. // Access: Public
  805. // Description: Function to write itself into a datagram
  806. ////////////////////////////////////////////////////////////////////
  807. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  808. write_datagram(Datagram &destination) const {
  809. #if FLOATTOKEN == 'f'
  810. destination.add_float32(_v.v._0);
  811. destination.add_float32(_v.v._1);
  812. destination.add_float32(_v.v._2);
  813. destination.add_float32(_v.v._3);
  814. #else
  815. destination.add_float64(_v.v._0);
  816. destination.add_float64(_v.v._1);
  817. destination.add_float64(_v.v._2);
  818. destination.add_float64(_v.v._3);
  819. #endif
  820. }
  821. ////////////////////////////////////////////////////////////////////
  822. // Function: LVecBase4::read_datagram
  823. // Access: Public
  824. // Description: Function to read itself from a datagramIterator
  825. ////////////////////////////////////////////////////////////////////
  826. INLINE_LINMATH void FLOATNAME(LVecBase4)::
  827. read_datagram(DatagramIterator &source) {
  828. #if FLOATTOKEN == 'f'
  829. _v.v._0 = source.get_float32();
  830. _v.v._1 = source.get_float32();
  831. _v.v._2 = source.get_float32();
  832. _v.v._3 = source.get_float32();
  833. #else
  834. _v.v._0 = source.get_float64();
  835. _v.v._1 = source.get_float64();
  836. _v.v._2 = source.get_float64();
  837. _v.v._3 = source.get_float64();
  838. #endif
  839. }