28 #ifndef PXR_BASE_GF_VEC2D_H 29 #define PXR_BASE_GF_VEC2D_H 36 #include "pxr/base/gf/api.h" 38 #include "pxr/base/gf/traits.h" 41 #include <boost/functional/hash.hpp> 48 PXR_NAMESPACE_OPEN_SCOPE
68 static const size_t dimension = 2;
75 : _data{ value, value }
132 return Set(a[0], a[1]);
136 double const *
data()
const {
return _data; }
137 double *
data() {
return _data; }
138 double const *GetArray()
const {
return data(); }
141 double const &
operator[](
size_t i)
const {
return _data[i]; }
142 double &
operator[](
size_t i) {
return _data[i]; }
147 boost::hash_combine(h, vec[0]);
148 boost::hash_combine(h, vec[1]);
154 return _data[0] == other[0] &&
155 _data[1] == other[1];
157 bool operator!=(
GfVec2d const &other)
const {
158 return !(*
this == other);
174 return GfVec2d(-_data[0], -_data[1]);
179 _data[0] += other[0];
180 _data[1] += other[1];
189 _data[0] -= other[0];
190 _data[1] -= other[1];
203 GfVec2d operator*(
double s)
const {
216 return *
this *= (1.0 / s);
218 GfVec2d operator/(
double s)
const {
219 return *
this * (1.0 / s);
224 return _data[0] * v[0] + _data[1] * v[1];
232 return v * (*
this * v);
246 return *
this * *
this;
266 *
this /= (length > eps) ? length : eps;
272 normalized.Normalize(eps);
286 PXR_NAMESPACE_CLOSE_SCOPE
292 PXR_NAMESPACE_OPEN_SCOPE
360 return v.GetNormalized(eps);
389 return delta.
GetLengthSq() <= tolerance * tolerance;
394 PXR_NAMESPACE_CLOSE_SCOPE
396 #endif // PXR_BASE_GF_VEC2D_H GfVec2d & operator+=(GfVec2d const &other)
Addition.
double GfDot(GfVec2d const &v1, GfVec2d const &v2)
Returns the dot (inner) product of two vectors.
GfVec2d GfGetProjection(GfVec2d const &a, GfVec2d const &b)
Returns the projection of a onto b.
double const * data() const
Direct data access.
GfVec2d & operator *=(double s)
Multiplication by scalar.
Basic type for a vector of 2 int components.
Assorted mathematical utility functions.
static GfVec2d YAxis()
Create a unit vector along the Y-axis.
Low-level utilities for informing users of various internal and external diagnostic conditions.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
GF_API std::ostream & operator<<(std::ostream &, GfVec2d const &)
Output a GfVec2d.
Basic type for a vector of 2 double components.
bool GfIsClose(GfVec2d const &v1, GfVec2d const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
double const & operator[](size_t i) const
Indexing.
GfVec2d GfGetNormalized(GfVec2d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec2d & operator-=(GfVec2d const &other)
Subtraction.
Basic type for a vector of 2 GfHalf components.
GfVec2d GfCompMult(GfVec2d const &v1, GfVec2d const &v2)
Returns component-wise multiplication of vectors v1 and v2.
constexpr GfVec2d(double value)
Initialize all elements to a single value.
double GetLengthSq() const
Squared length.
double GetLength() const
Length.
double GfNormalize(GfVec2d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
GfVec2d & Set(double const *a)
Set all elements with a pointer to data.
bool operator==(GfVec2d const &other) const
Equality comparison.
constexpr GfVec2d(Scl const *p)
Construct with pointer to values.
double GfSqrt(double f)
Return sqrt(f).
static GfVec2d XAxis()
Create a unit vector along the X-axis.
friend size_t hash_value(GfVec2d const &vec)
Hash.
GfVec2d & operator/=(double s)
Division by scalar.
GfVec2d & Set(double s0, double s1)
Set all elements with passed arguments.
Basic type for a vector of 2 float components.
constexpr GfVec2d(double s0, double s1)
Initialize all elements with explicit arguments.
static GfVec2d Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Defines useful mathematical limits.
GfVec2d GfCompDiv(GfVec2d const &v1, GfVec2d const &v2)
Returns component-wise quotient of vectors v1 and v2.
double GfGetLength(GfVec2d const &v)
Returns the geometric length of v.
GfVec2d GetProjection(GfVec2d const &v) const
Returns the projection of this onto v.
GfVec2d GfGetComplement(GfVec2d const &a, GfVec2d const &b)
Returns the orthogonal complement of a.GetProjection(b).
GfVec2d operator-() const
Create a vec with negated elements.
double ScalarType
Scalar element type and dimension.
GfVec2d GetComplement(GfVec2d const &b) const
Returns the orthogonal complement of this->GetProjection(b).
GfVec2d()=default
Default constructor does no initialization.
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.