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 //
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_VEC2I_H
29 #define PXR_BASE_GF_VEC2I_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 GfVec2i;
49 
50 template <>
51 struct GfIsGfVec<class GfVec2i> { static const bool value = true; };
52 
61 class GfVec2i
62 {
63 public:
65  typedef int ScalarType;
66  static const size_t dimension = 2;
67 
69  GfVec2i() = default;
70 
72  constexpr explicit GfVec2i(int value)
73  : _data{ value, value }
74  {
75  }
76 
78  constexpr GfVec2i(int s0, int s1)
79  : _data{ s0, s1 }
80  {
81  }
82 
84  template <class Scl>
85  constexpr explicit GfVec2i(Scl const *p)
86  : _data{ p[0], p[1] }
87  {
88  }
89 
91  static GfVec2i XAxis() {
92  GfVec2i result(0);
93  result[0] = 1;
94  return result;
95  }
97  static GfVec2i YAxis() {
98  GfVec2i result(0);
99  result[1] = 1;
100  return result;
101  }
102 
105  static GfVec2i Axis(size_t i) {
106  GfVec2i result(0);
107  if (i < 2)
108  result[i] = 1;
109  return result;
110  }
111 
113  GfVec2i &Set(int s0, int s1) {
114  _data[0] = s0;
115  _data[1] = s1;
116  return *this;
117  }
118 
120  GfVec2i &Set(int const *a) {
121  return Set(a[0], a[1]);
122  }
123 
125  int const *data() const { return _data; }
126  int *data() { return _data; }
127  int const *GetArray() const { return data(); }
128 
130  int const &operator[](size_t i) const { return _data[i]; }
131  int &operator[](size_t i) { return _data[i]; }
132 
134  friend inline size_t hash_value(GfVec2i const &vec) {
135  size_t h = 0;
136  boost::hash_combine(h, vec[0]);
137  boost::hash_combine(h, vec[1]);
138  return h;
139  }
140 
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...
152  GF_API
153  bool operator==(class GfVec2d const &other) const;
155  GF_API
156  bool operator==(class GfVec2f const &other) const;
158  GF_API
159  bool operator==(class GfVec2h const &other) const;
160 
162  GfVec2i operator-() const {
163  return GfVec2i(-_data[0], -_data[1]);
164  }
165 
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 
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 
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 
200  GfVec2i &operator/=(int s) {
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 
210  int operator*(GfVec2i const &v) const {
211  return _data[0] * v[0] + _data[1] * v[1];
212  }
213 
218  GfVec2i GetProjection(GfVec2i const &v) const {
219  return v * (*this * v);
220  }
221 
227  GfVec2i GetComplement(GfVec2i const &b) const {
228  return *this - this->GetProjection(b);
229  }
230 
232  int GetLengthSq() const {
233  return *this * *this;
234  }
235 
236 
237 private:
238  int _data[2];
239 };
240 
243 GF_API std::ostream& operator<<(std::ostream &, GfVec2i const &);
244 
245 
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 
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 
265 inline int
266 GfDot(GfVec2i const &v1, GfVec2i const &v2) {
267  return v1 * v2;
268 }
269 
270 
271 PXR_NAMESPACE_CLOSE_SCOPE
272 
273 #endif // PXR_BASE_GF_VEC2I_H
int operator*(GfVec2i const &v) const
See GfDot().
Definition: vec2i.h:210
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
GfVec2i & operator+=(GfVec2i const &other)
Addition.
Definition: vec2i.h:167
static GfVec2i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec2i.h:105
GfVec2i & Set(int s0, int s1)
Set all elements with passed arguments.
Definition: vec2i.h:113
decltype(std::declval< Left >()*std::declval< Right >()) GfCompMult(Left left, Right right)
Returns component-wise multiplication of vectors.
Definition: math.h:253
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
constexpr GfVec2i(Scl const *p)
Construct with pointer to values.
Definition: vec2i.h:85
bool operator==(GfVec2i const &other) const
Equality comparison.
Definition: vec2i.h:142
Basic type for a vector of 2 double components.
Definition: vec2d.h:63
constexpr GfVec2i(int s0, int s1)
Initialize all elements with explicit arguments.
Definition: vec2i.h:78
GfVec2i GetProjection(GfVec2i const &v) const
Returns the projection of this onto v.
Definition: vec2i.h:218
Basic type for a vector of 2 GfHalf components.
Definition: vec2h.h:64
static GfVec2i XAxis()
Create a unit vector along the X-axis.
Definition: vec2i.h:91
decltype(std::declval< Left >()/std::declval< Right >()) GfCompDiv(Left left, Right right)
Returns component-wise quotient of vectors.
Definition: math.h:264
decltype(std::declval< Left >()*std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
Definition: math.h:242
GfVec2i & operator-=(GfVec2i const &other)
Subtraction.
Definition: vec2i.h:177
int const * data() const
Direct data access.
Definition: vec2i.h:125
friend size_t hash_value(GfVec2i const &vec)
Hash.
Definition: vec2i.h:134
GfVec2i GetComplement(GfVec2i const &b) const
Returns the orthogonal complement of this-&gt;GetProjection(b).
Definition: vec2i.h:227
static GfVec2i YAxis()
Create a unit vector along the Y-axis.
Definition: vec2i.h:97
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
constexpr GfVec2i(int value)
Initialize all elements to a single value.
Definition: vec2i.h:72
GfVec2i & operator*=(double s)
Multiplication by scalar.
Definition: vec2i.h:187
int ScalarType
Scalar element type and dimension.
Definition: vec2i.h:65
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
GfVec2i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec2i.h:120
int GetLengthSq() const
Squared length.
Definition: vec2i.h:232
Defines useful mathematical limits.
int const & operator[](size_t i) const
Indexing.
Definition: vec2i.h:130
GfVec2i operator-() const
Create a vec with negated elements.
Definition: vec2i.h:162
GfVec2i()=default
Default constructor does no initialization.
GfVec2i & operator/=(int s)
Division by scalar.
Definition: vec2i.h:200