Loading...
Searching...
No Matches
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"
36#include "pxr/base/gf/api.h"
37#include "pxr/base/gf/limits.h"
38#include "pxr/base/gf/traits.h"
39#include "pxr/base/tf/hash.h"
40
41#include <cstddef>
42
43#include <iosfwd>
44
45PXR_NAMESPACE_OPEN_SCOPE
46
47class GfVec2i;
48
49template <>
50struct GfIsGfVec<class GfVec2i> { static const bool value = true; };
51
61{
62public:
64 typedef int ScalarType;
65 static const size_t dimension = 2;
66
68 GfVec2i() = default;
69
71 constexpr explicit GfVec2i(int value)
72 : _data{ value, value }
73 {
74 }
75
77 constexpr GfVec2i(int s0, int s1)
78 : _data{ s0, s1 }
79 {
80 }
81
83 template <class Scl>
84 constexpr explicit GfVec2i(Scl const *p)
85 : _data{ p[0], p[1] }
86 {
87 }
88
90 static GfVec2i XAxis() {
91 GfVec2i result(0);
92 result[0] = 1;
93 return result;
94 }
96 static GfVec2i YAxis() {
97 GfVec2i result(0);
98 result[1] = 1;
99 return result;
100 }
101
104 static GfVec2i Axis(size_t i) {
105 GfVec2i result(0);
106 if (i < 2)
107 result[i] = 1;
108 return result;
109 }
110
112 GfVec2i &Set(int s0, int s1) {
113 _data[0] = s0;
114 _data[1] = s1;
115 return *this;
116 }
117
119 GfVec2i &Set(int const *a) {
120 return Set(a[0], a[1]);
121 }
122
124 int const *data() const { return _data; }
125 int *data() { return _data; }
126 int const *GetArray() const { return data(); }
127
129 int const &operator[](size_t i) const { return _data[i]; }
130 int &operator[](size_t i) { return _data[i]; }
131
133 friend inline size_t hash_value(GfVec2i const &vec) {
134 return TfHash::Combine(vec[0], vec[1]);
135 }
136
138 bool operator==(GfVec2i const &other) const {
139 return _data[0] == other[0] &&
140 _data[1] == other[1];
141 }
142 bool operator!=(GfVec2i const &other) const {
143 return !(*this == other);
144 }
145
146 // TODO Add inequality for other vec types...
148 GF_API
149 bool operator==(class GfVec2d const &other) const;
151 GF_API
152 bool operator==(class GfVec2f const &other) const;
154 GF_API
155 bool operator==(class GfVec2h const &other) const;
156
159 return GfVec2i(-_data[0], -_data[1]);
160 }
161
163 GfVec2i &operator+=(GfVec2i const &other) {
164 _data[0] += other[0];
165 _data[1] += other[1];
166 return *this;
167 }
168 friend GfVec2i operator+(GfVec2i const &l, GfVec2i const &r) {
169 return GfVec2i(l) += r;
170 }
171
173 GfVec2i &operator-=(GfVec2i const &other) {
174 _data[0] -= other[0];
175 _data[1] -= other[1];
176 return *this;
177 }
178 friend GfVec2i operator-(GfVec2i const &l, GfVec2i const &r) {
179 return GfVec2i(l) -= r;
180 }
181
183 GfVec2i &operator*=(double s) {
184 _data[0] *= s;
185 _data[1] *= s;
186 return *this;
187 }
188 GfVec2i operator*(double s) const {
189 return GfVec2i(*this) *= s;
190 }
191 friend GfVec2i operator*(double s, GfVec2i const &v) {
192 return v * s;
193 }
194
197 _data[0] /= s;
198 _data[1] /= s;
199 return *this;
200 }
201 GfVec2i operator/(int s) const {
202 return GfVec2i(*this) /= s;
203 }
204
206 int operator*(GfVec2i const &v) const {
207 return _data[0] * v[0] + _data[1] * v[1];
208 }
209
214 GfVec2i GetProjection(GfVec2i const &v) const {
215 return v * (*this * v);
216 }
217
223 GfVec2i GetComplement(GfVec2i const &b) const {
224 return *this - this->GetProjection(b);
225 }
226
228 int GetLengthSq() const {
229 return *this * *this;
230 }
231
232
233private:
234 int _data[2];
235};
236
239GF_API std::ostream& operator<<(std::ostream &, GfVec2i const &);
240
241
243inline GfVec2i
244GfCompMult(GfVec2i const &v1, GfVec2i const &v2) {
245 return GfVec2i(
246 v1[0] * v2[0],
247 v1[1] * v2[1]
248 );
249}
250
252inline GfVec2i
253GfCompDiv(GfVec2i const &v1, GfVec2i const &v2) {
254 return GfVec2i(
255 v1[0] / v2[0],
256 v1[1] / v2[1]
257 );
258}
259
261inline int
262GfDot(GfVec2i const &v1, GfVec2i const &v2) {
263 return v1 * v2;
264}
265
266
267PXR_NAMESPACE_CLOSE_SCOPE
268
269#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:63
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
Basic type for a vector of 2 GfHalf components.
Definition: vec2h.h:64
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
static GfVec2i XAxis()
Create a unit vector along the X-axis.
Definition: vec2i.h:90
bool operator==(GfVec2i const &other) const
Equality comparison.
Definition: vec2i.h:138
GfVec2i GetComplement(GfVec2i const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition: vec2i.h:223
GfVec2i & operator-=(GfVec2i const &other)
Subtraction.
Definition: vec2i.h:173
int operator*(GfVec2i const &v) const
See GfDot().
Definition: vec2i.h:206
GF_API bool operator==(class GfVec2h const &other) const
Equality comparison.
GfVec2i operator-() const
Create a vec with negated elements.
Definition: vec2i.h:158
GfVec2i & Set(int s0, int s1)
Set all elements with passed arguments.
Definition: vec2i.h:112
GfVec2i & operator*=(double s)
Multiplication by scalar.
Definition: vec2i.h:183
static GfVec2i YAxis()
Create a unit vector along the Y-axis.
Definition: vec2i.h:96
static GfVec2i Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition: vec2i.h:104
friend size_t hash_value(GfVec2i const &vec)
Hash.
Definition: vec2i.h:133
constexpr GfVec2i(int value)
Initialize all elements to a single value.
Definition: vec2i.h:71
GfVec2i & operator/=(int s)
Division by scalar.
Definition: vec2i.h:196
constexpr GfVec2i(int s0, int s1)
Initialize all elements with explicit arguments.
Definition: vec2i.h:77
int const * data() const
Direct data access.
Definition: vec2i.h:124
constexpr GfVec2i(Scl const *p)
Construct with pointer to values.
Definition: vec2i.h:84
GF_API bool operator==(class GfVec2f const &other) const
Equality comparison.
int const & operator[](size_t i) const
Indexing.
Definition: vec2i.h:129
GfVec2i & operator+=(GfVec2i const &other)
Addition.
Definition: vec2i.h:163
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:214
GfVec2i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec2i.h:119
int ScalarType
Scalar element type and dimension.
Definition: vec2i.h:64
int GetLengthSq() const
Squared length.
Definition: vec2i.h:228
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:492
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:36
GfVec2i GfCompMult(GfVec2i const &v1, GfVec2i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec2i.h:244
GfVec2i GfCompDiv(GfVec2i const &v1, GfVec2i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec2i.h:253
int GfDot(GfVec2i const &v1, GfVec2i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec2i.h:262