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
size2.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//
7#ifndef PXR_BASE_GF_SIZE2_H
8#define PXR_BASE_GF_SIZE2_H
9
12
13#include "pxr/pxr.h"
15#include "pxr/base/gf/vec2i.h"
16#include "pxr/base/gf/api.h"
17
18#include <iosfwd>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
34class GfSize2 {
35public:
38 Set(0, 0);
39 }
40
42 GfSize2(const GfSize2& o) {
43 *this = o;
44 }
45
47 explicit GfSize2(const GfVec2i&o) {
48 Set(o[0], o[1]);
49 }
50
52 GfSize2(const size_t v[2]) {
53 Set(v);
54 }
55
57 GfSize2(size_t v0, size_t v1) {
58 Set(v0, v1);
59 }
60
62 GfSize2 & Set(const size_t v[2]) {
63 _vec[0] = v[0];
64 _vec[1] = v[1];
65 return *this;
66 }
67
69 GfSize2 & Set(size_t v0, size_t v1) {
70 _vec[0] = v0;
71 _vec[1] = v1;
72 return *this;
73 }
74
76 size_t & operator [](size_t i) {
77 return _vec[i];
78 }
79
81 const size_t & operator [](size_t i) const {
82 return _vec[i];
83 }
84
86 bool operator ==(const GfSize2 &v) const {
87 return _vec[0] == v._vec[0] && _vec[1] == v._vec[1];
88 }
89
91 bool operator !=(const GfSize2 &v) const {
92 return ! (*this == v);
93 }
94
97 _vec[0] += v._vec[0];
98 _vec[1] += v._vec[1];
99 return *this;
100 }
101
104 _vec[0] -= v._vec[0];
105 _vec[1] -= v._vec[1];
106 return *this;
107 }
108
111 _vec[0] *= v._vec[0];
112 _vec[1] *= v._vec[1];
113 return *this;
114 }
115
118 _vec[0] = _vec[0] * d;
119 _vec[1] = _vec[1] * d;
120 return *this;
121 }
122
125 _vec[0] = _vec[0] / d;
126 _vec[1] = _vec[1] / d;
127 return *this;
128 }
129
131 friend GfSize2 operator +(const GfSize2 &v1, const GfSize2 &v2) {
132 return GfSize2(v1._vec[0]+v2._vec[0],
133 v1._vec[1]+v2._vec[1]);
134 }
135
137 friend GfSize2 operator -(const GfSize2 &v1, const GfSize2 &v2) {
138 return GfSize2(v1._vec[0]-v2._vec[0],
139 v1._vec[1]-v2._vec[1]);
140 }
141
143 friend GfSize2 operator *(const GfSize2 &v1, const GfSize2 &v2) {
144 return GfSize2(v1._vec[0]*v2._vec[0],
145 v1._vec[1]*v2._vec[1]);
146 }
147
149 friend GfSize2 operator *(const GfSize2 &v1, int s) {
150 return GfSize2(v1._vec[0]*s,
151 v1._vec[1]*s);
152 }
153
155 friend GfSize2 operator *(int s, const GfSize2 &v1) {
156 return GfSize2(v1._vec[0]*s,
157 v1._vec[1]*s);
158 }
159
161 friend GfSize2 operator /(const GfSize2 &v1, int s) {
162 return GfSize2(v1._vec[0]/s,
163 v1._vec[1]/s);
164 }
165
167 GF_API
168 friend std::ostream &operator<<(std::ostream &o, GfSize2 const &v);
169
171 operator GfVec2i() const {
172 return GfVec2i(_vec[0], _vec[1]);
173 }
174 private:
175 size_t _vec[2];
176};
177
178// Friend functions must be declared
179GF_API std::ostream &operator<<(std::ostream &o, GfSize2 const &v);
180
181PXR_NAMESPACE_CLOSE_SCOPE
182
183#endif // PXR_BASE_GF_SIZE2_H
Two-dimensional array of sizes.
Definition: size2.h:34
GfSize2()
Default constructor initializes components to zero.
Definition: size2.h:37
GfSize2(const size_t v[2])
Construct from an array.
Definition: size2.h:52
GfSize2 & operator*=(GfSize2 const &v)
Component-wise in-place multiplication.
Definition: size2.h:110
friend GfSize2 operator/(const GfSize2 &v1, int s)
Component-wise division by a scalar.
Definition: size2.h:161
GfSize2 & Set(const size_t v[2])
Set to the values in a given array.
Definition: size2.h:62
friend GfSize2 operator-(const GfSize2 &v1, const GfSize2 &v2)
Component-wise subtraction.
Definition: size2.h:137
bool operator!=(const GfSize2 &v) const
Component-wise inequality.
Definition: size2.h:91
GfSize2(const GfVec2i &o)
Conversion from GfVec2i.
Definition: size2.h:47
GfSize2 & operator/=(int d)
Component-wise in-place division by a scalar.
Definition: size2.h:124
GfSize2(size_t v0, size_t v1)
Construct from two values.
Definition: size2.h:57
GF_API friend std::ostream & operator<<(std::ostream &o, GfSize2 const &v)
Output operator.
bool operator==(const GfSize2 &v) const
Component-wise equality.
Definition: size2.h:86
friend GfSize2 operator+(const GfSize2 &v1, const GfSize2 &v2)
Component-wise addition.
Definition: size2.h:131
GfSize2 & Set(size_t v0, size_t v1)
Set to values passed directly.
Definition: size2.h:69
GfSize2 & operator+=(const GfSize2 &v)
Component-wise in-place addition.
Definition: size2.h:96
size_t & operator[](size_t i)
Array operator.
Definition: size2.h:76
GfSize2(const GfSize2 &o)
Copy constructor.
Definition: size2.h:42
friend GfSize2 operator*(const GfSize2 &v1, const GfSize2 &v2)
Component-wise multiplication.
Definition: size2.h:143
GfSize2 & operator-=(const GfSize2 &v)
Component-wise in-place subtraction.
Definition: size2.h:103
Basic type for a vector of 2 int components.
Definition: vec2i.h:44
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Define integral types.