HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vec2i.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 // This file is generated by a script. Do not edit directly. Edit the
26 // vec.template.h file to make changes.
27 
28 #ifndef GF_VEC2I_H
29 #define GF_VEC2I_H
30 
31 /// \file gf/vec2i.h
32 /// \ingroup group_gf_LinearAlgebra
33 
34 #include "pxr/pxr.h"
35 #include "pxr/base/tf/diagnostic.h"
36 #include "pxr/base/gf/api.h"
37 #include "pxr/base/gf/limits.h"
38 #include "pxr/base/gf/traits.h"
39 
40 #include <hboost/functional/hash.hpp>
41 
42 #include <cstddef>
43 
44 #include <iosfwd>
45 
47 
48 class GfVec2i;
49 
50 template <>
51 struct GfIsGfVec<class GfVec2i> { static const bool value = true; };
52 
53 /// \class GfVec2i
54 /// \ingroup group_gf_LinearAlgebra
55 ///
56 /// Basic type for a vector of 2 int components.
57 ///
58 /// Represents a vector of 2 components of type \c int.
59 /// It is intended to be fast and simple.
60 ///
61 class GfVec2i
62 {
63 public:
64  /// Scalar element type and dimension.
65  typedef int ScalarType;
66  static const size_t dimension = 2;
67 
68  /// Default constructor does no initialization.
69  GfVec2i() = default;
70 
71  /// Initialize all elements to a single value.
72  constexpr explicit GfVec2i(int value)
73  : _data{ value, value }
74  {
75  }
76 
77  /// Initialize all elements with explicit arguments.
78  constexpr GfVec2i(int s0, int s1)
79  : _data{ s0, s1 }
80  {
81  }
82 
83  /// Construct with pointer to values.
84  template <class Scl>
85  constexpr explicit GfVec2i(Scl const *p)
86  : _data{ p[0], p[1] }
87  {
88  }
89 
90  /// Create a unit vector along the X-axis.
91  static GfVec2i XAxis() {
92  GfVec2i result(0);
93  result[0] = 1;
94  return result;
95  }
96  /// Create a unit vector along the Y-axis.
97  static GfVec2i YAxis() {
98  GfVec2i result(0);
99  result[1] = 1;
100  return result;
101  }
102 
103  /// Create a unit vector along the i-th axis, zero-based. Return the zero
104  /// vector if \p i is greater than or equal to 2.
105  static GfVec2i Axis(size_t i) {
106  GfVec2i result(0);
107  if (i < 2)
108  result[i] = 1;
109  return result;
110  }
111 
112  /// Set all elements with passed arguments.
113  GfVec2i &Set(int s0, int s1) {
114  _data[0] = s0;
115  _data[1] = s1;
116  return *this;
117  }
118 
119  /// Set all elements with a pointer to data.
120  GfVec2i &Set(int const *a) {
121  return Set(a[0], a[1]);
122  }
123 
124  /// Direct data access.
125  int const *data() const { return _data; }
126  int *data() { return _data; }
127  int const *GetArray() const { return data(); }
128 
129  /// Indexing.
130  int const &operator[](size_t i) const { return _data[i]; }
131  int &operator[](size_t i) { return _data[i]; }
132 
133  /// Hash.
134  friend inline size_t hash_value(GfVec2i const &vec) {
135  size_t h = 0;
136  hboost::hash_combine(h, vec[0]);
137  hboost::hash_combine(h, vec[1]);
138  return h;
139  }
140 
141  /// Equality comparison.
142  bool operator==(GfVec2i const &other) const {
143  return _data[0] == other[0] &&
144  _data[1] == other[1];
145  }
146  bool operator!=(GfVec2i const &other) const {
147  return !(*this == other);
148  }
149 
150  // TODO Add inequality for other vec types...
151  /// Equality comparison.
152  GF_API
153  bool operator==(class GfVec2d const &other) const;
154  /// Equality comparison.
155  GF_API
156  bool operator==(class GfVec2f const &other) const;
157  /// Equality comparison.
158  GF_API
159  bool operator==(class GfVec2h const &other) const;
160 
161  /// Create a vec with negated elements.
162  GfVec2i operator-() const {
163  return GfVec2i(-_data[0], -_data[1]);
164  }
165 
166  /// Addition.
167  GfVec2i &operator+=(GfVec2i const &other) {
168  _data[0] += other[0];
169  _data[1] += other[1];
170  return *this;
171  }
172  friend GfVec2i operator+(GfVec2i const &l, GfVec2i const &r) {
173  return GfVec2i(l) += r;
174  }
175 
176  /// Subtraction.
177  GfVec2i &operator-=(GfVec2i const &other) {
178  _data[0] -= other[0];
179  _data[1] -= other[1];
180  return *this;
181  }
182  friend GfVec2i operator-(GfVec2i const &l, GfVec2i const &r) {
183  return GfVec2i(l) -= r;
184  }
185 
186  /// Multiplication by scalar.
187  GfVec2i &operator*=(double s) {
188  _data[0] *= s;
189  _data[1] *= s;
190  return *this;
191  }
192  GfVec2i operator*(double s) const {
193  return GfVec2i(*this) *= s;
194  }
195  friend GfVec2i operator*(double s, GfVec2i const &v) {
196  return v * s;
197  }
198 
199  /// Division by scalar.
201  _data[0] /= s;
202  _data[1] /= s;
203  return *this;
204  }
205  GfVec2i operator/(int s) const {
206  return GfVec2i(*this) /= s;
207  }
208 
209  /// See GfDot().
210  int operator*(GfVec2i const &v) const {
211  return _data[0] * v[0] + _data[1] * v[1];
212  }
213 
214  /// Returns the projection of \p this onto \p v. That is:
215  /// \code
216  /// v * (*this * v)
217  /// \endcode
218  GfVec2i GetProjection(GfVec2i const &v) const {
219  return v * (*this * v);
220  }
221 
222  /// Returns the orthogonal complement of \p this->GetProjection(b).
223  /// That is:
224  /// \code
225  /// *this - this->GetProjection(b)
226  /// \endcode
227  GfVec2i GetComplement(GfVec2i const &b) const {
228  return *this - this->GetProjection(b);
229  }
230 
231  /// Squared length.
232  int GetLengthSq() const {
233  return *this * *this;
234  }
235 
236 
237 private:
238  int _data[2];
239 };
240 
241 /// Output a GfVec2i.
242 /// \ingroup group_gf_DebuggingOutput
243 GF_API std::ostream& operator<<(std::ostream &, GfVec2i const &);
244 
245 
246 /// Returns component-wise multiplication of vectors \p v1 and \p v2.
247 inline GfVec2i
248 GfCompMult(GfVec2i const &v1, GfVec2i const &v2) {
249  return GfVec2i(
250  v1[0] * v2[0],
251  v1[1] * v2[1]
252  );
253 }
254 
255 /// Returns component-wise quotient of vectors \p v1 and \p v2.
256 inline GfVec2i
257 GfCompDiv(GfVec2i const &v1, GfVec2i const &v2) {
258  return GfVec2i(
259  v1[0] / v2[0],
260  v1[1] / v2[1]
261  );
262 }
263 
264 /// Returns the dot (inner) product of two vectors.
265 inline int
266 GfDot(GfVec2i const &v1, GfVec2i const &v2) {
267  return v1 * v2;
268 }
269 
270 
272 
273 #endif // GF_VEC2I_H
GLdouble s
Definition: glew.h:1390
int const & operator[](size_t i) const
Indexing.
Definition: vec2i.h:130
friend GfVec2i operator+(GfVec2i const &l, GfVec2i const &r)
Definition: vec2i.h:172
GfVec2i GetProjection(GfVec2i const &v) const
Definition: vec2i.h:218
bool operator!=(GfVec2i const &other) const
Definition: vec2i.h:146
friend GfVec2i operator*(double s, GfVec2i const &v)
Definition: vec2i.h:195
Definition: vec2i.h:61
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:643
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
GfVec2i()=default
Default constructor does no initialization.
int const * GetArray() const
Definition: vec2i.h:127
GLdouble l
Definition: glew.h:9122
const GLdouble * v
Definition: glew.h:1391
GF_API std::ostream & operator<<(std::ostream &, GfVec2i const &)
Definition: vec2d.h:63
bool operator==(GfVec2i const &other) const
Equality comparison.
Definition: vec2i.h:142
GfVec2i & operator*=(double s)
Multiplication by scalar.
Definition: vec2i.h:187
GLfloat GLfloat GLfloat v2
Definition: glew.h:1856
static GfVec2i XAxis()
Create a unit vector along the X-axis.
Definition: vec2i.h:91
int GetLengthSq() const
Squared length.
Definition: vec2i.h:232
GfVec2i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec2i.h:120
GfVec2i operator-() const
Create a vec with negated elements.
Definition: vec2i.h:162
GfVec2i operator/(int s) const
Definition: vec2i.h:205
Definition: vec2h.h:64
int GfDot(GfVec2i const &v1, GfVec2i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec2i.h:266
GfVec2i GfCompMult(GfVec2i const &v1, GfVec2i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec2i.h:248
friend GfVec2i operator-(GfVec2i const &l, GfVec2i const &r)
Definition: vec2i.h:182
int const * data() const
Direct data access.
Definition: vec2i.h:125
GfVec2i & operator+=(GfVec2i const &other)
Addition.
Definition: vec2i.h:167
static GfVec2i Axis(size_t i)
Definition: vec2i.h:105
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
friend size_t hash_value(GfVec2i const &vec)
Hash.
Definition: vec2i.h:134
int ScalarType
Scalar element type and dimension.
Definition: vec2i.h:65
int operator*(GfVec2i const &v) const
See GfDot().
Definition: vec2i.h:210
GfVec2i & Set(int s0, int s1)
Set all elements with passed arguments.
Definition: vec2i.h:113
int * data()
Definition: vec2i.h:126
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
GfVec2i & operator/=(int s)
Division by scalar.
Definition: vec2i.h:200
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1245
static GfVec2i YAxis()
Create a unit vector along the Y-axis.
Definition: vec2i.h:97
GfVec2i GfCompDiv(GfVec2i const &v1, GfVec2i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec2i.h:257
Definition: vec2f.h:63
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition: glew.h:12681
int & operator[](size_t i)
Definition: vec2i.h:131
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
constexpr GfVec2i(int value)
Initialize all elements to a single value.
Definition: vec2i.h:72
GfVec2i GetComplement(GfVec2i const &b) const
Definition: vec2i.h:227
GLuint64EXT * result
Definition: glew.h:14007
constexpr GfVec2i(Scl const *p)
Construct with pointer to values.
Definition: vec2i.h:85
GfVec2i & operator-=(GfVec2i const &other)
Subtraction.
Definition: vec2i.h:177
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s0
Definition: glew.h:12681
GLsizei const GLfloat * value
Definition: glew.h:1849
GLfloat GLfloat v1
Definition: glew.h:1852
GfVec2i operator*(double s) const
Definition: vec2i.h:192
#define GF_API
Definition: api.h:40
static const size_t dimension
Definition: vec2i.h:66
constexpr GfVec2i(int s0, int s1)
Initialize all elements with explicit arguments.
Definition: vec2i.h:78