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" 48 PXR_NAMESPACE_OPEN_SCOPE
68 static const size_t dimension = 2;
75 : _data{ value, value }
132 return Set(a[0], a[1]);
138 GfHalf const *GetArray()
const {
return data(); }
151 return _data[0] == other[0] &&
152 _data[1] == other[1];
154 bool operator!=(
GfVec2h const &other)
const {
155 return !(*
this == other);
171 return GfVec2h(-_data[0], -_data[1]);
176 _data[0] += other[0];
177 _data[1] += other[1];
186 _data[0] -= other[0];
187 _data[1] -= other[1];
200 GfVec2h operator*(
double s)
const {
213 return *
this *= (1.0 / s);
215 GfVec2h operator/(
double s)
const {
216 return *
this * (1.0 / s);
221 return _data[0] * v[0] + _data[1] * v[1];
229 return v * (*
this * v);
243 return *
this * *
this;
263 *
this /= (length > eps) ? length : eps;
269 normalized.Normalize(eps);
283 PXR_NAMESPACE_CLOSE_SCOPE
289 PXR_NAMESPACE_OPEN_SCOPE
357 return v.GetNormalized(eps);
386 return delta.
GetLengthSq() <= tolerance * tolerance;
391 PXR_NAMESPACE_CLOSE_SCOPE
393 #endif // PXR_BASE_GF_VEC2H_H GfVec2h GfCompDiv(GfVec2h const &v1, GfVec2h const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfVec2h & operator *=(double s)
Multiplication by scalar.
Basic type for a vector of 2 int components.
GfVec2h GetComplement(GfVec2h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
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.
GfVec2h GfGetNormalized(GfVec2h const &v, GfHalf eps=0.001)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec2h GfGetComplement(GfVec2h const &a, GfVec2h const &b)
Returns the orthogonal complement of a.GetProjection(b).
Low-level utilities for informing users of various internal and external diagnostic conditions.
bool GfIsClose(GfVec2h const &v1, GfVec2h const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
A metafunction with a static const bool member 'value' that is true for GfVec types,...
GfHalf GfGetLength(GfVec2h const &v)
Returns the geometric length of v.
Basic type for a vector of 2 double components.
GfVec2h & operator-=(GfVec2h const &other)
Subtraction.
GfHalf GetLength() const
Length.
bool operator==(GfVec2h const &other) const
Equality comparison.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
constexpr GfVec2h(GfHalf value)
Initialize all elements to a single value.
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.
GfHalf GfNormalize(GfVec2h *v, GfHalf eps=0.001)
Normalizes *v in place to unit length, returning the length before normalization.
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.
GF_API std::ostream & operator<<(std::ostream &, GfVec2h const &)
Output a GfVec2h.
friend size_t hash_value(GfVec2h const &vec)
Hash.
GfHalf const & operator[](size_t i) const
Indexing.
double GfSqrt(double f)
Return sqrt(f).
GfVec2h & Set(GfHalf const *a)
Set all elements with a pointer to data.
GfVec2h GfCompMult(GfVec2h const &v1, GfVec2h const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfVec2h & operator+=(GfVec2h const &other)
Addition.
static GfVec2h YAxis()
Create a unit vector along the Y-axis.
GfHalf GetLengthSq() const
Squared length.
Basic type for a vector of 2 float components.
GfVec2h GetProjection(GfVec2h const &v) const
Returns the projection of this onto v.
Defines useful mathematical limits.
GfHalf const * data() const
Direct data access.
constexpr GfVec2h(GfHalf s0, GfHalf s1)
Initialize all elements with explicit arguments.
GfHalf ScalarType
Scalar element type and dimension.
GfVec2h operator-() const
Create a vec with negated elements.
GfHalf GfDot(GfVec2h const &v1, GfVec2h const &v2)
Returns the dot (inner) product of two vectors.
GfVec2h GfGetProjection(GfVec2h const &a, GfVec2h const &b)
Returns the projection of a onto b.
GfVec2h & Set(GfHalf s0, GfHalf s1)
Set all elements with passed arguments.