11#ifndef PXR_BASE_GF_VEC2F_H
12#define PXR_BASE_GF_VEC2F_H
19#include "pxr/base/gf/api.h"
21#include "pxr/base/gf/traits.h"
30PXR_NAMESPACE_OPEN_SCOPE
50 static const size_t dimension = 2;
57 : _data{ value, value }
114 return Set(a[0], a[1]);
118 float const *
data()
const {
return _data; }
119 float *
data() {
return _data; }
120 float const *GetArray()
const {
return data(); }
124 float &
operator[](
size_t i) {
return _data[i]; }
133 return _data[0] == other[0] &&
134 _data[1] == other[1];
136 bool operator!=(
GfVec2f const &other)
const {
137 return !(*
this == other);
153 return GfVec2f(-_data[0], -_data[1]);
158 _data[0] += other[0];
159 _data[1] += other[1];
168 _data[0] -= other[0];
169 _data[1] -= other[1];
182 GfVec2f operator*(
double s)
const {
195 return *
this *= (1.0 / s);
197 GfVec2f operator/(
double s)
const {
198 return *
this * (1.0 / s);
203 return _data[0] * v[0] + _data[1] * v[1];
211 return v * (*
this * v);
225 return *
this * *
this;
245 *
this /= (length > eps) ? length : eps;
251 normalized.Normalize(eps);
265PXR_NAMESPACE_CLOSE_SCOPE
271PXR_NAMESPACE_OPEN_SCOPE
339 return v.GetNormalized(eps);
368 return delta.
GetLengthSq() <= tolerance * tolerance;
373PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 2 double components.
Basic type for a vector of 2 float components.
GfVec2f()=default
Default constructor does no initialization.
constexpr GfVec2f(float s0, float s1)
Initialize all elements with explicit arguments.
friend size_t hash_value(GfVec2f const &vec)
Hash.
GfVec2f & operator+=(GfVec2f const &other)
Addition.
GfVec2f GetComplement(GfVec2f const &b) const
Returns the orthogonal complement of this->GetProjection(b).
GfVec2f & operator/=(double s)
Division by scalar.
GfVec2f & operator-=(GfVec2f const &other)
Subtraction.
GF_API bool operator==(class GfVec2h const &other) const
Equality comparison.
GfVec2f & Set(float s0, float s1)
Set all elements with passed arguments.
static GfVec2f Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
static GfVec2f XAxis()
Create a unit vector along the X-axis.
constexpr GfVec2f(Scl const *p)
Construct with pointer to values.
float GetLength() const
Length.
static GfVec2f YAxis()
Create a unit vector along the Y-axis.
float Normalize(float eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
float operator*(GfVec2f const &v) const
See GfDot().
GfVec2f operator-() const
Create a vec with negated elements.
float const & operator[](size_t i) const
Indexing.
float GetLengthSq() const
Squared length.
bool operator==(GfVec2f const &other) const
Equality comparison.
GfVec2f & Set(float const *a)
Set all elements with a pointer to data.
GfVec2f & operator*=(double s)
Multiplication by scalar.
GfVec2f GetProjection(GfVec2f const &v) const
Returns the projection of this onto v.
constexpr GfVec2f(float value)
Initialize all elements to a single value.
GF_API bool operator==(class GfVec2d const &other) const
Equality comparison.
float const * data() const
Direct data access.
float ScalarType
Scalar element type and dimension.
GF_API bool operator==(class GfVec2i const &other) const
Equality comparison.
Basic type for a vector of 2 GfHalf components.
Basic type for a vector of 2 int components.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Assorted mathematical utility functions.
double GfSqrt(double f)
Return sqrt(f).
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.
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,...
float GfGetLength(GfVec2f const &v)
Returns the geometric length of v.
GfVec2f GfGetProjection(GfVec2f const &a, GfVec2f const &b)
Returns the projection of a onto b.
GfVec2f GfGetComplement(GfVec2f const &a, GfVec2f const &b)
Returns the orthogonal complement of a.GetProjection(b).
bool GfIsClose(GfVec2f const &v1, GfVec2f const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
float GfDot(GfVec2f const &v1, GfVec2f const &v2)
Returns the dot (inner) product of two vectors.
GfVec2f GfCompMult(GfVec2f const &v1, GfVec2f const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfVec2f GfCompDiv(GfVec2f const &v1, GfVec2f const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfVec2f GfGetNormalized(GfVec2f const &v, float eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
float GfNormalize(GfVec2f *v, float eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.