HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vec3i.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 ////////////////////////////////////////////////////////////////////////
8 // This file is generated by a script. Do not edit directly. Edit the
9 // vec.template.h file to make changes.
10 
11 #ifndef PXR_BASE_GF_VEC3I_H
12 #define PXR_BASE_GF_VEC3I_H
13 
14 /// \file gf/vec3i.h
15 /// \ingroup group_gf_LinearAlgebra
16 
17 #include "pxr/pxr.h"
18 #include "pxr/base/tf/diagnostic.h"
19 #include "pxr/base/gf/api.h"
20 #include "pxr/base/gf/limits.h"
21 #include "pxr/base/gf/traits.h"
22 #include "pxr/base/tf/hash.h"
23 
24 #include <cstddef>
25 
26 #include <iosfwd>
27 
29 
30 class GfVec3i;
31 
32 template <>
33 struct GfIsGfVec<class GfVec3i> { static const bool value = true; };
34 
35 /// \class GfVec3i
36 /// \ingroup group_gf_LinearAlgebra
37 ///
38 /// Basic type for a vector of 3 int components.
39 ///
40 /// Represents a vector of 3 components of type \c int.
41 /// It is intended to be fast and simple.
42 ///
43 class GfVec3i
44 {
45 public:
46  /// Scalar element type and dimension.
47  typedef int ScalarType;
48  static const size_t dimension = 3;
49 
50  /// Default constructor does no initialization.
51  GfVec3i() = default;
52 
53  /// Initialize all elements to a single value.
54  constexpr explicit GfVec3i(int value)
55  : _data{ value, value, value }
56  {
57  }
58 
59  /// Initialize all elements with explicit arguments.
60  constexpr GfVec3i(int s0, int s1, int s2)
61  : _data{ s0, s1, s2 }
62  {
63  }
64 
65  /// Construct with pointer to values.
66  template <class Scl>
67  constexpr explicit GfVec3i(Scl const *p)
68  : _data{ p[0], p[1], p[2] }
69  {
70  }
71 
72  /// Create a unit vector along the X-axis.
73  static GfVec3i XAxis() {
74  GfVec3i result(0);
75  result[0] = 1;
76  return result;
77  }
78  /// Create a unit vector along the Y-axis.
79  static GfVec3i YAxis() {
80  GfVec3i result(0);
81  result[1] = 1;
82  return result;
83  }
84  /// Create a unit vector along the Z-axis.
85  static GfVec3i ZAxis() {
86  GfVec3i result(0);
87  result[2] = 1;
88  return result;
89  }
90 
91  /// Create a unit vector along the i-th axis, zero-based. Return the zero
92  /// vector if \p i is greater than or equal to 3.
93  static GfVec3i Axis(size_t i) {
94  GfVec3i result(0);
95  if (i < 3)
96  result[i] = 1;
97  return result;
98  }
99 
100  /// Set all elements with passed arguments.
101  GfVec3i &Set(int s0, int s1, int s2) {
102  _data[0] = s0;
103  _data[1] = s1;
104  _data[2] = s2;
105  return *this;
106  }
107 
108  /// Set all elements with a pointer to data.
109  GfVec3i &Set(int const *a) {
110  return Set(a[0], a[1], a[2]);
111  }
112 
113  /// Direct data access.
114  int const *data() const { return _data; }
115  int *data() { return _data; }
116  int const *GetArray() const { return data(); }
117 
118  /// Indexing.
119  int const &operator[](size_t i) const { return _data[i]; }
120  int &operator[](size_t i) { return _data[i]; }
121 
122  /// Hash.
123  friend inline size_t hash_value(GfVec3i const &vec) {
124  return TfHash::Combine(vec[0], vec[1], vec[2]);
125  }
126 
127  /// Equality comparison.
128  bool operator==(GfVec3i const &other) const {
129  return _data[0] == other[0] &&
130  _data[1] == other[1] &&
131  _data[2] == other[2];
132  }
133  bool operator!=(GfVec3i const &other) const {
134  return !(*this == other);
135  }
136 
137  // TODO Add inequality for other vec types...
138  /// Equality comparison.
139  GF_API
140  bool operator==(class GfVec3d const &other) const;
141  /// Equality comparison.
142  GF_API
143  bool operator==(class GfVec3f const &other) const;
144  /// Equality comparison.
145  GF_API
146  bool operator==(class GfVec3h const &other) const;
147 
148  /// Create a vec with negated elements.
149  GfVec3i operator-() const {
150  return GfVec3i(-_data[0], -_data[1], -_data[2]);
151  }
152 
153  /// Addition.
154  GfVec3i &operator+=(GfVec3i const &other) {
155  _data[0] += other[0];
156  _data[1] += other[1];
157  _data[2] += other[2];
158  return *this;
159  }
160  friend GfVec3i operator+(GfVec3i const &l, GfVec3i const &r) {
161  return GfVec3i(l) += r;
162  }
163 
164  /// Subtraction.
165  GfVec3i &operator-=(GfVec3i const &other) {
166  _data[0] -= other[0];
167  _data[1] -= other[1];
168  _data[2] -= other[2];
169  return *this;
170  }
171  friend GfVec3i operator-(GfVec3i const &l, GfVec3i const &r) {
172  return GfVec3i(l) -= r;
173  }
174 
175  /// Multiplication by scalar.
176  GfVec3i &operator*=(double s) {
177  _data[0] *= s;
178  _data[1] *= s;
179  _data[2] *= s;
180  return *this;
181  }
182  GfVec3i operator*(double s) const {
183  return GfVec3i(*this) *= s;
184  }
185  friend GfVec3i operator*(double s, GfVec3i const &v) {
186  return v * s;
187  }
188 
189  /// Division by scalar.
191  _data[0] /= s;
192  _data[1] /= s;
193  _data[2] /= s;
194  return *this;
195  }
196  GfVec3i operator/(int s) const {
197  return GfVec3i(*this) /= s;
198  }
199 
200  /// See GfDot().
201  int operator*(GfVec3i const &v) const {
202  return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
203  }
204 
205  /// Returns the projection of \p this onto \p v. That is:
206  /// \code
207  /// v * (*this * v)
208  /// \endcode
209  GfVec3i GetProjection(GfVec3i const &v) const {
210  return v * (*this * v);
211  }
212 
213  /// Returns the orthogonal complement of \p this->GetProjection(b).
214  /// That is:
215  /// \code
216  /// *this - this->GetProjection(b)
217  /// \endcode
218  GfVec3i GetComplement(GfVec3i const &b) const {
219  return *this - this->GetProjection(b);
220  }
221 
222  /// Squared length.
223  int GetLengthSq() const {
224  return *this * *this;
225  }
226 
227 
228 private:
229  int _data[3];
230 };
231 
232 /// Output a GfVec3i.
233 /// \ingroup group_gf_DebuggingOutput
234 GF_API std::ostream& operator<<(std::ostream &, GfVec3i const &);
235 
236 
237 /// Returns component-wise multiplication of vectors \p v1 and \p v2.
238 inline GfVec3i
239 GfCompMult(GfVec3i const &v1, GfVec3i const &v2) {
240  return GfVec3i(
241  v1[0] * v2[0],
242  v1[1] * v2[1],
243  v1[2] * v2[2]
244  );
245 }
246 
247 /// Returns component-wise quotient of vectors \p v1 and \p v2.
248 inline GfVec3i
249 GfCompDiv(GfVec3i const &v1, GfVec3i const &v2) {
250  return GfVec3i(
251  v1[0] / v2[0],
252  v1[1] / v2[1],
253  v1[2] / v2[2]
254  );
255 }
256 
257 /// Returns the dot (inner) product of two vectors.
258 inline int
259 GfDot(GfVec3i const &v1, GfVec3i const &v2) {
260  return v1 * v2;
261 }
262 
263 
265 
266 #endif // PXR_BASE_GF_VEC3I_H
GfVec3i & operator/=(int s)
Division by scalar.
Definition: vec3i.h:190
static GfVec3i YAxis()
Create a unit vector along the Y-axis.
Definition: vec3i.h:79
int GetLengthSq() const
Squared length.
Definition: vec3i.h:223
constexpr GfVec3i(int s0, int s1, int s2)
Initialize all elements with explicit arguments.
Definition: vec3i.h:60
static GfVec3i Axis(size_t i)
Definition: vec3i.h:93
*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:632
int * data()
Definition: vec3i.h:115
friend size_t hash_value(GfVec3i const &vec)
Hash.
Definition: vec3i.h:123
GfVec3i & Set(int s0, int s1, int s2)
Set all elements with passed arguments.
Definition: vec3i.h:101
const GLdouble * v
Definition: glcorearb.h:837
static GfVec3i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec3i.h:85
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GfVec3i & operator-=(GfVec3i const &other)
Subtraction.
Definition: vec3i.h:165
Definition: vec3f.h:45
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
int & operator[](size_t i)
Definition: vec3i.h:120
**But if you need a result
Definition: thread.h:622
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
GfVec3i GetComplement(GfVec3i const &b) const
Definition: vec3i.h:218
constexpr GfVec3i(int value)
Initialize all elements to a single value.
Definition: vec3i.h:54
GfVec3i GfCompMult(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec3i.h:239
bool operator!=(GfVec3i const &other) const
Definition: vec3i.h:133
GfVec3i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec3i.h:109
int ScalarType
Scalar element type and dimension.
Definition: vec3i.h:47
int operator*(GfVec3i const &v) const
See GfDot().
Definition: vec3i.h:201
static GfVec3i XAxis()
Create a unit vector along the X-axis.
Definition: vec3i.h:73
int const * data() const
Direct data access.
Definition: vec3i.h:114
GfVec3i & operator*=(double s)
Multiplication by scalar.
Definition: vec3i.h:176
GfVec3i GfCompDiv(GfVec3i const &v1, GfVec3i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec3i.h:249
Definition: vec3i.h:43
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GF_API std::ostream & operator<<(std::ostream &, GfVec3i const &)
GfVec3i()=default
Default constructor does no initialization.
static const size_t dimension
Definition: vec3i.h:48
friend GfVec3i operator-(GfVec3i const &l, GfVec3i const &r)
Definition: vec3i.h:171
GfVec3i operator*(double s) const
Definition: vec3i.h:182
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
friend GfVec3i operator*(double s, GfVec3i const &v)
Definition: vec3i.h:185
GfVec3i operator-() const
Create a vec with negated elements.
Definition: vec3i.h:149
Definition: vec3d.h:45
GLfloat GLfloat v1
Definition: glcorearb.h:817
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
int GfDot(GfVec3i const &v1, GfVec3i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec3i.h:259
bool operator==(GfVec3i const &other) const
Equality comparison.
Definition: vec3i.h:128
GLboolean r
Definition: glcorearb.h:1222
constexpr GfVec3i(Scl const *p)
Construct with pointer to values.
Definition: vec3i.h:67
friend GfVec3i operator+(GfVec3i const &l, GfVec3i const &r)
Definition: vec3i.h:160
Definition: vec3h.h:46
GfVec3i GetProjection(GfVec3i const &v) const
Definition: vec3i.h:209
GfVec3i & operator+=(GfVec3i const &other)
Addition.
Definition: vec3i.h:154
int const * GetArray() const
Definition: vec3i.h:116
#define GF_API
Definition: api.h:23
int const & operator[](size_t i) const
Indexing.
Definition: vec3i.h:119
GfVec3i operator/(int s) const
Definition: vec3i.h:196