28 #ifndef PXR_BASE_GF_VEC2F_H
29 #define PXR_BASE_GF_VEC2F_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 float const *
data()
const {
return _data; }
137 float *
data() {
return _data; }
138 float const *GetArray()
const {
return data(); }
142 float &
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!=(
GfVec2f const &other)
const {
158 return !(*
this == other);
174 return GfVec2f(-_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 GfVec2f operator*(
double s)
const {
216 return *
this *= (1.0 / s);
218 GfVec2f 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;
267 *
this /= (length > eps) ? length : eps;
273 normalized.Normalize(eps);
287 PXR_NAMESPACE_CLOSE_SCOPE
293 PXR_NAMESPACE_OPEN_SCOPE
361 return v.GetNormalized(eps);
390 return delta.
GetLengthSq() <= tolerance * tolerance;
395 PXR_NAMESPACE_CLOSE_SCOPE
397 #endif // PXR_BASE_GF_VEC2F_H
static GfVec2f Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfVec2d GfGetProjection(GfVec2d const &a, GfVec2d const &b)
Returns the projection of a onto b.
bool GfIsClose(double a, double b, double epsilon)
Returns true if a and b are with epsilon of each other.
Basic type for a vector of 2 int components.
float const * data() const
Direct data access.
decltype(std::declval< Left >()*std::declval< Right >()) GfCompMult(Left left, Right right)
Returns component-wise multiplication of vectors.
constexpr GfVec2f(Scl const *p)
Construct with pointer to values.
Assorted mathematical utility functions.
GfVec2f & operator/=(double s)
Division by scalar.
float const & operator[](size_t i) const
Indexing.
GfVec2f operator-() const
Create a vec with negated elements.
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, like GfVec2i, GfVec4d, etc and false for all other types.
constexpr GfVec2f(float value)
Initialize all elements to a single value.
bool operator==(GfVec2f const &other) const
Equality comparison.
Basic type for a vector of 2 double components.
float ScalarType
Scalar element type and dimension.
float GetLength() const
Length.
GfVec2f()=default
Default constructor does no initialization.
GfVec2d GfGetNormalized(GfVec2d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec2f & operator-=(GfVec2f const &other)
Subtraction.
static GfVec2f XAxis()
Create a unit vector along the X-axis.
Basic type for a vector of 2 GfHalf components.
GfVec2f GetProjection(GfVec2f const &v) const
Returns the projection of this onto v.
decltype(std::declval< Left >()/std::declval< Right >()) GfCompDiv(Left left, Right right)
Returns component-wise quotient of vectors.
GfVec2f & Set(float const *a)
Set all elements with a pointer to data.
decltype(std::declval< Left >()*std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
friend size_t hash_value(GfVec2f const &vec)
Hash.
double GfNormalize(GfVec2d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization. ...
float Normalize(float eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfVec2f GetComplement(GfVec2f const &b) const
Returns the orthogonal complement of this->GetProjection(b).
float GetLengthSq() const
Squared length.
GfVec2f & Set(float s0, float s1)
Set all elements with passed arguments.
constexpr GfVec2f(float s0, float s1)
Initialize all elements with explicit arguments.
Basic type for a vector of 2 float components.
GfVec2f & operator+=(GfVec2f const &other)
Addition.
float operator*(GfVec2f const &v) const
See GfDot().
Defines useful mathematical limits.
double GfGetLength(GfVec2d const &v)
Returns the geometric length of v.
GfVec2d GfGetComplement(GfVec2d const &a, GfVec2d const &b)
Returns the orthogonal complement of a.GetProjection(b).
GfVec2f & operator*=(double s)
Multiplication by scalar.
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately...
static GfVec2f YAxis()
Create a unit vector along the Y-axis.