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.
19/** General purpose integer pair.
25 /** Type of Vec class.*/
26 typedef int value_type;
28 /** Number of vector components. */
29 enum { num_components = 2 };
31 /** Vec member variable. */
34 Vec2i() { _v[0]=0; _v[1]=0; }
36 Vec2i(value_type x, value_type y) { _v[0] = x; _v[1] = y; }
38 inline bool operator == (const Vec2i& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
39 inline bool operator != (const Vec2i& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
40 inline bool operator < (const Vec2i& v) const
42 if (_v[0]<v._v[0]) return true;
43 else if (_v[0]>v._v[0]) return false;
44 else return (_v[1]<v._v[1]);
47 inline value_type* ptr() { return _v; }
48 inline const value_type* ptr() const { return _v; }
50 inline void set( value_type x, value_type y)
55 inline void set( const Vec2i& rhs)
57 _v[0]=rhs._v[0]; _v[1]=rhs._v[1];
60 inline value_type& operator [] (int i) { return _v[i]; }
61 inline value_type operator [] (int i) const { return _v[i]; }
63 inline value_type& x() { return _v[0]; }
64 inline value_type& y() { return _v[1]; }
66 inline value_type x() const { return _v[0]; }
67 inline value_type y() const { return _v[1]; }
69 inline value_type& r() { return _v[0]; }
70 inline value_type& g() { return _v[1]; }
72 inline value_type r() const { return _v[0]; }
73 inline value_type g() const { return _v[1]; }
75 inline Vec2i operator * (value_type rhs) const
77 return Vec2i(_v[0]*rhs, _v[1]*rhs);
80 inline Vec2i operator / (value_type rhs) const
82 return Vec2i(_v[0]/rhs, _v[1]/rhs);
85 inline Vec2i operator + (value_type rhs) const
87 return Vec2i(_v[0]+rhs, _v[1]+rhs);
90 inline Vec2i operator - (value_type rhs) const
92 return Vec2i(_v[0]-rhs, _v[1]-rhs);
95 inline Vec2i operator + (const Vec2i& rhs) const
97 return Vec2i(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
100 inline Vec2i operator - (const Vec2i& rhs) const
102 return Vec2i(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
105 inline Vec2i operator * (const Vec2i& rhs) const
107 return Vec2i(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);