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"
19#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/limits.h"
21#include "pxr/base/gf/traits.h"
22#include "pxr/base/tf/hash.h"
23
24#include <cstddef>
25
26#include <iosfwd>
27
28PXR_NAMESPACE_OPEN_SCOPE
29
30class GfVec2i;
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
52 GfVec2i() = default;
53
55 constexpr explicit GfVec2i(int value)
56 : _data{ value, value }
57 {
58 }
59
61 constexpr GfVec2i(int s0, int s1)
62 : _data{ s0, s1 }
63 {
64 }
65
67 template <class Scl>
68 constexpr explicit GfVec2i(Scl const *p)
69 : _data{ p[0], p[1] }
70 {
71 }
72
74 static GfVec2i XAxis() {
75 GfVec2i result(0);
76 result[0] = 1;
77 return result;
78 }
80 static GfVec2i YAxis() {
81 GfVec2i result(0);
82 result[1] = 1;
83 return result;
84 }
85
88 static GfVec2i Axis(size_t i) {
89 GfVec2i result(0);
90 if (i < 2)
91 result[i] = 1;
92 return result;
93 }
94
96 GfVec2i &Set(int s0, int s1) {
97 _data[0] = s0;
98 _data[1] = s1;
99 return *this;
100 }
101
103 GfVec2i &Set(int const *a) {
104 return Set(a[0], a[1]);
105 }
106
108 int const *data() const { return _data; }
109 int *data() { return _data; }
110 int const *GetArray() const { return data(); }
111
113 int const &operator[](size_t i) const { return _data[i]; }
114 int &operator[](size_t i) { return _data[i]; }
115
117 friend inline size_t hash_value(GfVec2i const &vec) {
118 return TfHash::Combine(vec[0], vec[1]);
119 }
120
122 bool operator==(GfVec2i const &other) const {
123 return _data[0] == other[0] &&
124 _data[1] == other[1];
125 }
126 bool operator!=(GfVec2i const &other) const {
127 return !(*this == other);
128 }
129
130 // TODO Add inequality for other vec types...
132 GF_API
133 bool operator==(class GfVec2d const &other) const;
135 GF_API
136 bool operator==(class GfVec2f const &other) const;
138 GF_API
139 bool operator==(class GfVec2h const &other) const;
140
143 return GfVec2i(-_data[0], -_data[1]);
144 }
145
147 GfVec2i &operator+=(GfVec2i const &other) {
148 _data[0] += other[0];
149 _data[1] += other[1];
150 return *this;
151 }
152 friend GfVec2i operator+(GfVec2i const &l, GfVec2i const &r) {
153 return GfVec2i(l) += r;
154 }
155
157 GfVec2i &operator-=(GfVec2i const &other) {
158 _data[0] -= other[0];
159 _data[1] -= other[1];
160 return *this;
161 }
162 friend GfVec2i operator-(GfVec2i const &l, GfVec2i const &r) {
163 return GfVec2i(l) -= r;
164 }
165
167 GfVec2i &operator*=(double s) {
168 _data[0] *= s;
169 _data[1] *= s;
170 return *this;
171 }
172 GfVec2i operator*(double s) const {
173 return GfVec2i(*this) *= s;
174 }
175 friend GfVec2i operator*(double s, GfVec2i const &v) {
176 return v * s;
177 }
178
181 _data[0] /= s;
182 _data[1] /= s;
183 return *this;
184 }
185 GfVec2i operator/(int s) const {
186 return GfVec2i(*this) /= s;
187 }
188
190 int operator*(GfVec2i const &v) const {
191 return _data[0] * v[0] + _data[1] * v[1];
192 }
193
198 GfVec2i GetProjection(GfVec2i const &v) const {
199 return v * (*this * v);
200 }
201
207 GfVec2i GetComplement(GfVec2i const &b) const {
208 return *this - this->GetProjection(b);
209 }
210
212 int GetLengthSq() const {
213 return *this * *this;
214 }
215
216
217private:
218 int _data[2];
219};
220
223GF_API std::ostream& operator<<(std::ostream &, GfVec2i const &);
224
225
227inline GfVec2i
228GfCompMult(GfVec2i const &v1, GfVec2i const &v2) {
229 return GfVec2i(
230 v1[0] * v2[0],
231 v1[1] * v2[1]
232 );
233}
234
236inline GfVec2i
237GfCompDiv(GfVec2i const &v1, GfVec2i const &v2) {
238 return GfVec2i(
239 v1[0] / v2[0],
240 v1[1] / v2[1]
241 );
242}
243
245inline int
246GfDot(GfVec2i const &v1, GfVec2i const &v2) {
247 return v1 * v2;
248}
249
250
251PXR_NAMESPACE_CLOSE_SCOPE
252
253#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
static GfVec2i XAxis()
Create a unit vector along the X-axis.
Definition: vec2i.h:74
bool operator==(GfVec2i const &other) const
Equality comparison.
Definition: vec2i.h:122
GfVec2i GetComplement(GfVec2i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition: vec2i.h:207
GfVec2i & operator-=(GfVec2i const &other)
Subtraction.
Definition: vec2i.h:157
int operator*(GfVec2i const &v) const
See GfDot().
Definition: vec2i.h:190
GF_API bool operator==(class GfVec2h const &other) const
Equality comparison.
GfVec2i operator-() const
Create a vec with negated elements.
Definition: vec2i.h:142
GfVec2i & Set(int s0, int s1)
Set all elements with passed arguments.
Definition: vec2i.h:96
GfVec2i & operator*=(double s)
Multiplication by scalar.
Definition: vec2i.h:167
static GfVec2i YAxis()
Create a unit vector along the Y-axis.
Definition: vec2i.h:80
static GfVec2i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec2i.h:88
friend size_t hash_value(GfVec2i const &vec)
Hash.
Definition: vec2i.h:117
constexpr GfVec2i(int value)
Initialize all elements to a single value.
Definition: vec2i.h:55
GfVec2i & operator/=(int s)
Division by scalar.
Definition: vec2i.h:180
constexpr GfVec2i(int s0, int s1)
Initialize all elements with explicit arguments.
Definition: vec2i.h:61
int const * data() const
Direct data access.
Definition: vec2i.h:108
constexpr GfVec2i(Scl const *p)
Construct with pointer to values.
Definition: vec2i.h:68
GF_API bool operator==(class GfVec2f const &other) const
Equality comparison.
int const & operator[](size_t i) const
Indexing.
Definition: vec2i.h:113
GfVec2i & operator+=(GfVec2i const &other)
Addition.
Definition: vec2i.h:147
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:198
GfVec2i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec2i.h:103
int ScalarType
Scalar element type and dimension.
Definition: vec2i.h:47
int GetLengthSq() const
Squared length.
Definition: vec2i.h:212
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 &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
Definition: traits.h:19
GfVec2i GfCompMult(GfVec2i const &v1, GfVec2i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec2i.h:228
GfVec2i GfCompDiv(GfVec2i const &v1, GfVec2i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec2i.h:237
int GfDot(GfVec2i const &v1, GfVec2i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec2i.h:246