11#ifndef PXR_BASE_GF_VEC2H_H
12#define PXR_BASE_GF_VEC2H_H
19#include "pxr/base/gf/api.h"
21#include "pxr/base/gf/traits.h"
31PXR_NAMESPACE_OPEN_SCOPE
51 static const size_t dimension = 2;
58 : _data{ value, value }
115 return Set(a[0], a[1]);
121 GfHalf const *GetArray()
const {
return data(); }
134 return _data[0] == other[0] &&
135 _data[1] == other[1];
137 bool operator!=(
GfVec2h const &other)
const {
138 return !(*
this == other);
154 return GfVec2h(-_data[0], -_data[1]);
159 _data[0] += other[0];
160 _data[1] += other[1];
169 _data[0] -= other[0];
170 _data[1] -= other[1];
183 GfVec2h operator*(
double s)
const {
196 return *
this *= (1.0 / s);
198 GfVec2h operator/(
double s)
const {
199 return *
this * (1.0 / s);
204 return _data[0] * v[0] + _data[1] * v[1];
212 return v * (*
this * v);
226 return *
this * *
this;
246 *
this /= (length > eps) ? length : eps;
252 normalized.Normalize(eps);
266PXR_NAMESPACE_CLOSE_SCOPE
272PXR_NAMESPACE_OPEN_SCOPE
340 return v.GetNormalized(eps);
369 return delta.
GetLengthSq() <= tolerance * tolerance;
374PXR_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.
GfVec2h()=default
Default constructor does no initialization.
constexpr GfVec2h(Scl const *p)
Construct with pointer to values.
GfHalf GetLength() const
Length.
GfVec2h operator-() const
Create a vec with negated elements.
GfHalf ScalarType
Scalar element type and dimension.
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 &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
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).