11#ifndef PXR_BASE_GF_VEC3H_H
12#define PXR_BASE_GF_VEC3H_H
18#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/traits.h"
32PXR_NAMESPACE_OPEN_SCOPE
52 static const size_t dimension = 3;
74 : x(value), y(value), z(value)
87 : x(p[0]), y(p[1]), z(p[2])
139 return Set(a[0], a[1], a[2]);
149 GfHalf const *GetArray()
const {
return data(); }
162 return x == other.x &&
166 bool operator!=(
GfVec3h const &other)
const {
167 return !(*
this == other);
215 GfVec3h operator*(
double s)
const {
228 return *
this *= (1.0 / s);
230 GfVec3h operator/(
double s)
const {
231 return *
this * (1.0 / s);
236 return x * v.x + y * v.y + z * v.z;
244 return v * (*
this * v);
258 return *
this * *
this;
278 *
this /= (length > eps) ? length : eps;
284 normalized.Normalize(eps);
300 const bool normalize,
309 GfHalf eps = 0.001)
const;
346 template <
class Vec = GfVec2h>
constexpr Vec xy()
const;
347 template <
class Vec = GfVec2h>
constexpr Vec xz()
const;
348 template <
class Vec = GfVec2h>
constexpr Vec yx()
const;
349 template <
class Vec = GfVec2h>
constexpr Vec yz()
const;
350 template <
class Vec = GfVec2h>
constexpr Vec zx()
const;
351 template <
class Vec = GfVec2h>
constexpr Vec zy()
const;
352 template <
class Vec = GfVec3h>
constexpr Vec xyz()
const;
353 template <
class Vec = GfVec3h>
constexpr Vec xzy()
const;
354 template <
class Vec = GfVec3h>
constexpr Vec yxz()
const;
355 template <
class Vec = GfVec3h>
constexpr Vec yzx()
const;
356 template <
class Vec = GfVec3h>
constexpr Vec zxy()
const;
357 template <
class Vec = GfVec3h>
constexpr Vec zyx()
const;
365PXR_NAMESPACE_CLOSE_SCOPE
375PXR_NAMESPACE_OPEN_SCOPE
403 static_assert(std::is_same<Vec, GfVec2h>::value);
411 static_assert(std::is_same<Vec, GfVec2h>::value);
419 static_assert(std::is_same<Vec, GfVec2h>::value);
427 static_assert(std::is_same<Vec, GfVec2h>::value);
435 static_assert(std::is_same<Vec, GfVec2h>::value);
443 static_assert(std::is_same<Vec, GfVec2h>::value);
451 static_assert(std::is_same<Vec, GfVec3h>::value);
459 static_assert(std::is_same<Vec, GfVec3h>::value);
467 static_assert(std::is_same<Vec, GfVec3h>::value);
475 static_assert(std::is_same<Vec, GfVec3h>::value);
483 static_assert(std::is_same<Vec, GfVec3h>::value);
491 static_assert(std::is_same<Vec, GfVec3h>::value);
545 return v.GetNormalized(eps);
574 return delta.
GetLengthSq() <= tolerance * tolerance;
583GfBuildOrthonormalFrame(
GfVec3h const &v0,
593 v1.y * v2.z - v1.z * v2.y,
594 v1.z * v2.x - v1.x * v2.z,
595 v1.x * v2.y - v1.y * v2.x);
612PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 2 GfHalf components.
Basic type for a vector of 3 double components.
Basic type for a vector of 3 float components.
Basic type for a vector of 3 GfHalf components.
GfVec3h & operator/=(double s)
Division by scalar.
GfHalf operator*(GfVec3h const &v) const
See GfDot().
GfHalf ScalarType
Scalar element type and dimension.
GfVec3h & operator-=(GfVec3h const &other)
Subtraction.
GfVec3h operator-() const
Create a vec with negated elements.
GfVec3h & operator*=(double s)
Multiplication by scalar.
GF_API bool operator==(class GfVec3d const &other) const
Equality comparison.
GfVec3h & operator+=(GfVec3h const &other)
Addition.
GF_API void BuildOrthonormalFrame(GfVec3h *v1, GfVec3h *v2, GfHalf eps=0.001) const
Sets v1 and v2 to unit vectors such that v1, v2 and *this are mutually orthogonal.
GfHalf GetLength() const
Length.
GF_API bool operator==(class GfVec3f const &other) const
Equality comparison.
static GF_API bool OrthogonalizeBasis(GfVec3h *tx, GfVec3h *ty, GfVec3h *tz, const bool normalize, double eps=GF_MIN_ORTHO_TOLERANCE)
Orthogonalize and optionally normalize a set of basis vectors.
GfVec3h & Set(GfHalf const *a)
Set all elements with a pointer to data.
GfVec3h GetComplement(GfVec3h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
constexpr GfVec3h(GfHalf value)
Initialize all elements to a single value.
friend size_t hash_value(GfVec3h const &vec)
Hash.
GfHalf Normalize(GfHalf eps=0.001)
Normalizes the vector in place to unit length, returning the length before normalization.
constexpr GfVec3h(Scl const *p)
Construct with pointer to values.
bool operator==(GfVec3h const &other) const
Equality comparison.
GfHalf GetLengthSq() const
Squared length.
static GfVec3h XAxis()
Create a unit vector along the X-axis.
GfVec3h()=default
GfVec3h value-initializes to zero and performs no default initialization, like float or double.
static GfVec3h ZAxis()
Create a unit vector along the Z-axis.
GfVec3h & Set(GfHalf s0, GfHalf s1, GfHalf s2)
Set all elements with passed arguments.
GfHalf const & operator[](size_t i) const
Indexing.
GfHalf const * data() const
Direct data access.
static GfVec3h YAxis()
Create a unit vector along the Y-axis.
GF_API bool operator==(class GfVec3i const &other) const
Equality comparison.
constexpr GfVec3h(GfHalf s0, GfHalf s1, GfHalf s2)
Initialize all elements with explicit arguments.
static GfVec3h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfVec3h GetProjection(GfVec3h const &v) const
Returns the projection of this onto v.
Basic type for a vector of 3 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 &, GfVec3h const &)
Output a GfVec3h.
#define GF_MIN_ORTHO_TOLERANCE
This constant is used to determine when a set of basis vectors is close to orthogonal.
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,...
GF_API GfVec3h GfSlerp(double alpha, GfVec3h const &v0, GfVec3h const &v1)
Spherical linear interpolation in three dimensions.
GfVec3h GfCompDiv(GfVec3h const &v1, GfVec3h const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfHalf GfGetLength(GfVec3h const &v)
Returns the geometric length of v.
GfVec3h GfGetProjection(GfVec3h const &a, GfVec3h const &b)
Returns the projection of a onto b.
GfVec3h GfGetNormalized(GfVec3h const &v, GfHalf eps=0.001)
Returns a normalized (unit-length) vector with the same direction as v.
GfHalf GfDot(GfVec3h const &v1, GfVec3h const &v2)
Returns the dot (inner) product of two vectors.
bool GfIsClose(GfVec3h const &v1, GfVec3h const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
GfVec3h GfGetComplement(GfVec3h const &a, GfVec3h const &b)
Returns the orthogonal complement of a.GetProjection(b).
GfVec3h operator^(GfVec3h const &v1, GfVec3h const &v2)
Returns the cross product of v1 and v2.
GfVec3h GfCompMult(GfVec3h const &v1, GfVec3h const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfVec3h GfCross(GfVec3h const &v1, GfVec3h const &v2)
Returns the cross product of v1 and v2.
GfHalf GfNormalize(GfVec3h *v, GfHalf eps=0.001)
Normalizes *v in place to unit length, returning the length before normalization.