lvecBase3_src.I 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. // Filename: lvecBase3_src.I
  2. // Created by: drose (08Mar00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: LVecBase3::Default Constructor
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE_LINMATH FLOATNAME(LVecBase3)::
  24. FLOATNAME(LVecBase3)() {
  25. }
  26. ////////////////////////////////////////////////////////////////////
  27. // Function: LVecBase3::Copy Constructor
  28. // Access: Public
  29. // Description:
  30. ////////////////////////////////////////////////////////////////////
  31. INLINE_LINMATH FLOATNAME(LVecBase3)::
  32. FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) &copy) {
  33. _v.v._0 = copy._v.v._0;
  34. _v.v._1 = copy._v.v._1;
  35. _v.v._2 = copy._v.v._2;
  36. // (*this) = copy;
  37. }
  38. ////////////////////////////////////////////////////////////////////
  39. // Function: LVecBase3::Copy Assignment Operator
  40. // Access: Public
  41. // Description:
  42. ////////////////////////////////////////////////////////////////////
  43. INLINE_LINMATH FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3)::
  44. operator = (const FLOATNAME(LVecBase3) &copy) {
  45. _v.v._0 = copy._v.v._0;
  46. _v.v._1 = copy._v.v._1;
  47. _v.v._2 = copy._v.v._2;
  48. // set(copy[0], copy[1], copy[2]);
  49. return *this;
  50. }
  51. ////////////////////////////////////////////////////////////////////
  52. // Function: LVecBase3::Fill Assignment Operator
  53. // Access: Public
  54. // Description:
  55. ////////////////////////////////////////////////////////////////////
  56. INLINE_LINMATH FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3)::
  57. operator = (FLOATTYPE fill_value) {
  58. fill(fill_value);
  59. return *this;
  60. }
  61. ////////////////////////////////////////////////////////////////////
  62. // Function: LVecBase3::Constructor
  63. // Access: Public
  64. // Description:
  65. ////////////////////////////////////////////////////////////////////
  66. INLINE_LINMATH FLOATNAME(LVecBase3)::
  67. FLOATNAME(LVecBase3)(FLOATTYPE fill_value) {
  68. fill(fill_value);
  69. }
  70. ////////////////////////////////////////////////////////////////////
  71. // Function: LVecBase3::Constructor
  72. // Access: Public
  73. // Description:
  74. ////////////////////////////////////////////////////////////////////
  75. INLINE_LINMATH FLOATNAME(LVecBase3)::
  76. FLOATNAME(LVecBase3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) {
  77. _v.v._0 = x;
  78. _v.v._1 = y;
  79. _v.v._2 = z;
  80. // set(x, y, z);
  81. }
  82. ////////////////////////////////////////////////////////////////////
  83. // Function: LVecBase3::zero Named Constructor
  84. // Access: Public
  85. // Description: Returns a zero-length vector.
  86. ////////////////////////////////////////////////////////////////////
  87. INLINE_LINMATH const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3)::
  88. zero() {
  89. return _zero;
  90. }
  91. ////////////////////////////////////////////////////////////////////
  92. // Function: LVecBase3::unit_x Named Constructor
  93. // Access: Public
  94. // Description: Returns a unit X vector.
  95. ////////////////////////////////////////////////////////////////////
  96. INLINE_LINMATH const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3)::
  97. unit_x() {
  98. return _unit_x;
  99. }
  100. ////////////////////////////////////////////////////////////////////
  101. // Function: LVecBase3::unit_y Named Constructor
  102. // Access: Public
  103. // Description: Returns a unit Y vector.
  104. ////////////////////////////////////////////////////////////////////
  105. INLINE_LINMATH const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3)::
  106. unit_y() {
  107. return _unit_y;
  108. }
  109. ////////////////////////////////////////////////////////////////////
  110. // Function: LVecBase3::unit_z Named Constructor
  111. // Access: Public
  112. // Description: Returns a unit Z vector.
  113. ////////////////////////////////////////////////////////////////////
  114. INLINE_LINMATH const FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3)::
  115. unit_z() {
  116. return _unit_z;
  117. }
  118. ////////////////////////////////////////////////////////////////////
  119. // Function: LVecBase3::Destructor
  120. // Access: Public
  121. // Description:
  122. ////////////////////////////////////////////////////////////////////
  123. INLINE_LINMATH FLOATNAME(LVecBase3)::
  124. ~FLOATNAME(LVecBase3)() {
  125. }
  126. ////////////////////////////////////////////////////////////////////
  127. // Function: LVecBase3::Indexing Operator
  128. // Access: Public
  129. // Description:
  130. ////////////////////////////////////////////////////////////////////
  131. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3)::
  132. operator [](int i) const {
  133. //nassertr(i >= 0 && i < 3, 0);
  134. return _v.data[i];
  135. }
  136. ////////////////////////////////////////////////////////////////////
  137. // Function: LVecBase3::Indexing Operator
  138. // Access: Public
  139. // Description:
  140. ////////////////////////////////////////////////////////////////////
  141. INLINE_LINMATH FLOATTYPE &FLOATNAME(LVecBase3)::
  142. operator [](int i) {
  143. //nassertr(i >= 0 && i < 3, _v.v._0);
  144. return _v.data[i];
  145. }
  146. ////////////////////////////////////////////////////////////////////
  147. // Function: LVecBase3::is_nan
  148. // Access: Public
  149. // Description: Returns true if any component of the vector is
  150. // not-a-number, false otherwise.
  151. ////////////////////////////////////////////////////////////////////
  152. INLINE_LINMATH bool FLOATNAME(LVecBase3)::
  153. is_nan() const {
  154. return cnan(_v.v._0) || cnan(_v.v._1) || cnan(_v.v._2);
  155. }
  156. ////////////////////////////////////////////////////////////////////
  157. // Function: LVecBase3::get_cell
  158. // Access: Public
  159. // Description:
  160. ////////////////////////////////////////////////////////////////////
  161. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3)::
  162. get_cell(int i) const {
  163. // nassertr(i >= 0 && i < 3, 0);
  164. return _v.data[i];
  165. }
  166. ////////////////////////////////////////////////////////////////////
  167. // Function: LVecBase3::get_x
  168. // Access: Public
  169. // Description:
  170. ////////////////////////////////////////////////////////////////////
  171. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3)::
  172. get_x() const {
  173. return _v.v._0;
  174. }
  175. ////////////////////////////////////////////////////////////////////
  176. // Function: LVecBase3::get_y
  177. // Access: Public
  178. // Description:
  179. ////////////////////////////////////////////////////////////////////
  180. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3)::
  181. get_y() const {
  182. return _v.v._1;
  183. }
  184. ////////////////////////////////////////////////////////////////////
  185. // Function: LVecBase3::get_z
  186. // Access: Public
  187. // Description:
  188. ////////////////////////////////////////////////////////////////////
  189. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3)::
  190. get_z() const {
  191. return _v.v._2;
  192. }
  193. ////////////////////////////////////////////////////////////////////
  194. // Function: LVecBase3::set_cell
  195. // Access: Public
  196. // Description:
  197. ////////////////////////////////////////////////////////////////////
  198. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  199. set_cell(int i, FLOATTYPE value) {
  200. // nassertv(i >= 0 && i < 3);
  201. _v.data[i] = value;
  202. }
  203. ////////////////////////////////////////////////////////////////////
  204. // Function: LVecBase3::set_x
  205. // Access: Public
  206. // Description:
  207. ////////////////////////////////////////////////////////////////////
  208. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  209. set_x(FLOATTYPE value) {
  210. _v.v._0 = value;
  211. }
  212. ////////////////////////////////////////////////////////////////////
  213. // Function: LVecBase3::set_y
  214. // Access: Public
  215. // Description:
  216. ////////////////////////////////////////////////////////////////////
  217. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  218. set_y(FLOATTYPE value) {
  219. _v.v._1 = value;
  220. }
  221. ////////////////////////////////////////////////////////////////////
  222. // Function: LVecBase3::set_z
  223. // Access: Public
  224. // Description:
  225. ////////////////////////////////////////////////////////////////////
  226. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  227. set_z(FLOATTYPE value) {
  228. _v.v._2 = value;
  229. }
  230. ////////////////////////////////////////////////////////////////////
  231. // Function: LVecBase3::get_data
  232. // Access: Public
  233. // Description: Returns the address of the first of the three data
  234. // elements in the vector. The remaining elements
  235. // occupy the next positions consecutively in memory.
  236. ////////////////////////////////////////////////////////////////////
  237. INLINE_LINMATH const FLOATTYPE *FLOATNAME(LVecBase3)::
  238. get_data() const {
  239. return _v.data;
  240. }
  241. ////////////////////////////////////////////////////////////////////
  242. // Function: LVecBase3::get_num_components
  243. // Access: Public
  244. // Description: Returns the number of elements in the vector, three.
  245. ////////////////////////////////////////////////////////////////////
  246. INLINE_LINMATH int FLOATNAME(LVecBase3)::
  247. get_num_components() const {
  248. return 3;
  249. }
  250. ////////////////////////////////////////////////////////////////////
  251. // Function: LVecBase3::begin
  252. // Access: Public
  253. // Description: Returns an iterator that may be used to traverse the
  254. // elements of the matrix, STL-style.
  255. ////////////////////////////////////////////////////////////////////
  256. INLINE_LINMATH FLOATNAME(LVecBase3)::iterator FLOATNAME(LVecBase3)::
  257. begin() {
  258. return _v.data;
  259. }
  260. ////////////////////////////////////////////////////////////////////
  261. // Function: LVecBase3::end
  262. // Access: Public
  263. // Description: Returns an iterator that may be used to traverse the
  264. // elements of the matrix, STL-style.
  265. ////////////////////////////////////////////////////////////////////
  266. INLINE_LINMATH FLOATNAME(LVecBase3)::iterator FLOATNAME(LVecBase3)::
  267. end() {
  268. return begin() + get_num_components();
  269. }
  270. ////////////////////////////////////////////////////////////////////
  271. // Function: LVecBase3::begin
  272. // Access: Public
  273. // Description: Returns an iterator that may be used to traverse the
  274. // elements of the matrix, STL-style.
  275. ////////////////////////////////////////////////////////////////////
  276. INLINE_LINMATH FLOATNAME(LVecBase3)::const_iterator FLOATNAME(LVecBase3)::
  277. begin() const {
  278. return _v.data;
  279. }
  280. ////////////////////////////////////////////////////////////////////
  281. // Function: LVecBase3::end
  282. // Access: Public
  283. // Description: Returns an iterator that may be used to traverse the
  284. // elements of the matrix, STL-style.
  285. ////////////////////////////////////////////////////////////////////
  286. INLINE_LINMATH FLOATNAME(LVecBase3)::const_iterator FLOATNAME(LVecBase3)::
  287. end() const {
  288. return begin() + get_num_components();
  289. }
  290. ////////////////////////////////////////////////////////////////////
  291. // Function: LVecBase3::fill
  292. // Access: Public
  293. // Description: Sets each element of the vector to the indicated
  294. // fill_value. This is particularly useful for
  295. // initializing to zero.
  296. ////////////////////////////////////////////////////////////////////
  297. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  298. fill(FLOATTYPE fill_value) {
  299. _v.v._0 = fill_value;
  300. _v.v._1 = fill_value;
  301. _v.v._2 = fill_value;
  302. }
  303. ////////////////////////////////////////////////////////////////////
  304. // Function: LVecBase3::set
  305. // Access: Public
  306. // Description:
  307. ////////////////////////////////////////////////////////////////////
  308. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  309. set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) {
  310. _v.v._0 = x;
  311. _v.v._1 = y;
  312. _v.v._2 = z;
  313. }
  314. ////////////////////////////////////////////////////////////////////
  315. // Function: LVecBase3::dot
  316. // Access: Public
  317. // Description:
  318. ////////////////////////////////////////////////////////////////////
  319. INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3)::
  320. dot(const FLOATNAME(LVecBase3) &other) const {
  321. return _v.v._0 * other._v.v._0 + _v.v._1 * other._v.v._1 + _v.v._2 * other._v.v._2;
  322. }
  323. ////////////////////////////////////////////////////////////////////
  324. // Function: LVecBase3::cross
  325. // Access: Public
  326. // Description:
  327. ////////////////////////////////////////////////////////////////////
  328. INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
  329. cross(const FLOATNAME(LVecBase3) &other) const {
  330. return FLOATNAME(LVecBase3)(_v.v._1 * other._v.v._2 - other._v.v._1 * _v.v._2,
  331. other._v.v._0 * _v.v._2 - _v.v._0 * other._v.v._2,
  332. _v.v._0 * other._v.v._1 - other._v.v._0 * _v.v._1);
  333. }
  334. ////////////////////////////////////////////////////////////////////
  335. // Function: LVecBase3::operator <
  336. // Access: Public
  337. // Description: This performs a lexicographical comparison. It's of
  338. // questionable mathematical meaning, but sometimes has
  339. // a practical purpose for sorting unique vectors,
  340. // especially in an STL container. Also see
  341. // compare_to().
  342. ////////////////////////////////////////////////////////////////////
  343. INLINE_LINMATH bool FLOATNAME(LVecBase3)::
  344. operator < (const FLOATNAME(LVecBase3) &other) const {
  345. return (compare_to(other) < 0);
  346. }
  347. ////////////////////////////////////////////////////////////////////
  348. // Function: LVecBase3::operator ==
  349. // Access: Public
  350. // Description:
  351. ////////////////////////////////////////////////////////////////////
  352. INLINE_LINMATH bool FLOATNAME(LVecBase3)::
  353. operator == (const FLOATNAME(LVecBase3) &other) const {
  354. return (_v.v._0 == other._v.v._0 &&
  355. _v.v._1 == other._v.v._1 &&
  356. _v.v._2 == other._v.v._2);
  357. }
  358. ////////////////////////////////////////////////////////////////////
  359. // Function: LVecBase3::operator !=
  360. // Access: Public
  361. // Description:
  362. ////////////////////////////////////////////////////////////////////
  363. INLINE_LINMATH bool FLOATNAME(LVecBase3)::
  364. operator != (const FLOATNAME(LVecBase3) &other) const {
  365. return !operator == (other);
  366. }
  367. ////////////////////////////////////////////////////////////////////
  368. // Function: LVecBase3::compare_to
  369. // Access: Public
  370. // Description: This flavor of compare_to uses a default threshold
  371. // value based on the numeric type.
  372. ////////////////////////////////////////////////////////////////////
  373. INLINE_LINMATH int FLOATNAME(LVecBase3)::
  374. compare_to(const FLOATNAME(LVecBase3) &other) const {
  375. return compare_to(other, NEARLY_ZERO(FLOATTYPE));
  376. }
  377. ////////////////////////////////////////////////////////////////////
  378. // Function: LVecBase3::compare_to
  379. // Access: Public
  380. // Description: Sorts vectors lexicographically, componentwise.
  381. // Returns a number less than 0 if this vector sorts
  382. // before the other one, greater than zero if it sorts
  383. // after, 0 if they are equivalent (within the indicated
  384. // tolerance).
  385. ////////////////////////////////////////////////////////////////////
  386. INLINE_LINMATH int FLOATNAME(LVecBase3)::
  387. compare_to(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const {
  388. if (!IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold)) {
  389. return (_v.v._0 < other._v.v._0) ? -1 : 1;
  390. }
  391. if (!IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold)) {
  392. return (_v.v._1 < other._v.v._1) ? -1 : 1;
  393. }
  394. if (!IS_THRESHOLD_EQUAL(_v.v._2, other._v.v._2, threshold)) {
  395. return (_v.v._2 < other._v.v._2) ? -1 : 1;
  396. }
  397. return 0;
  398. }
  399. ////////////////////////////////////////////////////////////////////
  400. // Function: LVecBase3::unary -
  401. // Access: Public
  402. // Description:
  403. ////////////////////////////////////////////////////////////////////
  404. INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
  405. operator - () const {
  406. return FLOATNAME(LVecBase3)(-_v.v._0, -_v.v._1, -_v.v._2);
  407. }
  408. ////////////////////////////////////////////////////////////////////
  409. // Function: LVecBase3::vector + vector
  410. // Access: Public
  411. // Description:
  412. ////////////////////////////////////////////////////////////////////
  413. INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
  414. operator + (const FLOATNAME(LVecBase3) &other) const {
  415. return FLOATNAME(LVecBase3)(_v.v._0 + other._v.v._0,
  416. _v.v._1 + other._v.v._1,
  417. _v.v._2 + other._v.v._2);
  418. }
  419. ////////////////////////////////////////////////////////////////////
  420. // Function: LVecBase3::vector - vector
  421. // Access: Public
  422. // Description:
  423. ////////////////////////////////////////////////////////////////////
  424. INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
  425. operator - (const FLOATNAME(LVecBase3) &other) const {
  426. return FLOATNAME(LVecBase3)(_v.v._0 - other._v.v._0,
  427. _v.v._1 - other._v.v._1,
  428. _v.v._2 - other._v.v._2);
  429. }
  430. ////////////////////////////////////////////////////////////////////
  431. // Function: LVecBase3::vector * scalar
  432. // Access: Public
  433. // Description:
  434. ////////////////////////////////////////////////////////////////////
  435. INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
  436. operator * (FLOATTYPE scalar) const {
  437. return FLOATNAME(LVecBase3)(_v.v._0 * scalar,
  438. _v.v._1 * scalar,
  439. _v.v._2 * scalar);
  440. }
  441. ////////////////////////////////////////////////////////////////////
  442. // Function: LVecBase3::vector / scalar
  443. // Access: Public
  444. // Description:
  445. ////////////////////////////////////////////////////////////////////
  446. INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
  447. operator / (FLOATTYPE scalar) const {
  448. FLOATTYPE recip_scalar = 1.0f/scalar;
  449. return FLOATNAME(LVecBase3)(_v.v._0 * recip_scalar,
  450. _v.v._1 * recip_scalar,
  451. _v.v._2 * recip_scalar);
  452. }
  453. ////////////////////////////////////////////////////////////////////
  454. // Function: LVecBase3::operator +=
  455. // Access: Public
  456. // Description:
  457. ////////////////////////////////////////////////////////////////////
  458. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  459. operator += (const FLOATNAME(LVecBase3) &other) {
  460. _v.v._0 += other._v.v._0;
  461. _v.v._1 += other._v.v._1;
  462. _v.v._2 += other._v.v._2;
  463. }
  464. ////////////////////////////////////////////////////////////////////
  465. // Function: LVecBase3::operator -=
  466. // Access: Public
  467. // Description:
  468. ////////////////////////////////////////////////////////////////////
  469. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  470. operator -= (const FLOATNAME(LVecBase3) &other) {
  471. _v.v._0 -= other._v.v._0;
  472. _v.v._1 -= other._v.v._1;
  473. _v.v._2 -= other._v.v._2;
  474. }
  475. ////////////////////////////////////////////////////////////////////
  476. // Function: LVecBase3::operator *=
  477. // Access: Public
  478. // Description:
  479. ////////////////////////////////////////////////////////////////////
  480. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  481. operator *= (FLOATTYPE scalar) {
  482. _v.v._0 *= scalar;
  483. _v.v._1 *= scalar;
  484. _v.v._2 *= scalar;
  485. }
  486. ////////////////////////////////////////////////////////////////////
  487. // Function: LVecBase3::operator /=
  488. // Access: Public
  489. // Description:
  490. ////////////////////////////////////////////////////////////////////
  491. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  492. operator /= (FLOATTYPE scalar) {
  493. FLOATTYPE recip_scalar = 1.0f/scalar;
  494. _v.v._0 *= recip_scalar;
  495. _v.v._1 *= recip_scalar;
  496. _v.v._2 *= recip_scalar;
  497. }
  498. ////////////////////////////////////////////////////////////////////
  499. // Function: LVecBase3::cross product (with assigment)
  500. // Access: Public
  501. // Description:
  502. ////////////////////////////////////////////////////////////////////
  503. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  504. cross_into(const FLOATNAME(LVecBase3) &other) {
  505. (*this) = cross(other);
  506. }
  507. ////////////////////////////////////////////////////////////////////
  508. // Function: LVecBase3::almost_equal
  509. // Access: Public
  510. // Description: Returns true if two vectors are memberwise equal
  511. // within a specified tolerance.
  512. ////////////////////////////////////////////////////////////////////
  513. INLINE_LINMATH bool FLOATNAME(LVecBase3)::
  514. almost_equal(const FLOATNAME(LVecBase3) &other, FLOATTYPE threshold) const {
  515. return (IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold) &&
  516. IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold) &&
  517. IS_THRESHOLD_EQUAL(_v.v._2, other._v.v._2, threshold));
  518. }
  519. ////////////////////////////////////////////////////////////////////
  520. // Function: LVecBase3::almost_equal
  521. // Access: Public
  522. // Description: Returns true if two vectors are memberwise equal
  523. // within a default tolerance based on the numeric type.
  524. ////////////////////////////////////////////////////////////////////
  525. INLINE_LINMATH bool FLOATNAME(LVecBase3)::
  526. almost_equal(const FLOATNAME(LVecBase3) &other) const {
  527. return almost_equal(other, NEARLY_ZERO(FLOATTYPE));
  528. }
  529. ////////////////////////////////////////////////////////////////////
  530. // Function: LVecBase3::output
  531. // Access: Public
  532. // Description:
  533. ////////////////////////////////////////////////////////////////////
  534. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  535. output(ostream &out) const {
  536. out << MAYBE_ZERO(_v.v._0) << " "
  537. << MAYBE_ZERO(_v.v._1) << " "
  538. << MAYBE_ZERO(_v.v._2);
  539. }
  540. ////////////////////////////////////////////////////////////////////
  541. // Function: LVecBase3::generate_hash
  542. // Access: Public
  543. // Description: Adds the vector to the indicated hash generator.
  544. ////////////////////////////////////////////////////////////////////
  545. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  546. generate_hash(ChecksumHashGenerator &hash) const {
  547. generate_hash(hash, NEARLY_ZERO(FLOATTYPE));
  548. }
  549. ////////////////////////////////////////////////////////////////////
  550. // Function: LVecBase3::generate_hash
  551. // Access: Public
  552. // Description: Adds the vector to the indicated hash generator.
  553. ////////////////////////////////////////////////////////////////////
  554. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  555. generate_hash(ChecksumHashGenerator &hash, FLOATTYPE threshold) const {
  556. hash.add_fp(_v.v._0, threshold);
  557. hash.add_fp(_v.v._1, threshold);
  558. hash.add_fp(_v.v._2, threshold);
  559. }
  560. ////////////////////////////////////////////////////////////////////
  561. // Function: LVecBase3::write_datagram
  562. // Access: Public
  563. // Description: Function to write itself into a datagram
  564. ////////////////////////////////////////////////////////////////////
  565. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  566. write_datagram(Datagram &destination) const {
  567. destination.add_float32(_v.v._0);
  568. destination.add_float32(_v.v._1);
  569. destination.add_float32(_v.v._2);
  570. }
  571. ////////////////////////////////////////////////////////////////////
  572. // Function: LVecBase3::read_datagram
  573. // Access: Public
  574. // Description: Function to read itself from a datagramIterator
  575. ////////////////////////////////////////////////////////////////////
  576. INLINE_LINMATH void FLOATNAME(LVecBase3)::
  577. read_datagram(DatagramIterator &source) {
  578. _v.v._0 = source.get_float32();
  579. _v.v._1 = source.get_float32();
  580. _v.v._2 = source.get_float32();
  581. }