openscenegraph
Vec2ui
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSG_VEC2UI
15#define OSG_VEC2UI 1
16
17namespace osg {
18
19/** General purpose integer pair.
20*/
21class Vec2ui
22{
23 public:
24
25 /** Type of Vec class.*/
26 typedef unsigned int value_type;
27
28 /** Number of vector components. */
29 enum { num_components = 2 };
30
31 /** Vec member variable. */
32 value_type _v[2];
33
34 Vec2ui() { _v[0]=0; _v[1]=0; }
35
36 Vec2ui(value_type x, value_type y) { _v[0] = x; _v[1] = y; }
37
38 inline bool operator == (const Vec2ui& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
39 inline bool operator != (const Vec2ui& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
40 inline bool operator < (const Vec2ui& v) const
41 {
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]);
45 }
46
47 inline value_type* ptr() { return _v; }
48 inline const value_type* ptr() const { return _v; }
49
50 inline void set( value_type x, value_type y)
51 {
52 _v[0]=x; _v[1]=y;
53 }
54
55 inline void set( const Vec2ui& rhs)
56 {
57 _v[0]=rhs._v[0]; _v[1]=rhs._v[1];
58 }
59
60 inline value_type& operator [] (int i) { return _v[i]; }
61 inline value_type operator [] (int i) const { return _v[i]; }
62
63 inline value_type& x() { return _v[0]; }
64 inline value_type& y() { return _v[1]; }
65
66 inline value_type x() const { return _v[0]; }
67 inline value_type y() const { return _v[1]; }
68
69 inline value_type& r() { return _v[0]; }
70 inline value_type& g() { return _v[1]; }
71
72 inline value_type r() const { return _v[0]; }
73 inline value_type g() const { return _v[1]; }
74
75 inline Vec2ui operator * (value_type rhs) const
76 {
77 return Vec2ui(_v[0]*rhs, _v[1]*rhs);
78 }
79
80 inline Vec2ui operator / (value_type rhs) const
81 {
82 return Vec2ui(_v[0]/rhs, _v[1]/rhs);
83 }
84
85 inline Vec2ui operator + (value_type rhs) const
86 {
87 return Vec2ui(_v[0]+rhs, _v[1]+rhs);
88 }
89
90 inline Vec2ui operator - (value_type rhs) const
91 {
92 return Vec2ui(_v[0]-rhs, _v[1]-rhs);
93 }
94
95 inline Vec2ui operator + (const Vec2ui& rhs) const
96 {
97 return Vec2ui(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
98 }
99
100 inline Vec2ui operator - (const Vec2ui& rhs) const
101 {
102 return Vec2ui(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
103 }
104
105 inline Vec2ui operator * (const Vec2ui& rhs) const
106 {
107 return Vec2ui(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);
108 }
109
110};
111
112}
113
114#endif