All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vec4i.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 //
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_VEC4I_H
29 #define GF_VEC4I_H
30 
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 <boost/functional/hash.hpp>
41 
42 #include <cstddef>
43 
44 #include <iosfwd>
45 
46 PXR_NAMESPACE_OPEN_SCOPE
47 
48 class GfVec4i;
49 
50 template <>
51 struct GfIsGfVec<class GfVec4i> { static const bool value = true; };
52 
61 class GfVec4i
62 {
63 public:
65  typedef int ScalarType;
66  static const size_t dimension = 4;
67 
69  GfVec4i() = default;
70 
72  constexpr explicit GfVec4i(int value)
73  : _data{ value, value, value, value }
74  {
75  }
76 
78  constexpr GfVec4i(int s0, int s1, int s2, int s3)
79  : _data{ s0, s1, s2, s3 }
80  {
81  }
82 
84  template <class Scl>
85  constexpr explicit GfVec4i(Scl const *p)
86  : _data{ p[0], p[1], p[2], p[3] }
87  {
88  }
89 
91  static GfVec4i XAxis() {
92  GfVec4i result(0);
93  result[0] = 1;
94  return result;
95  }
97  static GfVec4i YAxis() {
98  GfVec4i result(0);
99  result[1] = 1;
100  return result;
101  }
103  static GfVec4i ZAxis() {
104  GfVec4i result(0);
105  result[2] = 1;
106  return result;
107  }
109  static GfVec4i WAxis() {
110  GfVec4i result(0);
111  result[3] = 1;
112  return result;
113  }
114 
117  static GfVec4i Axis(size_t i) {
118  GfVec4i result(0);
119  if (i < 4)
120  result[i] = 1;
121  return result;
122  }
123 
125  GfVec4i &Set(int s0, int s1, int s2, int s3) {
126  _data[0] = s0;
127  _data[1] = s1;
128  _data[2] = s2;
129  _data[3] = s3;
130  return *this;
131  }
132 
134  GfVec4i &Set(int const *a) {
135  return Set(a[0], a[1], a[2], a[3]);
136  }
137 
139  int const *data() const { return _data; }
140  int *data() { return _data; }
141  int const *GetArray() const { return data(); }
142 
144  int const &operator[](size_t i) const { return _data[i]; }
145  int &operator[](size_t i) { return _data[i]; }
146 
148  friend inline size_t hash_value(GfVec4i const &vec) {
149  size_t h = 0;
150  boost::hash_combine(h, vec[0]);
151  boost::hash_combine(h, vec[1]);
152  boost::hash_combine(h, vec[2]);
153  boost::hash_combine(h, vec[3]);
154  return h;
155  }
156 
158  bool operator==(GfVec4i const &other) const {
159  return _data[0] == other[0] &&
160  _data[1] == other[1] &&
161  _data[2] == other[2] &&
162  _data[3] == other[3];
163  }
164  bool operator!=(GfVec4i const &other) const {
165  return !(*this == other);
166  }
167 
168  // TODO Add inequality for other vec types...
170  GF_API
171  bool operator==(class GfVec4d const &other) const;
173  GF_API
174  bool operator==(class GfVec4f const &other) const;
176  GF_API
177  bool operator==(class GfVec4h const &other) const;
178 
180  GfVec4i operator-() const {
181  return GfVec4i(-_data[0], -_data[1], -_data[2], -_data[3]);
182  }
183 
185  GfVec4i &operator+=(GfVec4i const &other) {
186  _data[0] += other[0];
187  _data[1] += other[1];
188  _data[2] += other[2];
189  _data[3] += other[3];
190  return *this;
191  }
192  friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r) {
193  return GfVec4i(l) += r;
194  }
195 
197  GfVec4i &operator-=(GfVec4i const &other) {
198  _data[0] -= other[0];
199  _data[1] -= other[1];
200  _data[2] -= other[2];
201  _data[3] -= other[3];
202  return *this;
203  }
204  friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r) {
205  return GfVec4i(l) -= r;
206  }
207 
209  GfVec4i &operator*=(double s) {
210  _data[0] *= s;
211  _data[1] *= s;
212  _data[2] *= s;
213  _data[3] *= s;
214  return *this;
215  }
216  GfVec4i operator*(double s) const {
217  return GfVec4i(*this) *= s;
218  }
219  friend GfVec4i operator*(double s, GfVec4i const &v) {
220  return v * s;
221  }
222 
224  GfVec4i &operator/=(int s) {
225  _data[0] /= s;
226  _data[1] /= s;
227  _data[2] /= s;
228  _data[3] /= s;
229  return *this;
230  }
231  GfVec4i operator/(int s) const {
232  return GfVec4i(*this) /= s;
233  }
234 
236  int operator*(GfVec4i const &v) const {
237  return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
238  }
239 
244  GfVec4i GetProjection(GfVec4i const &v) const {
245  return v * (*this * v);
246  }
247 
253  GfVec4i GetComplement(GfVec4i const &b) const {
254  return *this - this->GetProjection(b);
255  }
256 
258  int GetLengthSq() const {
259  return *this * *this;
260  }
261 
262 
263 private:
264  int _data[4];
265 };
266 
269 GF_API std::ostream& operator<<(std::ostream &, GfVec4i const &);
270 
271 
273 inline GfVec4i
274 GfCompMult(GfVec4i const &v1, GfVec4i const &v2) {
275  return GfVec4i(
276  v1[0] * v2[0],
277  v1[1] * v2[1],
278  v1[2] * v2[2],
279  v1[3] * v2[3]
280  );
281 }
282 
284 inline GfVec4i
285 GfCompDiv(GfVec4i const &v1, GfVec4i const &v2) {
286  return GfVec4i(
287  v1[0] / v2[0],
288  v1[1] / v2[1],
289  v1[2] / v2[2],
290  v1[3] / v2[3]
291  );
292 }
293 
295 inline int
296 GfDot(GfVec4i const &v1, GfVec4i const &v2) {
297  return v1 * v2;
298 }
299 
300 
301 PXR_NAMESPACE_CLOSE_SCOPE
302 
303 #endif // GF_VEC4I_H
static GfVec4i WAxis()
Create a unit vector along the W-axis.
Definition: vec4i.h:109
Basic type for a vector of 4 int components.
Definition: vec4i.h:61
constexpr GfVec4i(int value)
Initialize all elements to a single value.
Definition: vec4i.h:72
friend size_t hash_value(GfVec4i const &vec)
Hash.
Definition: vec4i.h:148
constexpr GfVec4i(Scl const *p)
Construct with pointer to values.
Definition: vec4i.h:85
GfVec4i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec4i.h:134
static GfVec4i YAxis()
Create a unit vector along the Y-axis.
Definition: vec4i.h:97
GfVec4i & operator+=(GfVec4i const &other)
Addition.
Definition: vec4i.h:185
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
constexpr GfVec4i(int s0, int s1, int s2, int s3)
Initialize all elements with explicit arguments.
Definition: vec4i.h:78
A metafunction with a static const bool member &#39;value&#39; that is true for GfVec types, like GfVec2i, GfVec4d, etc and false for all other types.
Definition: traits.h:34
Basic type for a vector of 4 GfHalf components.
Definition: vec4h.h:64
static GfVec4i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec4i.h:103
GfVec4i()=default
Default constructor does no initialization.
GfVec4i & operator-=(GfVec4i const &other)
Subtraction.
Definition: vec4i.h:197
GfVec4i & operator*=(double s)
Multiplication by scalar.
Definition: vec4i.h:209
GfVec2d GfCompMult(GfVec2d const &v1, GfVec2d const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec2d.h:316
static GfVec4i XAxis()
Create a unit vector along the X-axis.
Definition: vec4i.h:91
static GfVec4i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec4i.h:117
int ScalarType
Scalar element type and dimension.
Definition: vec4i.h:65
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
int const * data() const
Direct data access.
Definition: vec4i.h:139
int GetLengthSq() const
Squared length.
Definition: vec4i.h:258
GfVec4i & operator/=(int s)
Division by scalar.
Definition: vec4i.h:224
GfVec4i GetComplement(GfVec4i const &b) const
Returns the orthogonal complement of this-&gt;GetProjection(b).
Definition: vec4i.h:253
bool operator==(GfVec4i const &other) const
Equality comparison.
Definition: vec4i.h:158
GfVec2d GfCompDiv(GfVec2d const &v1, GfVec2d const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec2d.h:325
GfVec4i operator-() const
Create a vec with negated elements.
Definition: vec4i.h:180
int operator*(GfVec4i const &v) const
See GfDot().
Definition: vec4i.h:236
GfVec4i GetProjection(GfVec4i const &v) const
Returns the projection of this onto v.
Definition: vec4i.h:244
int const & operator[](size_t i) const
Indexing.
Definition: vec4i.h:144
GfVec4i & Set(int s0, int s1, int s2, int s3)
Set all elements with passed arguments.
Definition: vec4i.h:125
GfHalf GfDot(GfHalf a, GfHalf b)
Returns the dot (inner) product of two vectors.
Definition: half.h:55