From 916d461e3e324f0f229c19c220dd34f094a2da2c Mon Sep 17 00:00:00 2001 From: Stephen Roderick Date: Tue, 15 Sep 2009 19:38:01 -0400 Subject: [PATCH] Add functions to match Vector2 interface to Vector --- src/frames.hpp | 22 ++++++++++++++++++++++ src/frames.inl | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/src/frames.hpp b/src/frames.hpp index c52ce81..e632259 100644 --- a/src/frames.hpp +++ b/src/frames.hpp @@ -921,6 +921,23 @@ public: //! Access to elements, range checked when NDEBUG is not set, from 0..1 inline double& operator() (int index); + //! Equivalent to double operator()(int index) const + double operator[] ( int index ) const + { + return this->operator() ( index ); + } + + //! Equivalent to double& operator()(int index) + double& operator[] ( int index ) + { + return this->operator() ( index ); + } + + inline double x() const; + inline double y() const; + inline void x(double); + inline void y(double); + inline void ReverseSign(); inline Vector2& operator-=(const Vector2& arg); inline Vector2& operator +=(const Vector2& arg); @@ -967,6 +984,11 @@ public: //! different. It compares whether the 2 arguments are equal in an eps-interval inline friend bool Equal(const Vector2& a,const Vector2& b,double eps=epsilon); + //! The literal equality operator==(), also identical. + inline friend bool operator==(const Vector2& a,const Vector2& b); + //! The literal inequality operator!=(). + inline friend bool operator!=(const Vector2& a,const Vector2& b); + friend class Rotation2; }; diff --git a/src/frames.inl b/src/frames.inl index 87d3f1d..48101c1 100644 --- a/src/frames.inl +++ b/src/frames.inl @@ -783,6 +783,14 @@ IMETHOD double& Vector2::operator () (int index) FRAMES_CHECKI((0<=index)&&(index<=1)); return data[index]; } + +IMETHOD double Vector2::x() const { return data[0]; } +IMETHOD double Vector2::y() const { return data[1]; } + +IMETHOD void Vector2::x( double _x ) { data[0] = _x; } +IMETHOD void Vector2::y( double _y ) { data[1] = _y; } + + IMETHOD void Vector2::ReverseSign() { data[0] = -data[0]; @@ -1338,3 +1346,16 @@ IMETHOD bool operator!=(const Rotation& a,const Rotation& b) { return !operator==(a,b); } +IMETHOD bool operator==(const Vector2& a,const Vector2& b) { +#ifdef KDL_USE_EQUAL + return Equal(a,b); +#else + return (a.data[0]==b.data[0]&& + a.data[1]==b.data[1] ); +#endif + } + +IMETHOD bool operator!=(const Vector2& a,const Vector2& b) { + return !operator==(a,b); +} + -- 1.6.4.1