Loading...
Searching...
No Matches
vec2i.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//
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_VEC2I_H
12#define PXR_BASE_GF_VEC2I_H
13
16
17#include "pxr/pxr.h"
18#include "pxr/base/gf/api.h"
19#include "pxr/base/gf/limits.h"
20#include "pxr/base/gf/traits.h"
22#include "pxr/base/tf/hash.h"
23
24#include <cstddef>
25#include <type_traits>
26
27#include <iosfwd>
28
29PXR_NAMESPACE_OPEN_SCOPE
30
31
32template <>
33struct GfIsGfVec<class GfVec2i> { static const bool value = true; };
34
44{
45public:
47 typedef int ScalarType;
48 static const size_t dimension = 2;
49
61 int x, y;
63
66 GfVec2i() = default;
67
69 constexpr explicit GfVec2i(int value)
70 : x(value), y(value)
71 {
72 }
73
75 constexpr GfVec2i(int s0, int s1)
76 : x(s0), y(s1)
77 {
78 }
79
81 template <class Scl>
82 constexpr explicit GfVec2i(Scl const *p)
83 : x(p[0]), y(p[1])
84 {
85 }
87 static GfVec2i XAxis() {
88 GfVec2i result(0);
89 result[0] = 1;
90 return result;
91 }
92
94 static GfVec2i YAxis() {
95 GfVec2i result(0);
96 result[1] = 1;
97 return result;
98 }
99
102 static GfVec2i Axis(size_t i) {
103 GfVec2i result(0);
104 if (i < 2)
105 result[i] = 1;
106 return result;
107 }
108
110 GfVec2i &Set(int s0, int s1) {
111 x = s0;
112 y = s1;
113 return *this;
114 }
115
117 GfVec2i &Set(int const *a) {
118 return Set(a[0], a[1]);
119 }
120
126 int const *data() const { return &x; }
127 int *data() { return &x; }
128 int const *GetArray() const { return data(); }
129
131 int const &operator[](size_t i) const { return data()[i]; }
132 int &operator[](size_t i) { return data()[i]; }
133
135 friend inline size_t hash_value(GfVec2i const &vec) {
136 return TfHash::Combine(vec.x, vec.y);
137 }
138
140 bool operator==(GfVec2i const &other) const {
141 return x == other.x &&
142 y == other.y;
143 }
144 bool operator!=(GfVec2i const &other) const {
145 return !(*this == other);
146 }
147
148 // TODO Add inequality for other vec types...
150 GF_API
151 bool operator==(class GfVec2d const &other) const;
153 GF_API
154 bool operator==(class GfVec2f const &other) const;
156 GF_API
157 bool operator==(class GfVec2h const &other) const;
158
161 return GfVec2i(-x, -y);
162 }
163
165 GfVec2i &operator+=(GfVec2i const &other) {
166 x += other.x;
167 y += other.y;
168 return *this;
169 }
170 friend GfVec2i operator+(GfVec2i const &l, GfVec2i const &r) {
171 return GfVec2i(l) += r;
172 }
173
175 GfVec2i &operator-=(GfVec2i const &other) {
176 x -= other.x;
177 y -= other.y;
178 return *this;
179 }
180 friend GfVec2i operator-(GfVec2i const &l, GfVec2i const &r) {
181 return GfVec2i(l) -= r;
182 }
183
185 GfVec2i &operator*=(double s) {
186 x *= s;
187 y *= s;
188 return *this;
189 }
190 GfVec2i operator*(double s) const {
191 return GfVec2i(*this) *= s;
192 }
193 friend GfVec2i operator*(double s, GfVec2i const &v) {
194 return v * s;
195 }
196
199 x /= s;
200 y /= s;
201 return *this;
202 }
203 GfVec2i operator/(int s) const {
204 return GfVec2i(*this) /= s;
205 }
206
208 int operator*(GfVec2i const &v) const {
209 return x * v.x + y * v.y;
210 }
211
216 GfVec2i GetProjection(GfVec2i const &v) const {
217 return v * (*this * v);
218 }
219
225 GfVec2i GetComplement(GfVec2i const &b) const {
226 return *this - this->GetProjection(b);
227 }
228
230 int GetLengthSq() const {
231 return *this * *this;
232 }
233
234
250#if defined (doxygen)
251 constexpr GfVec2i xy() const;
252 constexpr GfVec2i yx() const;
254#else // !doxygen
255 // Note that these are templated on their own return type so that the
256 // declarations cost nothing in compile time & debug info unless they are
257 // actually called in a TU. Naming a different type is an error and
258 // static_assert()ed against.
259 template <class Vec = GfVec2i> constexpr Vec xy() const;
260 template <class Vec = GfVec2i> constexpr Vec yx() const;
261#endif // doxygen
262 };
263
266GF_API std::ostream& operator<<(std::ostream &, GfVec2i const &);
267
268PXR_NAMESPACE_CLOSE_SCOPE
269
270
271PXR_NAMESPACE_OPEN_SCOPE
272
273
274template <class Vec>
275constexpr Vec
276GfVec2i::xy() const
277{
278 static_assert(std::is_same<Vec, GfVec2i>::value);
279 return Vec(x, y);
280}
281
282template <class Vec>
283constexpr Vec
284GfVec2i::yx() const
285{
286 static_assert(std::is_same<Vec, GfVec2i>::value);
287 return Vec(y, x);
288}
289
290
292inline GfVec2i
293GfCompMult(GfVec2i const &v1, GfVec2i const &v2) {
294 return GfVec2i(
295 v1.x * v2.x,
296 v1.y * v2.y
297 );
298}
299
301inline GfVec2i
302GfCompDiv(GfVec2i const &v1, GfVec2i const &v2) {
303 return GfVec2i(
304 v1.x / v2.x,
305 v1.y / v2.y
306 );
307}
308
310inline int
311GfDot(GfVec2i const &v1, GfVec2i const &v2) {
312 return v1 * v2;
313}
314
315
316PXR_NAMESPACE_CLOSE_SCOPE
317
318#endif // PXR_BASE_GF_VEC2I_H
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 2 double components.
Definition vec2d.h:46
Basic type for a vector of 2 float components.
Definition vec2f.h:46
Basic type for a vector of 2 GfHalf components.
Definition vec2h.h:47
Basic type for a vector of 2 int components.
Definition vec2i.h:44
int ScalarType
Scalar element type and dimension.
Definition vec2i.h:47
static GfVec2i XAxis()
Create a unit vector along the X-axis.
Definition vec2i.h:87
bool operator==(GfVec2i const &other) const
Equality comparison.
Definition vec2i.h:140
GfVec2i GetComplement(GfVec2i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition vec2i.h:225
GfVec2i & operator-=(GfVec2i const &other)
Subtraction.
Definition vec2i.h:175
int operator*(GfVec2i const &v) const
See GfDot().
Definition vec2i.h:208
GF_API bool operator==(class GfVec2h const &other) const
Equality comparison.
GfVec2i operator-() const
Create a vec with negated elements.
Definition vec2i.h:160
GfVec2i & Set(int s0, int s1)
Set all elements with passed arguments.
Definition vec2i.h:110
GfVec2i & operator*=(double s)
Multiplication by scalar.
Definition vec2i.h:185
static GfVec2i YAxis()
Create a unit vector along the Y-axis.
Definition vec2i.h:94
static GfVec2i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition vec2i.h:102
friend size_t hash_value(GfVec2i const &vec)
Hash.
Definition vec2i.h:135
constexpr GfVec2i(int value)
Initialize all elements to a single value.
Definition vec2i.h:69
GfVec2i & operator/=(int s)
Division by scalar.
Definition vec2i.h:198
constexpr GfVec2i(int s0, int s1)
Initialize all elements with explicit arguments.
Definition vec2i.h:75
int const * data() const
Direct data access.
Definition vec2i.h:126
constexpr GfVec2i(Scl const *p)
Construct with pointer to values.
Definition vec2i.h:82
GF_API bool operator==(class GfVec2f const &other) const
Equality comparison.
int const & operator[](size_t i) const
Indexing.
Definition vec2i.h:131
GfVec2i & operator+=(GfVec2i const &other)
Addition.
Definition vec2i.h:165
GF_API bool operator==(class GfVec2d const &other) const
Equality comparison.
GfVec2i()=default
GfVec2i value-initializes to zero and performs no default initialization, like float or double.
GfVec2i GetProjection(GfVec2i const &v) const
Returns the projection of this onto v.
Definition vec2i.h:216
GfVec2i & Set(int const *a)
Set all elements with a pointer to data.
Definition vec2i.h:117
int GetLengthSq() const
Squared length.
Definition vec2i.h:230
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition hash.h:487
GF_API std::ostream & operator<<(std::ostream &, GfVec2i const &)
Output a GfVec2i.
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
Definition traits.h:23
GfVec2i GfCompMult(GfVec2i const &v1, GfVec2i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition vec2i.h:293
GfVec2i GfCompDiv(GfVec2i const &v1, GfVec2i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition vec2i.h:302
int GfDot(GfVec2i const &v1, GfVec2i const &v2)
Returns the dot (inner) product of two vectors.
Definition vec2i.h:311