11#ifndef PXR_BASE_GF_VEC2H_H
12#define PXR_BASE_GF_VEC2H_H
18#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/traits.h"
32PXR_NAMESPACE_OPEN_SCOPE
51 static const size_t dimension = 2;
130 return Set(a[0], a[1]);
140 GfHalf const *GetArray()
const {
return data(); }
153 return x == other.x &&
156 bool operator!=(
GfVec2h const &other)
const {
157 return !(*
this == other);
202 GfVec2h operator*(
double s)
const {
215 return *
this *= (1.0 / s);
217 GfVec2h operator/(
double s)
const {
218 return *
this * (1.0 / s);
223 return x * v.x + y * v.y;
231 return v * (*
this * v);
245 return *
this * *
this;
265 *
this /= (length > eps) ? length : eps;
271 normalized.Normalize(eps);
300 template <
class Vec = GfVec2h>
constexpr Vec xy()
const;
301 template <
class Vec = GfVec2h>
constexpr Vec yx()
const;
309PXR_NAMESPACE_CLOSE_SCOPE
316PXR_NAMESPACE_OPEN_SCOPE
341 static_assert(std::is_same<Vec, GfVec2h>::value);
349 static_assert(std::is_same<Vec, GfVec2h>::value);
401 return v.GetNormalized(eps);
430 return delta.
GetLengthSq() <= tolerance * tolerance;
435PXR_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.
Basic type for a vector of 2 GfHalf components.
static GfVec2h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfHalf ScalarType
Scalar element type and dimension.
GfVec2h()=default
GfVec2h value-initializes to zero and performs no default initialization, like float or double.
constexpr GfVec2h(Scl const *p)
Construct with pointer to values.
GfHalf GetLength() const
Length.
GfVec2h operator-() const
Create a vec with negated elements.
GfVec2h & Set(GfHalf const *a)
Set all elements with a pointer to data.
GfVec2h & operator-=(GfVec2h const &other)
Subtraction.
constexpr GfVec2h(GfHalf s0, GfHalf s1)
Initialize all elements with explicit arguments.
GfVec2h & operator/=(double s)
Division by scalar.
GfHalf operator*(GfVec2h const &v) const
See GfDot().
bool operator==(GfVec2h const &other) const
Equality comparison.
GfHalf Normalize(GfHalf eps=0.001)
Normalizes the vector in place to unit length, returning the length before normalization.
GfVec2h & operator*=(double s)
Multiplication by scalar.
GfHalf GetLengthSq() const
Squared length.
GF_API bool operator==(class GfVec2f const &other) const
Equality comparison.
GfHalf const & operator[](size_t i) const
Indexing.
GF_API bool operator==(class GfVec2d const &other) const
Equality comparison.
GfHalf const * data() const
Direct data access.
static GfVec2h YAxis()
Create a unit vector along the Y-axis.
GfVec2h & operator+=(GfVec2h const &other)
Addition.
friend size_t hash_value(GfVec2h const &vec)
Hash.
GfVec2h GetComplement(GfVec2h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
static GfVec2h XAxis()
Create a unit vector along the X-axis.
constexpr GfVec2h(GfHalf value)
Initialize all elements to a single value.
GfVec2h GetProjection(GfVec2h const &v) const
Returns the projection of this onto v.
GF_API bool operator==(class GfVec2i const &other) const
Equality comparison.
GfVec2h & Set(GfHalf s0, GfHalf s1)
Set all elements with passed arguments.
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).
GF_API std::ostream & operator<<(std::ostream &, GfVec2h const &)
Output a GfVec2h.
This header serves to simply bring in the half float datatype and provide a hash_value function.
pxr_half::half GfHalf
A 16-bit floating point data type.
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
GfHalf GfNormalize(GfVec2h *v, GfHalf eps=0.001)
Normalizes *v in place to unit length, returning the length before normalization.
GfVec2h GfGetProjection(GfVec2h const &a, GfVec2h const &b)
Returns the projection of a onto b.
GfHalf GfGetLength(GfVec2h const &v)
Returns the geometric length of v.
GfHalf GfDot(GfVec2h const &v1, GfVec2h const &v2)
Returns the dot (inner) product of two vectors.
GfVec2h GfCompMult(GfVec2h const &v1, GfVec2h const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfVec2h GfCompDiv(GfVec2h const &v1, GfVec2h const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfVec2h GfGetNormalized(GfVec2h const &v, GfHalf eps=0.001)
Returns a normalized (unit-length) vector with the same direction as v.
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...
GfVec2h GfGetComplement(GfVec2h const &a, GfVec2h const &b)
Returns the orthogonal complement of a.GetProjection(b).