| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- // Filename: lvector2_src.I
- // Created by: drose (08Mar00)
- //
- ////////////////////////////////////////////////////////////////////
- //
- // PANDA 3D SOFTWARE
- // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
- //
- // All use of this software is subject to the terms of the Panda 3d
- // Software license. You should have received a copy of this license
- // along with this source code; you will also find a current copy of
- // the license at http://etc.cmu.edu/panda3d/docs/license/ .
- //
- // To contact the maintainers of this program write to
- // [email protected] .
- //
- ////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::Default Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2)::
- FLOATNAME(LVector2)() {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::Copy Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2)::
- FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(copy) {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::Copy Assignment Operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2) &FLOATNAME(LVector2)::
- operator = (const FLOATNAME(LVecBase2) ©) {
- FLOATNAME(LVecBase2)::operator = (copy);
- return *this;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::Copy Fill Operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2) &FLOATNAME(LVector2)::
- operator = (FLOATTYPE fill_value) {
- FLOATNAME(LVecBase2)::operator = (fill_value);
- return *this;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2)::
- FLOATNAME(LVector2)(FLOATTYPE fill_value) :
- FLOATNAME(LVecBase2)(fill_value)
- {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2)::
- FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y) :
- FLOATNAME(LVecBase2)(x, y)
- {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::zero Named Constructor
- // Access: Public
- // Description: Returns a zero-length vector.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH const FLOATNAME(LVector2) &FLOATNAME(LVector2)::
- zero() {
- return (const FLOATNAME(LVector2) &)FLOATNAME(LVecBase2)::zero();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::unit_x Named Constructor
- // Access: Public
- // Description: Returns a unit X vector.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH const FLOATNAME(LVector2) &FLOATNAME(LVector2)::
- unit_x() {
- return (const FLOATNAME(LVector2) &)FLOATNAME(LVecBase2)::unit_x();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::unit_y Named Constructor
- // Access: Public
- // Description: Returns a unit Y vector.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH const FLOATNAME(LVector2) &FLOATNAME(LVector2)::
- unit_y() {
- return (const FLOATNAME(LVector2) &)FLOATNAME(LVecBase2)::unit_y();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::unary -
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2)::
- operator - () const {
- return FLOATNAME(LVecBase2)::operator - ();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::vector + vecbase
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVector2)::
- operator + (const FLOATNAME(LVecBase2) &other) const {
- return FLOATNAME(LVecBase2)::operator + (other);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::vector + vector
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2)::
- operator + (const FLOATNAME(LVector2) &other) const {
- return FLOATNAME(LVecBase2)::operator + (other);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::vector - vecbase
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVector2)::
- operator - (const FLOATNAME(LVecBase2) &other) const {
- return FLOATNAME(LVecBase2)::operator - (other);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::vector - vector
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2)::
- operator - (const FLOATNAME(LVector2) &other) const {
- return FLOATNAME(LVecBase2)::operator - (other);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::length
- // Access: Public
- // Description: Returns the length of the vector, by the Pythagorean
- // theorem.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2)::
- length() const {
- return csqrt((*this).dot(*this));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::length_squared
- // Access: Public
- // Description: Returns the square of the vector's length, cheap and
- // easy.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2)::
- length_squared() const {
- return (*this).dot(*this);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::normalize
- // Access: Public
- // Description: Normalizes the vector in place. Returns true if the
- // vector was normalized, false if it was a zero-length
- // vector.
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH bool FLOATNAME(LVector2)::
- normalize() {
- FLOATTYPE l2 = length_squared();
- if (l2 == (FLOATTYPE)0.0f) {
- set(0.0f, 0.0f);
- return false;
- } else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) {
- (*this) /= csqrt(l2);
- }
- return true;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::operator * scalar
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2)::
- operator * (FLOATTYPE scalar) const {
- return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (scalar));
- }
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::operator / scalar
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2)::
- operator / (FLOATTYPE scalar) const {
- FLOATTYPE recip_scalar = 1.0f/scalar;
- return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (recip_scalar));
- }
- #ifdef HAVE_PYTHON
- ////////////////////////////////////////////////////////////////////
- // Function: LVector2::python_repr
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE_LINMATH void FLOATNAME(LVector2)::
- python_repr(ostream &out, const string &class_name) const {
- FLOATNAME(LVecBase2)::python_repr(out, class_name);
- }
- #endif // HAVE_PYTHON
|