diff --git a/dtool/src/dtoolbase/dtoolbase_cc.h b/dtool/src/dtoolbase/dtoolbase_cc.h index 2f722b7d22..836a51f027 100644 --- a/dtool/src/dtoolbase/dtoolbase_cc.h +++ b/dtool/src/dtoolbase/dtoolbase_cc.h @@ -39,6 +39,7 @@ using namespace std; #define FINAL #define OVERRIDE #define MOVE(x) x +#define DEFAULT_CTOR = default #define EXPORT_TEMPLATE_CLASS(expcl, exptp, classname) @@ -136,59 +137,83 @@ typedef ios::seekdir ios_seekdir; #if defined(__has_extension) // Clang magic. # if __has_extension(cxx_constexpr) # define CONSTEXPR constexpr -# else -# define CONSTEXPR INLINE # endif # if __has_extension(cxx_noexcept) # define NOEXCEPT noexcept -# else -# define NOEXCEPT # endif # if __has_extension(cxx_rvalue_references) && (__cplusplus >= 201103L) # define USE_MOVE_SEMANTICS # define MOVE(x) move(x) -# else -# define MOVE(x) x # endif # if __has_extension(cxx_override_control) && (__cplusplus >= 201103L) # define FINAL final # define OVERRIDE override -# else -# define FINAL -# define OVERRIDE # endif -#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && (__cplusplus >= 201103L) -// noexcept was introduced in GCC 4.6, constexpr in GCC 4.7, rvalue refs in -// GCC 4.3. However, GCC only started defining __cplusplus properly in 4.7. +# if __has_extension(cxx_defaulted_functions) +# define DEFAULT_CTOR = default +# endif +#elif defined(__GNUC__) && (__cplusplus >= 201103L) // GCC + +// GCC defines several macros which we can query. +// List of all supported builtin macros: https://gcc.gnu.org/projects/cxx0x.html +# if __cpp_constexpr >= 200704 +# define CONSTEXPR constexpr +# endif + +// Starting at GCC 4.4 +# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) +# define DEFAULT_CTOR = default +# endif + +// Starting at GCC 4.6 +# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +# define NOEXCEPT noexcept +# define USE_MOVE_SEMANTICS +# define FINAL final +# define MOVE(x) move(x) +# endif + +// Starting at GCC 4.7 +# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) +# define OVERRIDE override +# endif + +#elif defined(_MSC_VER) && _MSC_VER >= 1900 // Visual Studio 2015 # define CONSTEXPR constexpr # define NOEXCEPT noexcept # define USE_MOVE_SEMANTICS # define FINAL final # define OVERRIDE override # define MOVE(x) move(x) -#elif defined(_MSC_VER) && _MSC_VER >= 1900 -// MSVC 2015 supports all of this goodness. -# define CONSTEXPR constexpr -# define NOEXCEPT noexcept -# define USE_MOVE_SEMANTICS -# define FINAL final -# define OVERRIDE override -# define MOVE(x) move(x) -#elif defined(_MSC_VER) && _MSC_VER >= 1600 -// MSVC 2010 has move semantics. Not much else. -# define CONSTEXPR INLINE +# define DEFAULT_CTOR = default +#elif defined(_MSC_VER) && _MSC_VER >= 1600 // Visual Studio 2010 # define NOEXCEPT throw() +# define OVERRIDE override # define USE_MOVE_SEMANTICS -# define FINAL -# define OVERRIDE +# define FINAL sealed # define MOVE(x) move(x) -#else +#endif + +// Fallbacks if features are not supported +#ifndef CONSTEXPR # define CONSTEXPR INLINE +#endif +#ifndef NOEXCEPT # define NOEXCEPT -# define FINAL -# define OVERRIDE +#endif +#ifndef MOVE # define MOVE(x) x #endif +#ifndef FINAL +# define FINAL +#endif +#ifndef OVERRIDE +# define OVERRIDE +#endif +#ifndef DEFAULT_CTOR +# define DEFAULT_CTOR {} +#endif + #if !defined(LINK_ALL_STATIC) && defined(EXPORT_TEMPLATES) // This macro must be used to export an instantiated template class diff --git a/dtool/src/parser-inc/Eigen/Dense b/dtool/src/parser-inc/Eigen/Dense index ab3fac8475..4219dc4652 100644 --- a/dtool/src/parser-inc/Eigen/Dense +++ b/dtool/src/parser-inc/Eigen/Dense @@ -1,4 +1,5 @@ namespace Eigen { - template - class Matrix; + template + class Matrix { + }; }; diff --git a/panda/src/linmath/lpoint2_src.I b/panda/src/linmath/lpoint2_src.I index a3f27084f6..4c94dab00d 100644 --- a/panda/src/linmath/lpoint2_src.I +++ b/panda/src/linmath/lpoint2_src.I @@ -14,49 +14,21 @@ //////////////////////////////////////////////////////////////////// -// Function: LPoint2::Default Constructor +// Function: LPoint2::Constructor // Access: Public -// Description: +// Description: Constructs a new LPoint2 from a LVecBase2 //////////////////////////////////////////////////////////////////// INLINE_LINMATH FLOATNAME(LPoint2):: -FLOATNAME(LPoint2)() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LPoint2):: -FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2) ©) : FLOATNAME(LVecBase2)(copy) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: -operator = (const FLOATNAME(LVecBase2) ©) { - FLOATNAME(LVecBase2)::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint2::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LPoint2) &FLOATNAME(LPoint2):: -operator = (FLOATTYPE fill_value) { - FLOATNAME(LVecBase2)::operator = (fill_value); - return *this; +FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2)& copy) : + FLOATNAME(LVecBase2)(copy) +{ } //////////////////////////////////////////////////////////////////// // Function: LPoint2::Constructor // Access: Public -// Description: +// Description: Constructs a new LPoint2 all components set to the +// fill value. //////////////////////////////////////////////////////////////////// INLINE_LINMATH FLOATNAME(LPoint2):: FLOATNAME(LPoint2)(FLOATTYPE fill_value) : @@ -67,7 +39,7 @@ FLOATNAME(LPoint2)(FLOATTYPE fill_value) : //////////////////////////////////////////////////////////////////// // Function: LPoint2::Constructor // Access: Public -// Description: +// Description: Constructs a new LPoint2 with the given components //////////////////////////////////////////////////////////////////// INLINE_LINMATH FLOATNAME(LPoint2):: FLOATNAME(LPoint2)(FLOATTYPE x, FLOATTYPE y) : @@ -186,6 +158,18 @@ operator / (FLOATTYPE scalar) const { } #ifndef FLOATTYPE_IS_INT +//////////////////////////////////////////////////////////////////// +// Function: LPoint2::normalized +// Access: Published +// Description: Normalizes the vector and returns the normalized +// vector as a copy. If the vector was a zero-length +// vector, a zero length vector will be returned. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint2):: +normalized() const { + return FLOATNAME(LVecBase2)::normalized(); +} + //////////////////////////////////////////////////////////////////// // Function: LPoint2::project // Access: Published diff --git a/panda/src/linmath/lpoint2_src.h b/panda/src/linmath/lpoint2_src.h index 5347325800..cdac92e106 100644 --- a/panda/src/linmath/lpoint2_src.h +++ b/panda/src/linmath/lpoint2_src.h @@ -19,10 +19,9 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA_LINMATH FLOATNAME(LPoint2) : public FLOATNAME(LVecBase2) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LPoint2)(); - INLINE_LINMATH FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2) ©); - INLINE_LINMATH FLOATNAME(LPoint2) &operator = (const FLOATNAME(LVecBase2) ©); - INLINE_LINMATH FLOATNAME(LPoint2) &operator = (FLOATTYPE fill_value); + + INLINE_LINMATH FLOATNAME(LPoint2)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2)& copy); INLINE_LINMATH FLOATNAME(LPoint2)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LPoint2)(FLOATTYPE x, FLOATTYPE y); @@ -51,6 +50,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LPoint2) operator / (FLOATTYPE scalar) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LPoint2) normalized() const; INLINE_LINMATH FLOATNAME(LPoint2) project(const FLOATNAME(LVecBase2) &onto) const; #endif diff --git a/panda/src/linmath/lpoint3_src.I b/panda/src/linmath/lpoint3_src.I index 9f8143c7d7..71eb2f0b4d 100644 --- a/panda/src/linmath/lpoint3_src.I +++ b/panda/src/linmath/lpoint3_src.I @@ -13,15 +13,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LPoint3):: -FLOATNAME(LPoint3)() { -} - //////////////////////////////////////////////////////////////////// // Function: LPoint3::Copy Constructor // Access: Public @@ -31,28 +22,6 @@ INLINE_LINMATH FLOATNAME(LPoint3):: FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(copy) { } -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: -operator = (const FLOATNAME(LVecBase3) ©) { - FLOATNAME(LVecBase3)::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint3::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LPoint3) &FLOATNAME(LPoint3):: -operator = (FLOATTYPE fill_value) { - FLOATNAME(LVecBase3)::operator = (fill_value); - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: LPoint3::Constructor // Access: Public @@ -230,6 +199,18 @@ cross(const FLOATNAME(LVecBase3) &other) const { } #ifndef FLOATTYPE_IS_INT +//////////////////////////////////////////////////////////////////// +// Function: LPoint3::normalized +// Access: Published +// Description: Normalizes the vector and returns the normalized +// vector as a copy. If the vector was a zero-length +// vector, a zero length vector will be returned. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3):: +normalized() const { + return FLOATNAME(LVecBase3)::normalized(); +} + //////////////////////////////////////////////////////////////////// // Function: LPoint3::project // Access: Published diff --git a/panda/src/linmath/lpoint3_src.h b/panda/src/linmath/lpoint3_src.h index e8645529ff..0be8774815 100644 --- a/panda/src/linmath/lpoint3_src.h +++ b/panda/src/linmath/lpoint3_src.h @@ -24,10 +24,8 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA_LINMATH FLOATNAME(LPoint3) : public FLOATNAME(LVecBase3) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LPoint3)(); + INLINE_LINMATH FLOATNAME(LPoint3)() DEFAULT_CTOR; INLINE_LINMATH FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©); - INLINE_LINMATH FLOATNAME(LPoint3) &operator = (const FLOATNAME(LVecBase3) ©); - INLINE_LINMATH FLOATNAME(LPoint3) &operator = (FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LPoint3)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LPoint3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); INLINE_LINMATH FLOATNAME(LPoint3)(const FLOATNAME(LVecBase2) ©, FLOATTYPE z); @@ -61,6 +59,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LPoint3) cross(const FLOATNAME(LVecBase3) &other) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LPoint3) normalized() const; INLINE_LINMATH FLOATNAME(LPoint3) project(const FLOATNAME(LVecBase3) &onto) const; #endif diff --git a/panda/src/linmath/lpoint4_src.I b/panda/src/linmath/lpoint4_src.I index d1a7e7b3ab..0e37a0c533 100644 --- a/panda/src/linmath/lpoint4_src.I +++ b/panda/src/linmath/lpoint4_src.I @@ -13,15 +13,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LPoint4):: -FLOATNAME(LPoint4)() { -} - //////////////////////////////////////////////////////////////////// // Function: LPoint4::Copy Constructor // Access: Public @@ -31,28 +22,6 @@ INLINE_LINMATH FLOATNAME(LPoint4):: FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy) { } -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: -operator = (const FLOATNAME(LVecBase4) ©) { - FLOATNAME(LVecBase4)::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LPoint4::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LPoint4) &FLOATNAME(LPoint4):: -operator = (FLOATTYPE fill_value) { - FLOATNAME(LVecBase4)::operator = (fill_value); - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: LPoint4::Constructor // Access: Public @@ -217,6 +186,19 @@ operator / (FLOATTYPE scalar) const { } #ifndef FLOATTYPE_IS_INT + +//////////////////////////////////////////////////////////////////// +// Function: LPoint4::normalized +// Access: Published +// Description: Normalizes the vector and returns the normalized +// vector as a copy. If the vector was a zero-length +// vector, a zero length vector will be returned. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LPoint4) FLOATNAME(LPoint4):: +normalized() const { + return FLOATNAME(LVecBase4)::normalized(); +} + //////////////////////////////////////////////////////////////////// // Function: LPoint4::project // Access: Published diff --git a/panda/src/linmath/lpoint4_src.h b/panda/src/linmath/lpoint4_src.h index 50eeb1ce5d..a9c4ed59fe 100644 --- a/panda/src/linmath/lpoint4_src.h +++ b/panda/src/linmath/lpoint4_src.h @@ -18,10 +18,8 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA_LINMATH FLOATNAME(LPoint4) : public FLOATNAME(LVecBase4) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LPoint4)(); + INLINE_LINMATH FLOATNAME(LPoint4)() DEFAULT_CTOR; INLINE_LINMATH FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©); - INLINE_LINMATH FLOATNAME(LPoint4) &operator = (const FLOATNAME(LVecBase4) ©); - INLINE_LINMATH FLOATNAME(LPoint4) &operator = (FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LPoint4)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LPoint4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); INLINE_LINMATH FLOATNAME(LPoint4)(const FLOATNAME(LVecBase3) ©, FLOATTYPE w); @@ -53,6 +51,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LPoint4) operator / (FLOATTYPE scalar) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LPoint4) normalized() const; INLINE_LINMATH FLOATNAME(LPoint4) project(const FLOATNAME(LVecBase4) &onto) const; #endif diff --git a/panda/src/linmath/lvecBase2_src.I b/panda/src/linmath/lvecBase2_src.I index 14057fbd50..c6745112ae 100644 --- a/panda/src/linmath/lvecBase2_src.I +++ b/panda/src/linmath/lvecBase2_src.I @@ -12,48 +12,6 @@ // //////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Default Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase2):: -FLOATNAME(LVecBase2)() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Copy Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase2):: -FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©) : _v(copy._v) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Copy Assignment Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: -operator = (const FLOATNAME(LVecBase2) ©) { - TAU_PROFILE("void LVecBase2::operator = (LVecBase2 &)", " ", TAU_USER); - _v = copy._v; - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Fill Assignment Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase2) &FLOATNAME(LVecBase2):: -operator = (FLOATTYPE fill_value) { - fill(fill_value); - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: LVecBase2::Constructor // Access: Published @@ -107,15 +65,6 @@ unit_y() { return _unit_y; } -//////////////////////////////////////////////////////////////////// -// Function: LVecBase2::Destructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase2):: -~FLOATNAME(LVecBase2)() { -} - //////////////////////////////////////////////////////////////////// // Function: LVecBase2::Indexing Operator // Access: Published @@ -143,7 +92,7 @@ operator [](int i) { // Access: Published, Static // Description: Returns 2: the number of components of a LVecBase2. //////////////////////////////////////////////////////////////////// -INLINE_LINMATH int FLOATNAME(LVecBase2):: +CONSTEXPR int FLOATNAME(LVecBase2):: size() { return 2; } @@ -274,8 +223,8 @@ get_data() const { // Access: Published // Description: Returns the number of elements in the vector, two. //////////////////////////////////////////////////////////////////// -INLINE_LINMATH int FLOATNAME(LVecBase2):: -get_num_components() const { +CONSTEXPR int FLOATNAME(LVecBase2):: +get_num_components() { return 2; } @@ -418,6 +367,22 @@ normalize() { return true; } +//////////////////////////////////////////////////////////////////// +// Function: LVecBase2::normalized +// Access: Published +// Description: Normalizes the vector and returns the normalized +// vector as a copy. If the vector was a zero-length +// vector, a zero length vector will be returned. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: +normalized() const { + FLOATTYPE l2 = length_squared(); + if (l2 == (FLOATTYPE)0.0f) { + return FLOATNAME(LVecBase2)(0.0f); + } + return (*this) / csqrt(l2); +} + //////////////////////////////////////////////////////////////////// // Function: LVecBase2::project // Access: Published diff --git a/panda/src/linmath/lvecBase2_src.h b/panda/src/linmath/lvecBase2_src.h index f1f6d125e0..1094b03617 100644 --- a/panda/src/linmath/lvecBase2_src.h +++ b/panda/src/linmath/lvecBase2_src.h @@ -34,38 +34,38 @@ PUBLISHED: #endif }; - INLINE_LINMATH FLOATNAME(LVecBase2)(); - INLINE_LINMATH FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©); - INLINE_LINMATH FLOATNAME(LVecBase2) &operator = (const FLOATNAME(LVecBase2) ©); - INLINE_LINMATH FLOATNAME(LVecBase2) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVecBase2)() DEFAULT_CTOR; INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y); + ALLOC_DELETED_CHAIN(FLOATNAME(LVecBase2)); INLINE_LINMATH static const FLOATNAME(LVecBase2) &zero(); INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_x(); INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_y(); - INLINE_LINMATH ~FLOATNAME(LVecBase2)(); - EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const string &attr_name) const); EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const string &attr_name, PyObject *assign)); INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); - INLINE_LINMATH static int size(); + CONSTEXPR static int size(); INLINE_LINMATH bool is_nan() const; INLINE_LINMATH FLOATTYPE get_cell(int i) const; + INLINE_LINMATH void set_cell(int i, FLOATTYPE value); + INLINE_LINMATH FLOATTYPE get_x() const; INLINE_LINMATH FLOATTYPE get_y() const; - - INLINE_LINMATH void set_cell(int i, FLOATTYPE value); INLINE_LINMATH void set_x(FLOATTYPE value); INLINE_LINMATH void set_y(FLOATTYPE value); +PUBLISHED: + MAKE_PROPERTY(x, get_x, set_x); + MAKE_PROPERTY(y, get_y, set_y); + // These next functions add to an existing value. // i.e. foo.set_x(foo.get_x() + value) // These are useful to reduce overhead in scripting @@ -75,7 +75,7 @@ PUBLISHED: INLINE_LINMATH void add_y(FLOATTYPE value); INLINE_LINMATH const FLOATTYPE *get_data() const; - INLINE_LINMATH int get_num_components() const; + CONSTEXPR static int get_num_components(); public: INLINE_LINMATH iterator begin(); @@ -94,6 +94,7 @@ PUBLISHED: #ifndef FLOATTYPE_IS_INT INLINE_LINMATH FLOATTYPE length() const; INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATNAME(LVecBase2) normalized() const; INLINE_LINMATH FLOATNAME(LVecBase2) project(const FLOATNAME(LVecBase2) &onto) const; #endif diff --git a/panda/src/linmath/lvecBase3_src.I b/panda/src/linmath/lvecBase3_src.I index 35df48b008..b63fdd6f21 100644 --- a/panda/src/linmath/lvecBase3_src.I +++ b/panda/src/linmath/lvecBase3_src.I @@ -13,47 +13,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase3):: -FLOATNAME(LVecBase3)() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase3):: -FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) ©) : _v(copy._v) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: -operator = (const FLOATNAME(LVecBase3) ©) { - TAU_PROFILE("void LVecBase3::operator =(LVecBase3 &)", " ", TAU_USER); - _v = copy._v; - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Fill Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase3) &FLOATNAME(LVecBase3):: -operator = (FLOATTYPE fill_value) { - fill(fill_value); - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: LVecBase3::Constructor // Access: Public @@ -128,15 +87,6 @@ unit_z() { return _unit_z; } -//////////////////////////////////////////////////////////////////// -// Function: LVecBase3::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase3):: -~FLOATNAME(LVecBase3)() { -} - //////////////////////////////////////////////////////////////////// // Function: LVecBase3::Indexing Operator // Access: Public @@ -164,7 +114,7 @@ operator [](int i) { // Access: Public, Static // Description: Returns 3: the number of components of a LVecBase3. //////////////////////////////////////////////////////////////////// -INLINE_LINMATH int FLOATNAME(LVecBase3):: +CONSTEXPR int FLOATNAME(LVecBase3):: size() { return 3; } @@ -358,8 +308,8 @@ get_data() const { // Access: Public // Description: Returns the number of elements in the vector, three. //////////////////////////////////////////////////////////////////// -INLINE_LINMATH int FLOATNAME(LVecBase3):: -get_num_components() const { +CONSTEXPR int FLOATNAME(LVecBase3):: +get_num_components() { return 3; } @@ -509,6 +459,22 @@ normalize() { return true; } +//////////////////////////////////////////////////////////////////// +// Function: LVecBase3::normalized +// Access: Published +// Description: Normalizes the vector and returns the normalized +// vector as a copy. If the vector was a zero-length +// vector, a zero length vector will be returned. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: +normalized() const { + FLOATTYPE l2 = length_squared(); + if (l2 == (FLOATTYPE)0.0f) { + return FLOATNAME(LVecBase3)(0.0f); + } + return (*this) / csqrt(l2); +} + //////////////////////////////////////////////////////////////////// // Function: LVecBase3::project // Access: Published diff --git a/panda/src/linmath/lvecBase3_src.h b/panda/src/linmath/lvecBase3_src.h index f2820acd50..f7641df367 100644 --- a/panda/src/linmath/lvecBase3_src.h +++ b/panda/src/linmath/lvecBase3_src.h @@ -34,10 +34,7 @@ PUBLISHED: #endif }; - INLINE_LINMATH FLOATNAME(LVecBase3)(); - INLINE_LINMATH FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase3) ©); - INLINE_LINMATH FLOATNAME(LVecBase3) &operator = (const FLOATNAME(LVecBase3) ©); - INLINE_LINMATH FLOATNAME(LVecBase3) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVecBase3)() DEFAULT_CTOR; INLINE_LINMATH FLOATNAME(LVecBase3)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVecBase3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); INLINE_LINMATH FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase2) ©, FLOATTYPE z); @@ -48,15 +45,13 @@ PUBLISHED: INLINE_LINMATH static const FLOATNAME(LVecBase3) &unit_y(); INLINE_LINMATH static const FLOATNAME(LVecBase3) &unit_z(); - INLINE_LINMATH ~FLOATNAME(LVecBase3)(); - EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const string &attr_name) const); EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const string &attr_name, PyObject *assign)); INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); - INLINE_LINMATH static int size(); + CONSTEXPR static int size(); INLINE_LINMATH bool is_nan() const; @@ -74,6 +69,12 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVecBase2) get_xz() const; INLINE_LINMATH FLOATNAME(LVecBase2) get_yz() const; +PUBLISHED: + MAKE_PROPERTY(x, get_x, set_x); + MAKE_PROPERTY(y, get_y, set_y); + MAKE_PROPERTY(z, get_z, set_z); + MAKE_PROPERTY(xy, get_xy); + // These next functions add to an existing value. // i.e. foo.set_x(foo.get_x() + value) // These are useful to reduce overhead in scripting @@ -84,7 +85,7 @@ PUBLISHED: INLINE_LINMATH void add_z(FLOATTYPE value); INLINE_LINMATH const FLOATTYPE *get_data() const; - INLINE_LINMATH int get_num_components() const; + CONSTEXPR static int get_num_components(); public: INLINE_LINMATH iterator begin(); @@ -103,6 +104,7 @@ PUBLISHED: #ifndef FLOATTYPE_IS_INT INLINE_LINMATH FLOATTYPE length() const; INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATNAME(LVecBase3) normalized() const; INLINE_LINMATH FLOATNAME(LVecBase3) project(const FLOATNAME(LVecBase3) &onto) const; #endif diff --git a/panda/src/linmath/lvecBase4_src.I b/panda/src/linmath/lvecBase4_src.I index f8c8422c58..6ed6bbd009 100644 --- a/panda/src/linmath/lvecBase4_src.I +++ b/panda/src/linmath/lvecBase4_src.I @@ -13,24 +13,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Default Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase4):: -FLOATNAME(LVecBase4)() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Copy Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase4):: -FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©) : _v(copy._v) { -} - //////////////////////////////////////////////////////////////////// // Function: LVecBase4::Copy Constructor // Access: Public @@ -41,40 +23,6 @@ FLOATNAME(LVecBase4)(const FLOATNAME(UnalignedLVecBase4) ©) { set(copy[0], copy[1], copy[2], copy[3]); } -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Copy Assignment Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: -operator = (const FLOATNAME(LVecBase4) ©) { - TAU_PROFILE("void LVecBase4::operator = (LVecBase4 &)", " ", TAU_USER); - _v = copy._v; - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: -operator = (const FLOATNAME(UnalignedLVecBase4) ©) { - set(copy[0], copy[1], copy[2], copy[3]); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Fill Assignment Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase4) &FLOATNAME(LVecBase4):: -operator = (FLOATTYPE fill_value) { - fill(fill_value); - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: LVecBase4::Constructor // Access: Published @@ -128,15 +76,6 @@ FLOATNAME(LVecBase4)(const FLOATNAME(LVector3) &vector) { set(vector[0], vector[1], vector[2], 0); } -//////////////////////////////////////////////////////////////////// -// Function: LVecBase4::Destructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVecBase4):: -~FLOATNAME(LVecBase4)() { -} - //////////////////////////////////////////////////////////////////// // Function: LVecBase4::zero Named Constructor // Access: Published @@ -214,7 +153,7 @@ operator [](int i) { // Access: Published, Static // Description: Returns 4: the number of components of a LVecBase4. //////////////////////////////////////////////////////////////////// -INLINE_LINMATH int FLOATNAME(LVecBase4):: +CONSTEXPR int FLOATNAME(LVecBase4):: size() { return 4; } @@ -286,6 +225,26 @@ get_w() const { return _v(3); } +//////////////////////////////////////////////////////////////////// +// Function: LVecBase4::get_xyz +// Access: Published +// Description: Returns the x, y and z component of this vector +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase4):: +get_xyz() const { + return FLOATNAME(LVecBase3)(_v(0), _v(1), _v(2)); +} + +//////////////////////////////////////////////////////////////////// +// Function: LVecBase4::get_xy +// Access: Published +// Description: Returns the x and y component of this vector +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase4):: +get_xy() const { + return FLOATNAME(LVecBase2)(_v(0), _v(1)); +} + //////////////////////////////////////////////////////////////////// // Function: LVecBase4::set_cell // Access: Published @@ -405,8 +364,8 @@ get_data() const { // Access: Published // Description: Returns the number of elements in the vector, four. //////////////////////////////////////////////////////////////////// -INLINE_LINMATH int FLOATNAME(LVecBase4):: -get_num_components() const { +CONSTEXPR int FLOATNAME(LVecBase4):: +get_num_components() { return 4; } @@ -559,6 +518,22 @@ normalize() { return true; } +//////////////////////////////////////////////////////////////////// +// Function: LVecBase4::normalized +// Access: Published +// Description: Normalizes the vector and returns the normalized +// vector as a copy. If the vector was a zero-length +// vector, a zero length vector will be returned. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: +normalized() const { + FLOATTYPE l2 = length_squared(); + if (l2 == (FLOATTYPE)0.0f) { + return FLOATNAME(LVecBase4)(0.0f); + } + return (*this) / csqrt(l2); +} + //////////////////////////////////////////////////////////////////// // Function: LVecBase4::project // Access: Published @@ -1107,15 +1082,6 @@ read_datagram(DatagramIterator &source) { #endif } -//////////////////////////////////////////////////////////////////// -// Function: UnalignedLVecBase4::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(UnalignedLVecBase4):: -FLOATNAME(UnalignedLVecBase4)() { -} - //////////////////////////////////////////////////////////////////// // Function: UnalignedLVecBase4::Copy Constructor // Access: Public @@ -1126,38 +1092,6 @@ FLOATNAME(UnalignedLVecBase4)(const FLOATNAME(LVecBase4) ©) { set(copy[0], copy[1], copy[2], copy[3]); } -//////////////////////////////////////////////////////////////////// -// Function: UnalignedLVecBase4::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(UnalignedLVecBase4):: -FLOATNAME(UnalignedLVecBase4)(const FLOATNAME(UnalignedLVecBase4) ©) : _v(copy._v) { -} - -//////////////////////////////////////////////////////////////////// -// Function: UnalignedLVecBase4::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(UnalignedLVecBase4) &FLOATNAME(UnalignedLVecBase4):: -operator = (const FLOATNAME(LVecBase4) ©) { - set(copy[0], copy[1], copy[2], copy[3]); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: UnalignedLVecBase4::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(UnalignedLVecBase4) &FLOATNAME(UnalignedLVecBase4):: -operator = (const FLOATNAME(UnalignedLVecBase4) ©) { - TAU_PROFILE("void UnalignedLVecBase4::operator =(UnalignedLVecBase4 &)", " ", TAU_USER); - _v = copy._v; - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: UnalignedLVecBase4::Constructor // Access: Public @@ -1210,7 +1144,7 @@ operator [](int i) { // Access: Public, Static // Description: Returns 4: the number of components of a LVecBase4. //////////////////////////////////////////////////////////////////// -INLINE_LINMATH int FLOATNAME(UnalignedLVecBase4):: +CONSTEXPR int FLOATNAME(UnalignedLVecBase4):: size() { return 4; } @@ -1232,7 +1166,7 @@ get_data() const { // Access: Public // Description: Returns the number of elements in the vector, 4. //////////////////////////////////////////////////////////////////// -INLINE_LINMATH int FLOATNAME(UnalignedLVecBase4):: -get_num_components() const { +CONSTEXPR int FLOATNAME(UnalignedLVecBase4):: +get_num_components() { return 4; } diff --git a/panda/src/linmath/lvecBase4_src.h b/panda/src/linmath/lvecBase4_src.h index 988d31b859..79b136eec1 100644 --- a/panda/src/linmath/lvecBase4_src.h +++ b/panda/src/linmath/lvecBase4_src.h @@ -39,14 +39,10 @@ PUBLISHED: #endif }; - INLINE_LINMATH FLOATNAME(LVecBase4)(); - INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase4) ©); - INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(UnalignedLVecBase4) ©); - INLINE_LINMATH FLOATNAME(LVecBase4) &operator = (const FLOATNAME(LVecBase4) ©); - INLINE_LINMATH FLOATNAME(LVecBase4) &operator = (const FLOATNAME(UnalignedLVecBase4) ©); - INLINE_LINMATH FLOATNAME(LVecBase4) &operator = (FLOATTYPE fill_value); + INLINE_LINMATH FLOATNAME(LVecBase4)() DEFAULT_CTOR; INLINE_LINMATH FLOATNAME(LVecBase4)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); + INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(UnalignedLVecBase4) ©); INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase3) ©, FLOATTYPE w); INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(LPoint3) &point); INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(LVector3) &vector); @@ -58,30 +54,39 @@ PUBLISHED: INLINE_LINMATH static const FLOATNAME(LVecBase4) &unit_z(); INLINE_LINMATH static const FLOATNAME(LVecBase4) &unit_w(); - INLINE_LINMATH ~FLOATNAME(LVecBase4)(); - EXTENSION(INLINE_LINMATH PyObject *__reduce__(PyObject *self) const); EXTENSION(INLINE_LINMATH PyObject *__getattr__(PyObject *self, const string &attr_name) const); EXTENSION(INLINE_LINMATH int __setattr__(PyObject *self, const string &attr_name, PyObject *assign)); INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); - INLINE_LINMATH static int size(); + CONSTEXPR static int size(); INLINE_LINMATH bool is_nan() const; INLINE_LINMATH FLOATTYPE get_cell(int i) const; + INLINE_LINMATH void set_cell(int i, FLOATTYPE value); + INLINE_LINMATH FLOATTYPE get_x() const; INLINE_LINMATH FLOATTYPE get_y() const; INLINE_LINMATH FLOATTYPE get_z() const; INLINE_LINMATH FLOATTYPE get_w() const; - INLINE_LINMATH void set_cell(int i, FLOATTYPE value); + INLINE_LINMATH FLOATNAME(LVecBase3) get_xyz() const; + INLINE_LINMATH FLOATNAME(LVecBase2) get_xy() const; + INLINE_LINMATH void set_x(FLOATTYPE value); INLINE_LINMATH void set_y(FLOATTYPE value); INLINE_LINMATH void set_z(FLOATTYPE value); INLINE_LINMATH void set_w(FLOATTYPE value); +PUBLISHED: + MAKE_PROPERTY(x, get_x, set_x); + MAKE_PROPERTY(y, get_y, set_y); + MAKE_PROPERTY(z, get_z, set_z); + MAKE_PROPERTY(xy, get_xy); + MAKE_PROPERTY(xyz, get_xyz); + // These next functions add to an existing value. // i.e. foo.set_x(foo.get_x() + value) // These are useful to reduce overhead in scripting @@ -93,7 +98,7 @@ PUBLISHED: INLINE_LINMATH void add_w(FLOATTYPE value); INLINE_LINMATH const FLOATTYPE *get_data() const; - INLINE_LINMATH int get_num_components() const; + CONSTEXPR static int get_num_components(); INLINE_LINMATH void extract_data(float*){}; public: @@ -113,6 +118,7 @@ PUBLISHED: #ifndef FLOATTYPE_IS_INT INLINE_LINMATH FLOATTYPE length() const; INLINE_LINMATH bool normalize(); + INLINE_LINMATH FLOATNAME(LVecBase4) normalized() const; INLINE_LINMATH FLOATNAME(LVecBase4) project(const FLOATNAME(LVecBase4) &onto) const; #endif @@ -223,21 +229,18 @@ PUBLISHED: #endif }; - INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)(); + INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)() DEFAULT_CTOR; INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)(const FLOATNAME(LVecBase4) ©); - INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)(const FLOATNAME(UnalignedLVecBase4) ©); - INLINE_LINMATH FLOATNAME(UnalignedLVecBase4) &operator = (const FLOATNAME(LVecBase4) ©); - INLINE_LINMATH FLOATNAME(UnalignedLVecBase4) &operator = (const FLOATNAME(UnalignedLVecBase4) ©); INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); - INLINE_LINMATH static int size(); + CONSTEXPR static int size(); INLINE_LINMATH const FLOATTYPE *get_data() const; - INLINE_LINMATH int get_num_components() const; + CONSTEXPR static int get_num_components(); public: typedef FLOATTYPE numeric_type; diff --git a/panda/src/linmath/lvector2_src.I b/panda/src/linmath/lvector2_src.I index 45c7975fea..19095a6a46 100644 --- a/panda/src/linmath/lvector2_src.I +++ b/panda/src/linmath/lvector2_src.I @@ -12,50 +12,23 @@ // //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// -// Function: LVector2::Default Constructor +// Function: LVector2::Constructor // Access: Public -// Description: +// Description: Constructs a new LVector2 from a LVecBase2 //////////////////////////////////////////////////////////////////// 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; +FLOATNAME(LVector2)(const FLOATNAME(LVecBase2)& copy) : + FLOATNAME(LVecBase2)(copy) +{ } //////////////////////////////////////////////////////////////////// // Function: LVector2::Constructor // Access: Public -// Description: +// Description: Constructs a new LVector2 with all components set +// to the fill value. //////////////////////////////////////////////////////////////////// INLINE_LINMATH FLOATNAME(LVector2):: FLOATNAME(LVector2)(FLOATTYPE fill_value) : @@ -175,6 +148,18 @@ operator / (FLOATTYPE scalar) const { } #ifndef FLOATTYPE_IS_INT +//////////////////////////////////////////////////////////////////// +// Function: LVector2::normalized +// Access: Published +// Description: Normalizes the vector and returns the normalized +// vector as a copy. If the vector was a zero-length +// vector, a zero length vector will be returned. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2):: +normalized() const { + return FLOATNAME(LVecBase2)::normalized(); +} + //////////////////////////////////////////////////////////////////// // Function: LVector2::project // Access: Published diff --git a/panda/src/linmath/lvector2_src.h b/panda/src/linmath/lvector2_src.h index 2ee50d34ab..3866be0269 100644 --- a/panda/src/linmath/lvector2_src.h +++ b/panda/src/linmath/lvector2_src.h @@ -18,10 +18,9 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA_LINMATH FLOATNAME(LVector2) : public FLOATNAME(LVecBase2) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LVector2)(); - INLINE_LINMATH FLOATNAME(LVector2)(const FLOATNAME(LVecBase2) ©); - INLINE_LINMATH FLOATNAME(LVector2) &operator = (const FLOATNAME(LVecBase2) ©); - INLINE_LINMATH FLOATNAME(LVector2) &operator = (FLOATTYPE fill_value); + + INLINE_LINMATH FLOATNAME(LVector2)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LVector2)(const FLOATNAME(LVecBase2)& copy); INLINE_LINMATH FLOATNAME(LVector2)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y); @@ -44,6 +43,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LVector2) normalized() const; INLINE_LINMATH FLOATNAME(LVector2) project(const FLOATNAME(LVecBase2) &onto) const; INLINE_LINMATH FLOATTYPE signed_angle_rad(const FLOATNAME(LVector2) &other) const; INLINE_LINMATH FLOATTYPE signed_angle_deg(const FLOATNAME(LVector2) &other) const; diff --git a/panda/src/linmath/lvector3_src.I b/panda/src/linmath/lvector3_src.I index 318d32d2c9..1144c14e07 100644 --- a/panda/src/linmath/lvector3_src.I +++ b/panda/src/linmath/lvector3_src.I @@ -13,15 +13,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: LVector3::Default Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVector3):: -FLOATNAME(LVector3)() { -} - //////////////////////////////////////////////////////////////////// // Function: LVector3::Copy Constructor // Access: Published @@ -31,27 +22,6 @@ INLINE_LINMATH FLOATNAME(LVector3):: FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©) : FLOATNAME(LVecBase3)(copy) { } -//////////////////////////////////////////////////////////////////// -// Function: LVector3::Copy Assignment Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVector3) &FLOATNAME(LVector3):: -operator = (const FLOATNAME(LVecBase3) ©) { - FLOATNAME(LVecBase3)::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector3::Copy Fill Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVector3) &FLOATNAME(LVector3):: -operator = (FLOATTYPE fill_value) { - FLOATNAME(LVecBase3)::operator = (fill_value); - return *this; -} //////////////////////////////////////////////////////////////////// // Function: LVector3::Constructor @@ -220,6 +190,19 @@ cross(const FLOATNAME(LVecBase3) &other) const { } #ifndef FLOATTYPE_IS_INT + +//////////////////////////////////////////////////////////////////// +// Function: LVector3::normalized +// Access: Published +// Description: Normalizes the vector and returns the normalized +// vector as a copy. If the vector was a zero-length +// vector, a zero length vector will be returned. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3):: +normalized() const { + return FLOATNAME(LVecBase3)::normalized(); +} + //////////////////////////////////////////////////////////////////// // Function: LVector3::project // Access: Published diff --git a/panda/src/linmath/lvector3_src.h b/panda/src/linmath/lvector3_src.h index 7e0dd196bb..926f5280bb 100644 --- a/panda/src/linmath/lvector3_src.h +++ b/panda/src/linmath/lvector3_src.h @@ -24,10 +24,8 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA_LINMATH FLOATNAME(LVector3) : public FLOATNAME(LVecBase3) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LVector3)(); + INLINE_LINMATH FLOATNAME(LVector3)() DEFAULT_CTOR; INLINE_LINMATH FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©); - INLINE_LINMATH FLOATNAME(LVector3) &operator = (const FLOATNAME(LVecBase3) ©); - INLINE_LINMATH FLOATNAME(LVector3) &operator = (FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVector3)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVector3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); INLINE_LINMATH FLOATNAME(LVector3)(const FLOATNAME(LVecBase2) ©, FLOATTYPE z); @@ -55,6 +53,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LVector3) normalized() const; INLINE_LINMATH FLOATNAME(LVector3) project(const FLOATNAME(LVecBase3) &onto) const; INLINE_LINMATH FLOATTYPE angle_rad(const FLOATNAME(LVector3) &other) const; INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LVector3) &other) const; diff --git a/panda/src/linmath/lvector4_src.I b/panda/src/linmath/lvector4_src.I index 78333268f4..047b7b2232 100644 --- a/panda/src/linmath/lvector4_src.I +++ b/panda/src/linmath/lvector4_src.I @@ -13,15 +13,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: LVector4::Default Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVector4):: -FLOATNAME(LVector4)() { -} - //////////////////////////////////////////////////////////////////// // Function: LVector4::Copy Constructor // Access: Public @@ -31,28 +22,6 @@ INLINE_LINMATH FLOATNAME(LVector4):: FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©) : FLOATNAME(LVecBase4)(copy) { } -//////////////////////////////////////////////////////////////////// -// Function: LVector4::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVector4) &FLOATNAME(LVector4):: -operator = (const FLOATNAME(LVecBase4) ©) { - FLOATNAME(LVecBase4)::operator = (copy); - return *this; -} - -//////////////////////////////////////////////////////////////////// -// Function: LVector4::Copy Fill Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_LINMATH FLOATNAME(LVector4) &FLOATNAME(LVector4):: -operator = (FLOATTYPE fill_value) { - FLOATNAME(LVecBase4)::operator = (fill_value); - return *this; -} - //////////////////////////////////////////////////////////////////// // Function: LVector4::Constructor // Access: Public @@ -207,6 +176,19 @@ operator / (FLOATTYPE scalar) const { } #ifndef FLOATTYPE_IS_INT + +//////////////////////////////////////////////////////////////////// +// Function: LVector4::normalized +// Access: Published +// Description: Normalizes the vector and returns the normalized +// vector as a copy. If the vector was a zero-length +// vector, a zero length vector will be returned. +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4):: +normalized() const { + return FLOATNAME(LVecBase4)::normalized(); +} + //////////////////////////////////////////////////////////////////// // Function: LVector4::project // Access: Published diff --git a/panda/src/linmath/lvector4_src.h b/panda/src/linmath/lvector4_src.h index ebf87429f6..a4cda0f612 100644 --- a/panda/src/linmath/lvector4_src.h +++ b/panda/src/linmath/lvector4_src.h @@ -18,10 +18,8 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA_LINMATH FLOATNAME(LVector4) : public FLOATNAME(LVecBase4) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LVector4)(); + INLINE_LINMATH FLOATNAME(LVector4)() DEFAULT_CTOR; INLINE_LINMATH FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©); - INLINE_LINMATH FLOATNAME(LVector4) &operator = (const FLOATNAME(LVecBase4) ©); - INLINE_LINMATH FLOATNAME(LVector4) &operator = (FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVector4)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); INLINE_LINMATH FLOATNAME(LVector4)(const FLOATNAME(LVecBase3) ©, FLOATTYPE w); @@ -47,6 +45,7 @@ PUBLISHED: INLINE_LINMATH FLOATNAME(LVector4) operator / (FLOATTYPE scalar) const; #ifndef FLOATTYPE_IS_INT + INLINE_LINMATH FLOATNAME(LVector4) normalized() const; INLINE_LINMATH FLOATNAME(LVector4) project(const FLOATNAME(LVecBase4) &onto) const; #endif