Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/linmath/lvecBase2_src.I

Go to the documentation of this file.
00001 // Filename: lvecBase2_src.I
00002 // Created by:  drose (08Mar00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: LVecBase2::Default Constructor
00022 //       Access: Public
00023 //  Description:
00024 ////////////////////////////////////////////////////////////////////
00025 INLINE_LINMATH FLOATNAME(LVecBase2)::
00026 FLOATNAME(LVecBase2)() {
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: LVecBase2::Copy Constructor
00031 //       Access: Public
00032 //  Description:
00033 ////////////////////////////////////////////////////////////////////
00034 INLINE_LINMATH FLOATNAME(LVecBase2)::
00035 FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) &copy) {
00036   _v.v._0 = copy._v.v._0;
00037   _v.v._1 = copy._v.v._1;
00038 //  (*this) = copy;
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: LVecBase2::Copy Assignment Operator
00043 //       Access: Public
00044 //  Description:
00045 ////////////////////////////////////////////////////////////////////
00046 INLINE_LINMATH FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2)::
00047 operator = (const FLOATNAME(LVecBase2) &copy) {
00048   _v.v._0 = copy._v.v._0;
00049   _v.v._1 = copy._v.v._1;
00050 //  set(copy[0], copy[1]);
00051   return *this;
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: LVecBase2::Fill Assignment Operator
00056 //       Access: Public
00057 //  Description:
00058 ////////////////////////////////////////////////////////////////////
00059 INLINE_LINMATH FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2)::
00060 operator = (FLOATTYPE fill_value) {
00061   fill(fill_value);
00062   return *this;
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: LVecBase2::Constructor
00067 //       Access: Public
00068 //  Description:
00069 ////////////////////////////////////////////////////////////////////
00070 INLINE_LINMATH FLOATNAME(LVecBase2)::
00071 FLOATNAME(LVecBase2)(FLOATTYPE fill_value) {
00072   fill(fill_value);
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: LVecBase2::Constructor
00077 //       Access: Public
00078 //  Description:
00079 ////////////////////////////////////////////////////////////////////
00080 INLINE_LINMATH FLOATNAME(LVecBase2)::
00081 FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y) {
00082   _v.v._0 = x;
00083   _v.v._1 = y;
00084 //  set(x, y);
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: LVecBase2::zero Named Constructor
00089 //       Access: Public
00090 //  Description: Returns a zero-length vector.
00091 ////////////////////////////////////////////////////////////////////
00092 INLINE_LINMATH const FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2)::
00093 zero() {
00094   return _zero;
00095 }
00096 
00097 ////////////////////////////////////////////////////////////////////
00098 //     Function: LVecBase2::unit_x Named Constructor
00099 //       Access: Public
00100 //  Description: Returns a unit X vector.
00101 ////////////////////////////////////////////////////////////////////
00102 INLINE_LINMATH const FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2)::
00103 unit_x() {
00104   return _unit_x;
00105 }
00106 
00107 ////////////////////////////////////////////////////////////////////
00108 //     Function: LVecBase2::unit_y Named Constructor
00109 //       Access: Public
00110 //  Description: Returns a unit Y vector.
00111 ////////////////////////////////////////////////////////////////////
00112 INLINE_LINMATH const FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2)::
00113 unit_y() {
00114   return _unit_y;
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: LVecBase2::Destructor
00119 //       Access: Public
00120 //  Description:
00121 ////////////////////////////////////////////////////////////////////
00122 INLINE_LINMATH FLOATNAME(LVecBase2)::
00123 ~FLOATNAME(LVecBase2)() {
00124 }
00125 
00126 ////////////////////////////////////////////////////////////////////
00127 //     Function: LVecBase2::Indexing Operator
00128 //       Access: Public
00129 //  Description:
00130 ////////////////////////////////////////////////////////////////////
00131 INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2)::
00132 operator [](int i) const {
00133   nassertr(i >= 0 && i < 2, 0.0);
00134   return _v.data[i];
00135 }
00136 
00137 ////////////////////////////////////////////////////////////////////
00138 //     Function: LVecBase2::Indexing Operator
00139 //       Access: Public
00140 //  Description:
00141 ////////////////////////////////////////////////////////////////////
00142 INLINE_LINMATH FLOATTYPE &FLOATNAME(LVecBase2)::
00143 operator [](int i) {
00144   nassertr(i >= 0 && i < 2, _v.data[0]);
00145   return _v.data[i];
00146 }
00147 
00148 ////////////////////////////////////////////////////////////////////
00149 //     Function: LVecBase2::is_nan
00150 //       Access: Public
00151 //  Description: Returns true if any component of the vector is
00152 //               not-a-number, false otherwise.
00153 ////////////////////////////////////////////////////////////////////
00154 INLINE_LINMATH bool FLOATNAME(LVecBase2)::
00155 is_nan() const {
00156   return cnan(_v.v._0) || cnan(_v.v._1);
00157 }
00158 
00159 ////////////////////////////////////////////////////////////////////
00160 //     Function: LVecBase2::get_cell
00161 //       Access: Public
00162 //  Description:
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2)::
00165 get_cell(int i) const {
00166   nassertr(i >= 0 && i < 2, 0.0);
00167   return _v.data[i];
00168 }
00169 
00170 ////////////////////////////////////////////////////////////////////
00171 //     Function: LVecBase2::get_x
00172 //       Access: Public
00173 //  Description:
00174 ////////////////////////////////////////////////////////////////////
00175 INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2)::
00176 get_x() const {
00177   return _v.v._0;
00178 }
00179 
00180 ////////////////////////////////////////////////////////////////////
00181 //     Function: LVecBase2::get_y
00182 //       Access: Public
00183 //  Description:
00184 ////////////////////////////////////////////////////////////////////
00185 INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2)::
00186 get_y() const {
00187   return _v.v._1;
00188 }
00189 
00190 ////////////////////////////////////////////////////////////////////
00191 //     Function: LVecBase2::set_cell
00192 //       Access: Public
00193 //  Description:
00194 ////////////////////////////////////////////////////////////////////
00195 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00196 set_cell(int i, FLOATTYPE value) {
00197   nassertv(i >= 0 && i < 2);
00198   _v.data[i] = value;
00199 }
00200 
00201 ////////////////////////////////////////////////////////////////////
00202 //     Function: LVecBase2::set_x
00203 //       Access: Public
00204 //  Description:
00205 ////////////////////////////////////////////////////////////////////
00206 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00207 set_x(FLOATTYPE value) {
00208   _v.v._0 = value;
00209 }
00210 
00211 ////////////////////////////////////////////////////////////////////
00212 //     Function: LVecBase2::set_y
00213 //       Access: Public
00214 //  Description:
00215 ////////////////////////////////////////////////////////////////////
00216 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00217 set_y(FLOATTYPE value) {
00218   _v.v._1 = value;
00219 }
00220 
00221 ////////////////////////////////////////////////////////////////////
00222 //     Function: LVecBase2::get_data
00223 //       Access: Public
00224 //  Description: Returns the address of the first of the two data
00225 //               elements in the vector.  The next element
00226 //               occupies the next position consecutively in memory.
00227 ////////////////////////////////////////////////////////////////////
00228 INLINE_LINMATH const FLOATTYPE *FLOATNAME(LVecBase2)::
00229 get_data() const {
00230   return _v.data;
00231 }
00232 
00233 ////////////////////////////////////////////////////////////////////
00234 //     Function: LVecBase2::get_num_components
00235 //       Access: Public
00236 //  Description: Returns the number of elements in the vector, two.
00237 ////////////////////////////////////////////////////////////////////
00238 INLINE_LINMATH int FLOATNAME(LVecBase2)::
00239 get_num_components() const {
00240   return 2;
00241 }
00242 
00243 ////////////////////////////////////////////////////////////////////
00244 //     Function: LVecBase2::begin
00245 //       Access: Public
00246 //  Description: Returns an iterator that may be used to traverse the
00247 //               elements of the matrix, STL-style.
00248 ////////////////////////////////////////////////////////////////////
00249 INLINE_LINMATH FLOATNAME(LVecBase2)::iterator FLOATNAME(LVecBase2)::
00250 begin() {
00251   return _v.data;
00252 }
00253 
00254 ////////////////////////////////////////////////////////////////////
00255 //     Function: LVecBase2::end
00256 //       Access: Public
00257 //  Description: Returns an iterator that may be used to traverse the
00258 //               elements of the matrix, STL-style.
00259 ////////////////////////////////////////////////////////////////////
00260 INLINE_LINMATH FLOATNAME(LVecBase2)::iterator FLOATNAME(LVecBase2)::
00261 end() {
00262   return begin() + get_num_components();
00263 }
00264 
00265 ////////////////////////////////////////////////////////////////////
00266 //     Function: LVecBase2::begin
00267 //       Access: Public
00268 //  Description: Returns an iterator that may be used to traverse the
00269 //               elements of the matrix, STL-style.
00270 ////////////////////////////////////////////////////////////////////
00271 INLINE_LINMATH FLOATNAME(LVecBase2)::const_iterator FLOATNAME(LVecBase2)::
00272 begin() const {
00273   return _v.data;
00274 }
00275 
00276 ////////////////////////////////////////////////////////////////////
00277 //     Function: LVecBase2::end
00278 //       Access: Public
00279 //  Description: Returns an iterator that may be used to traverse the
00280 //               elements of the matrix, STL-style.
00281 ////////////////////////////////////////////////////////////////////
00282 INLINE_LINMATH FLOATNAME(LVecBase2)::const_iterator FLOATNAME(LVecBase2)::
00283 end() const {
00284   return begin() + get_num_components();
00285 }
00286 
00287 ////////////////////////////////////////////////////////////////////
00288 //     Function: LVecBase2::fill
00289 //       Access: Public
00290 //  Description: Sets each element of the vector to the indicated
00291 //               fill_value.  This is particularly useful for
00292 //               initializing to zero.
00293 ////////////////////////////////////////////////////////////////////
00294 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00295 fill(FLOATTYPE fill_value) {
00296   _v.v._0 = fill_value;
00297   _v.v._1 = fill_value;
00298 }
00299 
00300 ////////////////////////////////////////////////////////////////////
00301 //     Function: LVecBase2::set
00302 //       Access: Public
00303 //  Description:
00304 ////////////////////////////////////////////////////////////////////
00305 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00306 set(FLOATTYPE x, FLOATTYPE y) {
00307   _v.v._0 = x;
00308   _v.v._1 = y;
00309 }
00310 
00311 ////////////////////////////////////////////////////////////////////
00312 //     Function: LVecBase2::dot
00313 //       Access: Public
00314 //  Description:
00315 ////////////////////////////////////////////////////////////////////
00316 INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2)::
00317 dot(const FLOATNAME(LVecBase2) &other) const {
00318   return _v.v._0 * other._v.v._0 + _v.v._1 * other._v.v._1;
00319 }
00320 
00321 ////////////////////////////////////////////////////////////////////
00322 //     Function: LVecBase2::operator <
00323 //       Access: Public
00324 //  Description: This performs a lexicographical comparison.  It's of
00325 //               questionable mathematical meaning, but sometimes has
00326 //               a practical purpose for sorting unique vectors,
00327 //               especially in an STL container.  Also see
00328 //               compare_to().
00329 ////////////////////////////////////////////////////////////////////
00330 INLINE_LINMATH bool FLOATNAME(LVecBase2)::
00331 operator < (const FLOATNAME(LVecBase2) &other) const {
00332   return (compare_to(other) < 0);
00333 }
00334 
00335 ////////////////////////////////////////////////////////////////////
00336 //     Function: LVecBase2::operator ==
00337 //       Access: Public
00338 //  Description:
00339 ////////////////////////////////////////////////////////////////////
00340 INLINE_LINMATH bool FLOATNAME(LVecBase2)::
00341 operator == (const FLOATNAME(LVecBase2) &other) const {
00342   return (_v.v._0 == other._v.v._0 &&
00343           _v.v._1 == other._v.v._1);
00344 }
00345 
00346 ////////////////////////////////////////////////////////////////////
00347 //     Function: LVecBase2::operator !=
00348 //       Access: Public
00349 //  Description:
00350 ////////////////////////////////////////////////////////////////////
00351 INLINE_LINMATH bool FLOATNAME(LVecBase2)::
00352 operator != (const FLOATNAME(LVecBase2) &other) const {
00353   return !operator == (other);
00354 }
00355 
00356 ////////////////////////////////////////////////////////////////////
00357 //     Function: LVecBase2::compare_to
00358 //       Access: Public
00359 //  Description: This flavor of compare_to uses a default threshold
00360 //               value based on the numeric type.
00361 ////////////////////////////////////////////////////////////////////
00362 INLINE_LINMATH int FLOATNAME(LVecBase2)::
00363 compare_to(const FLOATNAME(LVecBase2) &other) const {
00364   return compare_to(other, NEARLY_ZERO(FLOATTYPE));
00365 }
00366 
00367 ////////////////////////////////////////////////////////////////////
00368 //     Function: LVecBase2::compare_to
00369 //       Access: Public
00370 //  Description: Sorts vectors lexicographically, componentwise.
00371 //               Returns a number less than 0 if this vector sorts
00372 //               before the other one, greater than zero if it sorts
00373 //               after, 0 if they are equivalent (within the indicated
00374 //               tolerance).
00375 ////////////////////////////////////////////////////////////////////
00376 INLINE_LINMATH int FLOATNAME(LVecBase2)::
00377 compare_to(const FLOATNAME(LVecBase2) &other, FLOATTYPE threshold) const {
00378   if (!IS_THRESHOLD_COMPEQ(_v.v._0, other._v.v._0, threshold)) {
00379     return (_v.v._0 < other._v.v._0) ? -1 : 1;
00380   }
00381   if (!IS_THRESHOLD_COMPEQ(_v.v._1, other._v.v._1, threshold)) {
00382     return (_v.v._1 < other._v.v._1) ? -1 : 1;
00383   }
00384   return 0;
00385 }
00386 
00387 ////////////////////////////////////////////////////////////////////
00388 //     Function: LVecBase2::unary -
00389 //       Access: Public
00390 //  Description:
00391 ////////////////////////////////////////////////////////////////////
00392 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
00393 operator - () const {
00394   return FLOATNAME(LVecBase2)(-_v.v._0, -_v.v._1);
00395 }
00396 
00397 ////////////////////////////////////////////////////////////////////
00398 //     Function: LVecBase2::vector + vector
00399 //       Access: Public
00400 //  Description:
00401 ////////////////////////////////////////////////////////////////////
00402 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
00403 operator + (const FLOATNAME(LVecBase2) &other) const {
00404   return FLOATNAME(LVecBase2)(_v.v._0 + other._v.v._0,
00405                               _v.v._1 + other._v.v._1);
00406 }
00407 
00408 ////////////////////////////////////////////////////////////////////
00409 //     Function: LVecBase2::vector - vector
00410 //       Access: Public
00411 //  Description:
00412 ////////////////////////////////////////////////////////////////////
00413 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
00414 operator - (const FLOATNAME(LVecBase2) &other) const {
00415   return FLOATNAME(LVecBase2)(_v.v._0 - other._v.v._0,
00416                               _v.v._1 - other._v.v._1);
00417 }
00418 
00419 ////////////////////////////////////////////////////////////////////
00420 //     Function: LVecBase2::vector * scalar
00421 //       Access: Public
00422 //  Description:
00423 ////////////////////////////////////////////////////////////////////
00424 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
00425 operator * (FLOATTYPE scalar) const {
00426   return FLOATNAME(LVecBase2)(_v.v._0 * scalar,
00427                               _v.v._1 * scalar);
00428 }
00429 
00430 ////////////////////////////////////////////////////////////////////
00431 //     Function: LVecBase2::vector / scalar
00432 //       Access: Public
00433 //  Description:
00434 ////////////////////////////////////////////////////////////////////
00435 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
00436 operator / (FLOATTYPE scalar) const {
00437   FLOATTYPE recip_scalar = 1.0f/scalar;
00438   return FLOATNAME(LVecBase2)(_v.v._0 * recip_scalar,
00439                               _v.v._1 * recip_scalar);
00440 }
00441 
00442 ////////////////////////////////////////////////////////////////////
00443 //     Function: LVecBase2::operator +=
00444 //       Access: Public
00445 //  Description:
00446 ////////////////////////////////////////////////////////////////////
00447 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00448 operator += (const FLOATNAME(LVecBase2) &other) {
00449   _v.v._0 += other._v.v._0;
00450   _v.v._1 += other._v.v._1;
00451 }
00452 
00453 ////////////////////////////////////////////////////////////////////
00454 //     Function: LVecBase2::operator -=
00455 //       Access: Public
00456 //  Description:
00457 ////////////////////////////////////////////////////////////////////
00458 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00459 operator -= (const FLOATNAME(LVecBase2) &other) {
00460   _v.v._0 -= other._v.v._0;
00461   _v.v._1 -= other._v.v._1;
00462 }
00463 
00464 ////////////////////////////////////////////////////////////////////
00465 //     Function: LVecBase2::operator *=
00466 //       Access: Public
00467 //  Description:
00468 ////////////////////////////////////////////////////////////////////
00469 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00470 operator *= (FLOATTYPE scalar) {
00471   _v.v._0 *= scalar;
00472   _v.v._1 *= scalar;
00473 }
00474 
00475 ////////////////////////////////////////////////////////////////////
00476 //     Function: LVecBase2::operator /=
00477 //       Access: Public
00478 //  Description:
00479 ////////////////////////////////////////////////////////////////////
00480 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00481 operator /= (FLOATTYPE scalar) {
00482   FLOATTYPE recip_scalar = 1.0f/scalar;
00483   _v.v._0 *= recip_scalar;
00484   _v.v._1 *= recip_scalar;
00485 }
00486 
00487 ////////////////////////////////////////////////////////////////////
00488 //     Function: LVecBase2::almost_equal
00489 //       Access: Public
00490 //  Description: Returns true if two vectors are memberwise equal
00491 //               within a specified tolerance.
00492 ////////////////////////////////////////////////////////////////////
00493 INLINE_LINMATH bool FLOATNAME(LVecBase2)::
00494 almost_equal(const FLOATNAME(LVecBase2) &other, FLOATTYPE threshold) const {
00495   return (IS_THRESHOLD_EQUAL(_v.v._0, other._v.v._0, threshold) &&
00496           IS_THRESHOLD_EQUAL(_v.v._1, other._v.v._1, threshold));
00497 }
00498 
00499 ////////////////////////////////////////////////////////////////////
00500 //     Function: LVecBase2::almost_equal
00501 //       Access: Public
00502 //  Description: Returns true if two vectors are memberwise equal
00503 //               within a default tolerance based on the numeric type.
00504 ////////////////////////////////////////////////////////////////////
00505 INLINE_LINMATH bool FLOATNAME(LVecBase2)::
00506 almost_equal(const FLOATNAME(LVecBase2) &other) const {
00507   return almost_equal(other, NEARLY_ZERO(FLOATTYPE));
00508 }
00509 
00510 ////////////////////////////////////////////////////////////////////
00511 //     Function: LVecBase2::output
00512 //       Access: Public
00513 //  Description:
00514 ////////////////////////////////////////////////////////////////////
00515 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00516 output(ostream &out) const {
00517   out << MAYBE_ZERO(_v.v._0) << " "
00518       << MAYBE_ZERO(_v.v._1);
00519 }
00520 
00521 ////////////////////////////////////////////////////////////////////
00522 //     Function: LVecBase2::generate_hash
00523 //       Access: Public
00524 //  Description: Adds the vector to the indicated hash generator.
00525 ////////////////////////////////////////////////////////////////////
00526 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00527 generate_hash(ChecksumHashGenerator &hashgen) const {
00528   generate_hash(hashgen, NEARLY_ZERO(FLOATTYPE));
00529 }
00530 
00531 ////////////////////////////////////////////////////////////////////
00532 //     Function: LVecBase2::generate_hash
00533 //       Access: Public
00534 //  Description: Adds the vector to the indicated hash generator.
00535 ////////////////////////////////////////////////////////////////////
00536 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00537 generate_hash(ChecksumHashGenerator &hashgen, FLOATTYPE threshold) const {
00538   hashgen.add_fp(_v.v._0, threshold);
00539   hashgen.add_fp(_v.v._1, threshold);
00540 }
00541 
00542 ////////////////////////////////////////////////////////////////////
00543 //     Function: LVecBase2::write_datagram
00544 //       Access: Public
00545 //  Description: Function to write itself into a datagram
00546 ////////////////////////////////////////////////////////////////////
00547 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00548 write_datagram(Datagram &destination) const {
00549   destination.add_float32(_v.v._0);
00550   destination.add_float32(_v.v._1);
00551 }
00552 
00553 ////////////////////////////////////////////////////////////////////
00554 //     Function: LVecBase2::read_datagram
00555 //       Access: Public
00556 //  Description: Function to read itself from a datagramIterator
00557 ////////////////////////////////////////////////////////////////////
00558 INLINE_LINMATH void FLOATNAME(LVecBase2)::
00559 read_datagram(DatagramIterator &source) {
00560   _v.v._0 = source.get_float32();
00561   _v.v._1 = source.get_float32();
00562 }
00563 

Generated on Fri May 2 00:40:15 2003 for Panda by doxygen1.3