28 #ifndef PXR_BASE_GF_VEC2H_H
29 #define PXR_BASE_GF_VEC2H_H
36 #include "pxr/base/gf/api.h"
38 #include "pxr/base/gf/traits.h"
42 #include <boost/functional/hash.hpp>
49 PXR_NAMESPACE_OPEN_SCOPE
69 static const size_t dimension = 2;
76 : _data{ value, value }
133 return Set(a[0], a[1]);
139 GfHalf const *GetArray()
const {
return data(); }
148 boost::hash_combine(h, vec[0]);
149 boost::hash_combine(h, vec[1]);
155 return _data[0] == other[0] &&
156 _data[1] == other[1];
158 bool operator!=(
GfVec2h const &other)
const {
159 return !(*
this == other);
175 return GfVec2h(-_data[0], -_data[1]);
180 _data[0] += other[0];
181 _data[1] += other[1];
190 _data[0] -= other[0];
191 _data[1] -= other[1];
204 GfVec2h operator*(
double s)
const {
217 return *
this *= (1.0 / s);
219 GfVec2h operator/(
double s)
const {
220 return *
this * (1.0 / s);
225 return _data[0] * v[0] + _data[1] * v[1];
233 return v * (*
this * v);
247 return *
this * *
this;
268 *
this /= (length > eps) ? length : eps;
274 normalized.Normalize(eps);
288 PXR_NAMESPACE_CLOSE_SCOPE
294 PXR_NAMESPACE_OPEN_SCOPE
362 return v.GetNormalized(eps);
391 return delta.
GetLengthSq() <= tolerance * tolerance;
396 PXR_NAMESPACE_CLOSE_SCOPE
398 #endif // PXR_BASE_GF_VEC2H_H
GfVec2d GfGetProjection(GfVec2d const &a, GfVec2d const &b)
Returns the projection of a onto b.
bool operator==(GfVec2h const &other) const
Equality comparison.
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.
decltype(std::declval< Left >()*std::declval< Right >()) GfCompMult(Left left, Right right)
Returns component-wise multiplication of vectors.
pxr_half::half GfHalf
A 16-bit floating point data type.
Assorted mathematical utility functions.
This header serves to simply bring in the half float datatype and provide a hash_value function...
GfVec2h()=default
Default constructor does no initialization.
GfVec2h & operator/=(double s)
Division by scalar.
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.
GfHalf GetLength() const
Length.
Basic type for a vector of 2 double components.
GfHalf GetLengthSq() const
Squared length.
GfVec2h & operator-=(GfVec2h const &other)
Subtraction.
constexpr GfVec2h(GfHalf value)
Initialize all elements to a single value.
GfVec2d GfGetNormalized(GfVec2d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec2h operator-() const
Create a vec with negated elements.
GfHalf Normalize(GfHalf eps=0.001)
Normalizes the vector in place to unit length, returning the length before normalization.
Basic type for a vector of 2 GfHalf components.
constexpr GfVec2h(Scl const *p)
Construct with pointer to values.
decltype(std::declval< Left >()/std::declval< Right >()) GfCompDiv(Left left, Right right)
Returns component-wise quotient of vectors.
GfHalf const * data() const
Direct data access.
static GfVec2h XAxis()
Create a unit vector along the X-axis.
static GfVec2h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
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(GfVec2h 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. ...
GfHalf const & operator[](size_t i) const
Indexing.
GfVec2h & Set(GfHalf const *a)
Set all elements with a pointer to data.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfVec2h GetProjection(GfVec2h const &v) const
Returns the projection of this onto v.
GfVec2h GetComplement(GfVec2h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
GfHalf operator*(GfVec2h const &v) const
See GfDot().
GfVec2h & operator+=(GfVec2h const &other)
Addition.
static GfVec2h YAxis()
Create a unit vector along the Y-axis.
GfVec2h & operator*=(double s)
Multiplication by scalar.
Basic type for a vector of 2 float components.
Defines useful mathematical limits.
constexpr GfVec2h(GfHalf s0, GfHalf s1)
Initialize all elements with explicit arguments.
GfHalf ScalarType
Scalar element type and dimension.
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).
GfVec2h & Set(GfHalf s0, GfHalf s1)
Set all elements with passed arguments.