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