1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
23 /** Data type of vector components.*/
24 typedef unsigned short value_type;
26 /** Number of vector components. */
27 enum { num_components = 2 };
31 /** Constructor that sets all components of the vector to zero */
32 Vec2us() { _v[0]=0; _v[1]=0; }
34 Vec2us(value_type x, value_type y) { _v[0] = x; _v[1] = y; }
36 inline bool operator == (const Vec2us& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
37 inline bool operator != (const Vec2us& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
38 inline bool operator < (const Vec2us& v) const
40 if (_v[0]<v._v[0]) return true;
41 else if (_v[0]>v._v[0]) return false;
42 else return (_v[1]<v._v[1]);
45 inline value_type* ptr() { return _v; }
46 inline const value_type* ptr() const { return _v; }
48 inline void set( value_type x, value_type y)
53 inline void set( const Vec2us& rhs)
55 _v[0]=rhs._v[0]; _v[1]=rhs._v[1];
58 inline value_type& operator [] (int i) { return _v[i]; }
59 inline value_type operator [] (int i) const { return _v[i]; }
61 inline value_type& x() { return _v[0]; }
62 inline value_type& y() { return _v[1]; }
64 inline value_type x() const { return _v[0]; }
65 inline value_type y() const { return _v[1]; }
67 inline value_type& r() { return _v[0]; }
68 inline value_type& g() { return _v[1]; }
70 inline value_type r() const { return _v[0]; }
71 inline value_type g() const { return _v[1]; }
73 inline Vec2us operator * (value_type rhs) const
75 return Vec2us(_v[0]*rhs, _v[1]*rhs);
78 inline Vec2us& operator *= (value_type rhs)
85 inline Vec2us operator / (value_type rhs) const
87 return Vec2us(_v[0]/rhs, _v[1]/rhs);
90 inline Vec2us& operator /= (value_type rhs)
97 inline Vec2us operator + (const Vec2us& rhs) const
99 return Vec2us(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
102 inline Vec2us& operator += (const Vec2us& rhs)
109 inline Vec2us operator - (const Vec2us& rhs) const
111 return Vec2us(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
114 inline Vec2us& operator -= (const Vec2us& rhs)
121}; // end of class Vec2us
123/** multiply by vector components. */
124inline Vec2us componentMultiply(const Vec2us& lhs, const Vec2us& rhs)
126 return Vec2us(lhs[0]*rhs[0], lhs[1]*rhs[1]);
129/** divide rhs components by rhs vector components. */
130inline Vec2us componentDivide(const Vec2us& lhs, const Vec2us& rhs)
132 return Vec2us(lhs[0]/rhs[0], lhs[1]/rhs[1]);
135} // end of namespace osg