This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
51 GfVec2i() = default;
52
54 constexpr explicit GfVec2i(int value)
55 : _data{ value, value }
56 {
57 }
58
60 constexpr GfVec2i(int s0, int s1)
61 : _data{ s0, s1 }
62 {
63 }
64
66 template <class Scl>
67 constexpr explicit GfVec2i(Scl const *p)
68 : _data{ p[0], p[1] }
69 {
70 }
71
73 static GfVec2i XAxis() {
74 GfVec2i result(0);
75 result[0] = 1;
76 return result;
77 }
79 static GfVec2i YAxis() {
80 GfVec2i result(0);
81 result[1] = 1;
82 return result;
83 }
84
87 static GfVec2i Axis(size_t i) {
88 GfVec2i result(0);
89 if (i < 2)
90 result[i] = 1;
91 return result;
92 }
93
95 GfVec2i &Set(int s0, int s1) {
96 _data[0] = s0;
97 _data[1] = s1;
98 return *this;
99 }
100
102 GfVec2i &Set(int const *a) {
103 return Set(a[0], a[1]);
104 }
105
107 int const *data() const { return _data; }
108 int *data() { return _data; }
109 int const *GetArray() const { return data(); }
110
112 int const &operator[](size_t i) const { return _data[i]; }
113 int &operator[](size_t i) { return _data[i]; }
114
116 friend inline size_t hash_value(GfVec2i const &vec) {
117 return TfHash::Combine(vec[0], vec[1]);
118 }
119
121 bool operator==(GfVec2i const &other) const {
122 return _data[0] == other[0] &&
123 _data[1] == other[1];
124 }
125 bool operator!=(GfVec2i const &other) const {
126 return !(*this == other);
127 }
128
129 // TODO Add inequality for other vec types...
131 GF_API
132 bool operator==(class GfVec2d const &other) const;
134 GF_API
135 bool operator==(class GfVec2f const &other) const;
137 GF_API
138 bool operator==(class GfVec2h const &other) const;
139
142 return GfVec2i(-_data[0], -_data[1]);
143 }
144
146 GfVec2i &operator+=(GfVec2i const &other) {
147 _data[0] += other[0];
148 _data[1] += other[1];
149 return *this;
150 }
151 friend GfVec2i operator+(GfVec2i const &l, GfVec2i const &r) {
152 return GfVec2i(l) += r;
153 }
154
156 GfVec2i &operator-=(GfVec2i const &other) {
157 _data[0] -= other[0];
158 _data[1] -= other[1];
159 return *this;
160 }
161 friend GfVec2i operator-(GfVec2i const &l, GfVec2i const &r) {
162 return GfVec2i(l) -= r;
163 }
164
166 GfVec2i &operator*=(double s) {
167 _data[0] *= s;
168 _data[1] *= s;
169 return *this;
170 }
171 GfVec2i operator*(double s) const {
172 return GfVec2i(*this) *= s;
173 }
174 friend GfVec2i operator*(double s, GfVec2i const &v) {
175 return v * s;
176 }
177
180 _data[0] /= s;
181 _data[1] /= s;
182 return *this;
183 }
184 GfVec2i operator/(int s) const {
185 return GfVec2i(*this) /= s;
186 }
187
189 int operator*(GfVec2i const &v) const {
190 return _data[0] * v[0] + _data[1] * v[1];
191 }
192
197 GfVec2i GetProjection(GfVec2i const &v) const {
198 return v * (*this * v);
199 }
200
206 GfVec2i GetComplement(GfVec2i const &b) const {
207 return *this - this->GetProjection(b);
208 }
209
211 int GetLengthSq() const {
212 return *this * *this;
213 }
214
215
216private:
217 int _data[2];
218};
219
222GF_API std::ostream& operator<<(std::ostream &, GfVec2i const &);
223
224
226inline GfVec2i
227GfCompMult(GfVec2i const &v1, GfVec2i const &v2) {
228 return GfVec2i(
229 v1[0] * v2[0],
230 v1[1] * v2[1]
231 );
232}
233
235inline GfVec2i
236GfCompDiv(GfVec2i const &v1, GfVec2i const &v2) {
237 return GfVec2i(
238 v1[0] / v2[0],
239 v1[1] / v2[1]
240 );
241}
242
244inline int
245GfDot(GfVec2i const &v1, GfVec2i const &v2) {
246 return v1 * v2;
247}
248
249
250PXR_NAMESPACE_CLOSE_SCOPE
251
252#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:73
bool operator==(GfVec2i const &other) const
Equality comparison.
Definition: vec2i.h:121
GfVec2i GetComplement(GfVec2i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition: vec2i.h:206
GfVec2i & operator-=(GfVec2i const &other)
Subtraction.
Definition: vec2i.h:156
int operator*(GfVec2i const &v) const
See GfDot().
Definition: vec2i.h:189
GF_API bool operator==(class GfVec2h const &other) const
Equality comparison.
GfVec2i operator-() const
Create a vec with negated elements.
Definition: vec2i.h:141
GfVec2i & Set(int s0, int s1)
Set all elements with passed arguments.
Definition: vec2i.h:95
GfVec2i & operator*=(double s)
Multiplication by scalar.
Definition: vec2i.h:166
static GfVec2i YAxis()
Create a unit vector along the Y-axis.
Definition: vec2i.h:79
static GfVec2i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec2i.h:87
friend size_t hash_value(GfVec2i const &vec)
Hash.
Definition: vec2i.h:116
constexpr GfVec2i(int value)
Initialize all elements to a single value.
Definition: vec2i.h:54
GfVec2i & operator/=(int s)
Division by scalar.
Definition: vec2i.h:179
constexpr GfVec2i(int s0, int s1)
Initialize all elements with explicit arguments.
Definition: vec2i.h:60
int const * data() const
Direct data access.
Definition: vec2i.h:107
constexpr GfVec2i(Scl const *p)
Construct with pointer to values.
Definition: vec2i.h:67
GF_API bool operator==(class GfVec2f const &other) const
Equality comparison.
int const & operator[](size_t i) const
Indexing.
Definition: vec2i.h:112
GfVec2i & operator+=(GfVec2i const &other)
Addition.
Definition: vec2i.h:146
GF_API bool operator==(class GfVec2d const &other) const
Equality comparison.
GfVec2i()=default
Default constructor does no initialization.
GfVec2i GetProjection(GfVec2i const &v) const
Returns the projection of this onto v.
Definition: vec2i.h:197
GfVec2i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec2i.h:102
int ScalarType
Scalar element type and dimension.
Definition: vec2i.h:47
int GetLengthSq() const
Squared length.
Definition: vec2i.h:211
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:475
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:227
GfVec2i GfCompDiv(GfVec2i const &v1, GfVec2i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec2i.h:236
int GfDot(GfVec2i const &v1, GfVec2i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec2i.h:245