Vec2d
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_VEC2D
#define OSG_VEC2D 1
#include <osg/Vec2f>
namespace osg {
class Vec2d
{
public:
typedef double value_type;
enum { num_components = 2 };
value_type _v[2];
Vec2d() {_v[0]=0.0; _v[1]=0.0;}
Vec2d(value_type x,value_type y) { _v[0]=x; _v[1]=y; }
inline Vec2d(const Vec2f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; }
inline operator Vec2f() const { return Vec2f(static_cast<float>(_v[0]),static_cast<float>(_v[1]));}
inline bool operator == (const Vec2d& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Vec2d& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Vec2d& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else return (_v[1]<v._v[1]);
}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline void set( value_type x, value_type y ) { _v[0]=x; _v[1]=y; }
inline value_type& operator [] (int i) { return _v[i]; }
inline value_type operator [] (int i) const { return _v[i]; }
inline value_type& x() { return _v[0]; }
inline value_type& y() { return _v[1]; }
inline value_type x() const { return _v[0]; }
inline value_type y() const { return _v[1]; }
inline bool valid() const { return !isNaN(); }
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
inline value_type operator * (const Vec2d& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1];
}
inline const Vec2d operator * (value_type rhs) const
{
return Vec2d(_v[0]*rhs, _v[1]*rhs);
}
inline Vec2d& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
return *this;
}
inline const Vec2d operator / (value_type rhs) const
{
return Vec2d(_v[0]/rhs, _v[1]/rhs);
}
inline Vec2d& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
return *this;
}
inline const Vec2d operator + (const Vec2d& rhs) const
{
return Vec2d(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
inline Vec2d& operator += (const Vec2d& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
return *this;
}
inline const Vec2d operator - (const Vec2d& rhs) const
{
return Vec2d(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
inline Vec2d& operator -= (const Vec2d& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
return *this;
}
inline const Vec2d operator - () const
{
return Vec2d (-_v[0], -_v[1]);
}
inline value_type length() const
{
return sqrt( _v[0]*_v[0] + _v[1]*_v[1] );
}
inline value_type length2( void ) const
{
return _v[0]*_v[0] + _v[1]*_v[1];
}
inline value_type normalize()
{
value_type norm = Vec2d::length();
if (norm>0.0)
{
value_type inv = 1.0/norm;
_v[0] *= inv;
_v[1] *= inv;
}
return( norm );
}
}; // end of class Vec2d
inline Vec2d componentMultiply(const Vec2d& lhs, const Vec2d& rhs)
{
return Vec2d(lhs[0]*rhs[0], lhs[1]*rhs[1]);
}
inline Vec2d componentDivide(const Vec2d& lhs, const Vec2d& rhs)
{
return Vec2d(lhs[0]/rhs[0], lhs[1]/rhs[1]);
}
} // end of namespace osg
#endif
Vec2f
osg::Vec2d
Definition Vec2d:29
osg::Vec2d::isNaN
bool isNaN() const
Definition Vec2d:78
osg::Vec2d::operator/=
Vec2d & operator/=(value_type rhs)
Definition Vec2d:107
osg::Vec2d::length
value_type length() const
Definition Vec2d:151
osg::Vec2d::operator/
const Vec2d operator/(value_type rhs) const
Definition Vec2d:101
osg::Vec2d::operator!=
bool operator!=(const Vec2d &v) const
Definition Vec2d:52
osg::Vec2d::operator==
bool operator==(const Vec2d &v) const
Definition Vec2d:50
osg::Vec2d::num_components
@ num_components
Definition Vec2d:36
osg::Vec2d::ptr
value_type * ptr()
Definition Vec2d:61
osg::Vec2d::Vec2d
Vec2d(value_type x, value_type y)
Definition Vec2d:43
osg::Vec2d::Vec2d
Vec2d(const Vec2f &vec)
Definition Vec2d:45
osg::Vec2d::operator-
const Vec2d operator-() const
Definition Vec2d:145
osg::Vec2d::x
value_type x() const
Definition Vec2d:72
osg::Vec2d::operator[]
value_type & operator[](int i)
Definition Vec2d:66
osg::Vec2d::_v
value_type _v[2]
Definition Vec2d:38
osg::Vec2d::operator*
value_type operator*(const Vec2d &rhs) const
Definition Vec2d:81
osg::Vec2d::Vec2d
Vec2d()
Definition Vec2d:41
osg::Vec2d::operator-=
Vec2d & operator-=(const Vec2d &rhs)
Definition Vec2d:137
osg::Vec2d::operator<
bool operator<(const Vec2d &v) const
Definition Vec2d:54
osg::Vec2d::y
value_type & y()
Definition Vec2d:70
osg::Vec2d::y
value_type y() const
Definition Vec2d:73
osg::Vec2d::x
value_type & x()
Definition Vec2d:69
osg::Vec2d::operator*=
Vec2d & operator*=(value_type rhs)
Definition Vec2d:93
osg::Vec2d::valid
bool valid() const
Definition Vec2d:76
osg::Vec2d::operator+=
Vec2d & operator+=(const Vec2d &rhs)
Definition Vec2d:123
osg::Vec2d::length2
value_type length2(void) const
Definition Vec2d:157
osg::Vec2d::normalize
value_type normalize()
Definition Vec2d:165
osg::Vec2d::set
void set(value_type x, value_type y)
Definition Vec2d:64
osg::Vec2d::ptr
const value_type * ptr() const
Definition Vec2d:62
osg::Vec2d::value_type
double value_type
Definition Vec2d:33
osg::Vec2d::operator+
const Vec2d operator+(const Vec2d &rhs) const
Definition Vec2d:115
osg::Vec2f
Definition Vec2f:29
osg::Vec2f::_v
value_type _v[2]
Definition Vec2f:39
osg
Definition AlphaFunc:19
osg::componentDivide
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:187
osg::isNaN
bool isNaN(float v)
Definition Math:133
osg::componentMultiply
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:181