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 //
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 
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 GfVec3i;
49 
50 template <>
51 struct GfIsGfVec<class GfVec3i> { static const bool value = true; };
52 
61 class GfVec3i
62 {
63 public:
65  typedef int ScalarType;
66  static const size_t dimension = 3;
67 
69  GfVec3i() = default;
70 
72  constexpr explicit GfVec3i(int value)
73  : _data{ value, value, value }
74  {
75  }
76 
78  constexpr GfVec3i(int s0, int s1, int s2)
79  : _data{ s0, s1, s2 }
80  {
81  }
82 
84  template <class Scl>
85  constexpr explicit GfVec3i(Scl const *p)
86  : _data{ p[0], p[1], p[2] }
87  {
88  }
89 
91  static GfVec3i XAxis() {
92  GfVec3i result(0);
93  result[0] = 1;
94  return result;
95  }
97  static GfVec3i YAxis() {
98  GfVec3i result(0);
99  result[1] = 1;
100  return result;
101  }
103  static GfVec3i ZAxis() {
104  GfVec3i result(0);
105  result[2] = 1;
106  return result;
107  }
108 
111  static GfVec3i Axis(size_t i) {
112  GfVec3i result(0);
113  if (i < 3)
114  result[i] = 1;
115  return result;
116  }
117 
119  GfVec3i &Set(int s0, int s1, int s2) {
120  _data[0] = s0;
121  _data[1] = s1;
122  _data[2] = s2;
123  return *this;
124  }
125 
127  GfVec3i &Set(int const *a) {
128  return Set(a[0], a[1], a[2]);
129  }
130 
132  int const *data() const { return _data; }
133  int *data() { return _data; }
134  int const *GetArray() const { return data(); }
135 
137  int const &operator[](size_t i) const { return _data[i]; }
138  int &operator[](size_t i) { return _data[i]; }
139 
141  friend inline size_t hash_value(GfVec3i const &vec) {
142  size_t h = 0;
143  boost::hash_combine(h, vec[0]);
144  boost::hash_combine(h, vec[1]);
145  boost::hash_combine(h, vec[2]);
146  return h;
147  }
148 
150  bool operator==(GfVec3i const &other) const {
151  return _data[0] == other[0] &&
152  _data[1] == other[1] &&
153  _data[2] == other[2];
154  }
155  bool operator!=(GfVec3i const &other) const {
156  return !(*this == other);
157  }
158 
159  // TODO Add inequality for other vec types...
161  GF_API
162  bool operator==(class GfVec3d const &other) const;
164  GF_API
165  bool operator==(class GfVec3f const &other) const;
167  GF_API
168  bool operator==(class GfVec3h const &other) const;
169 
171  GfVec3i operator-() const {
172  return GfVec3i(-_data[0], -_data[1], -_data[2]);
173  }
174 
176  GfVec3i &operator+=(GfVec3i const &other) {
177  _data[0] += other[0];
178  _data[1] += other[1];
179  _data[2] += other[2];
180  return *this;
181  }
182  friend GfVec3i operator+(GfVec3i const &l, GfVec3i const &r) {
183  return GfVec3i(l) += r;
184  }
185 
187  GfVec3i &operator-=(GfVec3i const &other) {
188  _data[0] -= other[0];
189  _data[1] -= other[1];
190  _data[2] -= other[2];
191  return *this;
192  }
193  friend GfVec3i operator-(GfVec3i const &l, GfVec3i const &r) {
194  return GfVec3i(l) -= r;
195  }
196 
198  GfVec3i &operator*=(double s) {
199  _data[0] *= s;
200  _data[1] *= s;
201  _data[2] *= s;
202  return *this;
203  }
204  GfVec3i operator*(double s) const {
205  return GfVec3i(*this) *= s;
206  }
207  friend GfVec3i operator*(double s, GfVec3i const &v) {
208  return v * s;
209  }
210 
212  GfVec3i &operator/=(int s) {
213  _data[0] /= s;
214  _data[1] /= s;
215  _data[2] /= s;
216  return *this;
217  }
218  GfVec3i operator/(int s) const {
219  return GfVec3i(*this) /= s;
220  }
221 
223  int operator*(GfVec3i const &v) const {
224  return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
225  }
226 
231  GfVec3i GetProjection(GfVec3i const &v) const {
232  return v * (*this * v);
233  }
234 
240  GfVec3i GetComplement(GfVec3i const &b) const {
241  return *this - this->GetProjection(b);
242  }
243 
245  int GetLengthSq() const {
246  return *this * *this;
247  }
248 
249 
250 private:
251  int _data[3];
252 };
253 
256 GF_API std::ostream& operator<<(std::ostream &, GfVec3i const &);
257 
258 
260 inline GfVec3i
261 GfCompMult(GfVec3i const &v1, GfVec3i const &v2) {
262  return GfVec3i(
263  v1[0] * v2[0],
264  v1[1] * v2[1],
265  v1[2] * v2[2]
266  );
267 }
268 
270 inline GfVec3i
271 GfCompDiv(GfVec3i const &v1, GfVec3i const &v2) {
272  return GfVec3i(
273  v1[0] / v2[0],
274  v1[1] / v2[1],
275  v1[2] / v2[2]
276  );
277 }
278 
280 inline int
281 GfDot(GfVec3i const &v1, GfVec3i const &v2) {
282  return v1 * v2;
283 }
284 
285 
286 PXR_NAMESPACE_CLOSE_SCOPE
287 
288 #endif // PXR_BASE_GF_VEC3I_H
GfVec3i()=default
Default constructor does no initialization.
constexpr GfVec3i(int value)
Initialize all elements to a single value.
Definition: vec3i.h:72
GfVec3i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec3i.h:127
int const & operator[](size_t i) const
Indexing.
Definition: vec3i.h:137
friend size_t hash_value(GfVec3i const &vec)
Hash.
Definition: vec3i.h:141
decltype(std::declval< Left >()*std::declval< Right >()) GfCompMult(Left left, Right right)
Returns component-wise multiplication of vectors.
Definition: math.h:253
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
GfVec3i GetProjection(GfVec3i const &v) const
Returns the projection of this onto v.
Definition: vec3i.h:231
Low-level utilities for informing users of various internal and external diagnostic conditions...
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:36
static GfVec3i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec3i.h:103
GfVec3i & Set(int s0, int s1, int s2)
Set all elements with passed arguments.
Definition: vec3i.h:119
bool operator==(GfVec3i const &other) const
Equality comparison.
Definition: vec3i.h:150
int const * data() const
Direct data access.
Definition: vec3i.h:132
GfVec3i GetComplement(GfVec3i const &b) const
Returns the orthogonal complement of this-&gt;GetProjection(b).
Definition: vec3i.h:240
GfVec3i & operator+=(GfVec3i const &other)
Addition.
Definition: vec3i.h:176
decltype(std::declval< Left >()/std::declval< Right >()) GfCompDiv(Left left, Right right)
Returns component-wise quotient of vectors.
Definition: math.h:264
static GfVec3i XAxis()
Create a unit vector along the X-axis.
Definition: vec3i.h:91
GfVec3i & operator-=(GfVec3i const &other)
Subtraction.
Definition: vec3i.h:187
decltype(std::declval< Left >()*std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
Definition: math.h:242
static GfVec3i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec3i.h:111
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
GfVec3i operator-() const
Create a vec with negated elements.
Definition: vec3i.h:171
constexpr GfVec3i(Scl const *p)
Construct with pointer to values.
Definition: vec3i.h:85
GfVec3i & operator/=(int s)
Division by scalar.
Definition: vec3i.h:212
GfVec3i & operator*=(double s)
Multiplication by scalar.
Definition: vec3i.h:198
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
Defines useful mathematical limits.
int GetLengthSq() const
Squared length.
Definition: vec3i.h:245
int operator*(GfVec3i const &v) const
See GfDot().
Definition: vec3i.h:223
int ScalarType
Scalar element type and dimension.
Definition: vec3i.h:65
constexpr GfVec3i(int s0, int s1, int s2)
Initialize all elements with explicit arguments.
Definition: vec3i.h:78
Basic type for a vector of 3 GfHalf components.
Definition: vec3h.h:64
static GfVec3i YAxis()
Create a unit vector along the Y-axis.
Definition: vec3i.h:97