11#ifndef PXR_BASE_GF_VEC4H_H
12#define PXR_BASE_GF_VEC4H_H
18#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/traits.h"
32PXR_NAMESPACE_OPEN_SCOPE
53 static const size_t dimension = 4;
75 : x(value), y(value), z(value), w(value)
81 : x(s0), y(s1), z(s2), w(s3)
88 : x(p[0]), y(p[1]), z(p[2]), w(p[3])
148 return Set(a[0], a[1], a[2], a[3]);
158 GfHalf const *GetArray()
const {
return data(); }
171 return x == other.x &&
176 bool operator!=(
GfVec4h const &other)
const {
177 return !(*
this == other);
193 return GfVec4h(-x, -y, -z, -w);
228 GfVec4h operator*(
double s)
const {
241 return *
this *= (1.0 / s);
243 GfVec4h operator/(
double s)
const {
244 return *
this * (1.0 / s);
249 return x * v.x + y * v.y + z * v.z + w * v.w;
257 return v * (*
this * v);
271 return *
this * *
this;
291 *
this /= (length > eps) ? length : eps;
297 normalized.Normalize(eps);
354 constexpr GfVec4h xyzw()
const;
355 constexpr GfVec4h xywz()
const;
356 constexpr GfVec4h xzyw()
const;
357 constexpr GfVec4h xzwy()
const;
358 constexpr GfVec4h xwyz()
const;
359 constexpr GfVec4h xwzy()
const;
360 constexpr GfVec4h yxzw()
const;
361 constexpr GfVec4h yxwz()
const;
362 constexpr GfVec4h yzxw()
const;
363 constexpr GfVec4h yzwx()
const;
364 constexpr GfVec4h ywxz()
const;
365 constexpr GfVec4h ywzx()
const;
366 constexpr GfVec4h zxyw()
const;
367 constexpr GfVec4h zxwy()
const;
368 constexpr GfVec4h zyxw()
const;
369 constexpr GfVec4h zywx()
const;
370 constexpr GfVec4h zwxy()
const;
371 constexpr GfVec4h zwyx()
const;
372 constexpr GfVec4h wxyz()
const;
373 constexpr GfVec4h wxzy()
const;
374 constexpr GfVec4h wyxz()
const;
375 constexpr GfVec4h wyzx()
const;
376 constexpr GfVec4h wzxy()
const;
377 constexpr GfVec4h wzyx()
const;
384 template <
class Vec = GfVec2h>
constexpr Vec xy()
const;
385 template <
class Vec = GfVec2h>
constexpr Vec xz()
const;
386 template <
class Vec = GfVec2h>
constexpr Vec xw()
const;
387 template <
class Vec = GfVec2h>
constexpr Vec yx()
const;
388 template <
class Vec = GfVec2h>
constexpr Vec yz()
const;
389 template <
class Vec = GfVec2h>
constexpr Vec yw()
const;
390 template <
class Vec = GfVec2h>
constexpr Vec zx()
const;
391 template <
class Vec = GfVec2h>
constexpr Vec zy()
const;
392 template <
class Vec = GfVec2h>
constexpr Vec zw()
const;
393 template <
class Vec = GfVec2h>
constexpr Vec wx()
const;
394 template <
class Vec = GfVec2h>
constexpr Vec wy()
const;
395 template <
class Vec = GfVec2h>
constexpr Vec wz()
const;
396 template <
class Vec = GfVec3h>
constexpr Vec xyz()
const;
397 template <
class Vec = GfVec3h>
constexpr Vec xyw()
const;
398 template <
class Vec = GfVec3h>
constexpr Vec xzy()
const;
399 template <
class Vec = GfVec3h>
constexpr Vec xzw()
const;
400 template <
class Vec = GfVec3h>
constexpr Vec xwy()
const;
401 template <
class Vec = GfVec3h>
constexpr Vec xwz()
const;
402 template <
class Vec = GfVec3h>
constexpr Vec yxz()
const;
403 template <
class Vec = GfVec3h>
constexpr Vec yxw()
const;
404 template <
class Vec = GfVec3h>
constexpr Vec yzx()
const;
405 template <
class Vec = GfVec3h>
constexpr Vec yzw()
const;
406 template <
class Vec = GfVec3h>
constexpr Vec ywx()
const;
407 template <
class Vec = GfVec3h>
constexpr Vec ywz()
const;
408 template <
class Vec = GfVec3h>
constexpr Vec zxy()
const;
409 template <
class Vec = GfVec3h>
constexpr Vec zxw()
const;
410 template <
class Vec = GfVec3h>
constexpr Vec zyx()
const;
411 template <
class Vec = GfVec3h>
constexpr Vec zyw()
const;
412 template <
class Vec = GfVec3h>
constexpr Vec zwx()
const;
413 template <
class Vec = GfVec3h>
constexpr Vec zwy()
const;
414 template <
class Vec = GfVec3h>
constexpr Vec wxy()
const;
415 template <
class Vec = GfVec3h>
constexpr Vec wxz()
const;
416 template <
class Vec = GfVec3h>
constexpr Vec wyx()
const;
417 template <
class Vec = GfVec3h>
constexpr Vec wyz()
const;
418 template <
class Vec = GfVec3h>
constexpr Vec wzx()
const;
419 template <
class Vec = GfVec3h>
constexpr Vec wzy()
const;
420 template <
class Vec = GfVec4h>
constexpr Vec xyzw()
const;
421 template <
class Vec = GfVec4h>
constexpr Vec xywz()
const;
422 template <
class Vec = GfVec4h>
constexpr Vec xzyw()
const;
423 template <
class Vec = GfVec4h>
constexpr Vec xzwy()
const;
424 template <
class Vec = GfVec4h>
constexpr Vec xwyz()
const;
425 template <
class Vec = GfVec4h>
constexpr Vec xwzy()
const;
426 template <
class Vec = GfVec4h>
constexpr Vec yxzw()
const;
427 template <
class Vec = GfVec4h>
constexpr Vec yxwz()
const;
428 template <
class Vec = GfVec4h>
constexpr Vec yzxw()
const;
429 template <
class Vec = GfVec4h>
constexpr Vec yzwx()
const;
430 template <
class Vec = GfVec4h>
constexpr Vec ywxz()
const;
431 template <
class Vec = GfVec4h>
constexpr Vec ywzx()
const;
432 template <
class Vec = GfVec4h>
constexpr Vec zxyw()
const;
433 template <
class Vec = GfVec4h>
constexpr Vec zxwy()
const;
434 template <
class Vec = GfVec4h>
constexpr Vec zyxw()
const;
435 template <
class Vec = GfVec4h>
constexpr Vec zywx()
const;
436 template <
class Vec = GfVec4h>
constexpr Vec zwxy()
const;
437 template <
class Vec = GfVec4h>
constexpr Vec zwyx()
const;
438 template <
class Vec = GfVec4h>
constexpr Vec wxyz()
const;
439 template <
class Vec = GfVec4h>
constexpr Vec wxzy()
const;
440 template <
class Vec = GfVec4h>
constexpr Vec wyxz()
const;
441 template <
class Vec = GfVec4h>
constexpr Vec wyzx()
const;
442 template <
class Vec = GfVec4h>
constexpr Vec wzxy()
const;
443 template <
class Vec = GfVec4h>
constexpr Vec wzyx()
const;
451PXR_NAMESPACE_CLOSE_SCOPE
462PXR_NAMESPACE_OPEN_SCOPE
493 static_assert(std::is_same<Vec, GfVec2h>::value);
501 static_assert(std::is_same<Vec, GfVec2h>::value);
509 static_assert(std::is_same<Vec, GfVec2h>::value);
517 static_assert(std::is_same<Vec, GfVec2h>::value);
525 static_assert(std::is_same<Vec, GfVec2h>::value);
533 static_assert(std::is_same<Vec, GfVec2h>::value);
541 static_assert(std::is_same<Vec, GfVec2h>::value);
549 static_assert(std::is_same<Vec, GfVec2h>::value);
557 static_assert(std::is_same<Vec, GfVec2h>::value);
565 static_assert(std::is_same<Vec, GfVec2h>::value);
573 static_assert(std::is_same<Vec, GfVec2h>::value);
581 static_assert(std::is_same<Vec, GfVec2h>::value);
589 static_assert(std::is_same<Vec, GfVec3h>::value);
597 static_assert(std::is_same<Vec, GfVec3h>::value);
605 static_assert(std::is_same<Vec, GfVec3h>::value);
613 static_assert(std::is_same<Vec, GfVec3h>::value);
621 static_assert(std::is_same<Vec, GfVec3h>::value);
629 static_assert(std::is_same<Vec, GfVec3h>::value);
637 static_assert(std::is_same<Vec, GfVec3h>::value);
645 static_assert(std::is_same<Vec, GfVec3h>::value);
653 static_assert(std::is_same<Vec, GfVec3h>::value);
661 static_assert(std::is_same<Vec, GfVec3h>::value);
669 static_assert(std::is_same<Vec, GfVec3h>::value);
677 static_assert(std::is_same<Vec, GfVec3h>::value);
685 static_assert(std::is_same<Vec, GfVec3h>::value);
693 static_assert(std::is_same<Vec, GfVec3h>::value);
701 static_assert(std::is_same<Vec, GfVec3h>::value);
709 static_assert(std::is_same<Vec, GfVec3h>::value);
717 static_assert(std::is_same<Vec, GfVec3h>::value);
725 static_assert(std::is_same<Vec, GfVec3h>::value);
733 static_assert(std::is_same<Vec, GfVec3h>::value);
741 static_assert(std::is_same<Vec, GfVec3h>::value);
749 static_assert(std::is_same<Vec, GfVec3h>::value);
757 static_assert(std::is_same<Vec, GfVec3h>::value);
765 static_assert(std::is_same<Vec, GfVec3h>::value);
773 static_assert(std::is_same<Vec, GfVec3h>::value);
781 static_assert(std::is_same<Vec, GfVec4h>::value);
782 return Vec(x, y, z, w);
789 static_assert(std::is_same<Vec, GfVec4h>::value);
790 return Vec(x, y, w, z);
797 static_assert(std::is_same<Vec, GfVec4h>::value);
798 return Vec(x, z, y, w);
805 static_assert(std::is_same<Vec, GfVec4h>::value);
806 return Vec(x, z, w, y);
813 static_assert(std::is_same<Vec, GfVec4h>::value);
814 return Vec(x, w, y, z);
821 static_assert(std::is_same<Vec, GfVec4h>::value);
822 return Vec(x, w, z, y);
829 static_assert(std::is_same<Vec, GfVec4h>::value);
830 return Vec(y, x, z, w);
837 static_assert(std::is_same<Vec, GfVec4h>::value);
838 return Vec(y, x, w, z);
845 static_assert(std::is_same<Vec, GfVec4h>::value);
846 return Vec(y, z, x, w);
853 static_assert(std::is_same<Vec, GfVec4h>::value);
854 return Vec(y, z, w, x);
861 static_assert(std::is_same<Vec, GfVec4h>::value);
862 return Vec(y, w, x, z);
869 static_assert(std::is_same<Vec, GfVec4h>::value);
870 return Vec(y, w, z, x);
877 static_assert(std::is_same<Vec, GfVec4h>::value);
878 return Vec(z, x, y, w);
885 static_assert(std::is_same<Vec, GfVec4h>::value);
886 return Vec(z, x, w, y);
893 static_assert(std::is_same<Vec, GfVec4h>::value);
894 return Vec(z, y, x, w);
901 static_assert(std::is_same<Vec, GfVec4h>::value);
902 return Vec(z, y, w, x);
909 static_assert(std::is_same<Vec, GfVec4h>::value);
910 return Vec(z, w, x, y);
917 static_assert(std::is_same<Vec, GfVec4h>::value);
918 return Vec(z, w, y, x);
925 static_assert(std::is_same<Vec, GfVec4h>::value);
926 return Vec(w, x, y, z);
933 static_assert(std::is_same<Vec, GfVec4h>::value);
934 return Vec(w, x, z, y);
941 static_assert(std::is_same<Vec, GfVec4h>::value);
942 return Vec(w, y, x, z);
949 static_assert(std::is_same<Vec, GfVec4h>::value);
950 return Vec(w, y, z, x);
957 static_assert(std::is_same<Vec, GfVec4h>::value);
958 return Vec(w, z, x, y);
965 static_assert(std::is_same<Vec, GfVec4h>::value);
966 return Vec(w, z, y, x);
1021 return v.GetNormalized(eps);
1050 return delta.
GetLengthSq() <= tolerance * tolerance;
1055PXR_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 GfHalf components.
Basic type for a vector of 4 double components.
Basic type for a vector of 4 float components.
Basic type for a vector of 4 GfHalf components.
GfVec4h GetComplement(GfVec4h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
static GfVec4h ZAxis()
Create a unit vector along the Z-axis.
GfHalf ScalarType
Scalar element type and dimension.
GfVec4h & operator-=(GfVec4h const &other)
Subtraction.
static GfVec4h YAxis()
Create a unit vector along the Y-axis.
static GfVec4h WAxis()
Create a unit vector along the W-axis.
GfHalf GetLength() const
Length.
GfHalf operator*(GfVec4h const &v) const
See GfDot().
constexpr GfVec4h(Scl const *p)
Construct with pointer to values.
GfVec4h operator-() const
Create a vec with negated elements.
GfVec4h & Set(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3)
Set all elements with passed arguments.
constexpr GfVec4h(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3)
Initialize all elements with explicit arguments.
GfHalf Normalize(GfHalf eps=0.001)
Normalizes the vector in place to unit length, returning the length before normalization.
GfVec4h()=default
GfVec4h value-initializes to zero and performs no default initialization, like float or double.
friend size_t hash_value(GfVec4h const &vec)
Hash.
GfVec4h & operator/=(double s)
Division by scalar.
GfHalf GetLengthSq() const
Squared length.
GF_API bool operator==(class GfVec4f const &other) const
Equality comparison.
GfVec4h & Set(GfHalf const *a)
Set all elements with a pointer to data.
GF_API bool operator==(class GfVec4i const &other) const
Equality comparison.
GfHalf const & operator[](size_t i) const
Indexing.
GfHalf const * data() const
Direct data access.
GF_API bool operator==(class GfVec4d const &other) const
Equality comparison.
GfVec4h & operator*=(double s)
Multiplication by scalar.
static GfVec4h XAxis()
Create a unit vector along the X-axis.
GfVec4h GetProjection(GfVec4h const &v) const
Returns the projection of this onto v.
GfVec4h & operator+=(GfVec4h const &other)
Addition.
bool operator==(GfVec4h const &other) const
Equality comparison.
static GfVec4h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
constexpr GfVec4h(GfHalf value)
Initialize all elements to a single value.
Basic type for a vector of 4 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 &, GfVec4h const &)
Output a GfVec4h.
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,...
GfVec4h GfGetComplement(GfVec4h const &a, GfVec4h const &b)
Returns the orthogonal complement of a.GetProjection(b).
bool GfIsClose(GfVec4h const &v1, GfVec4h const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
GfHalf GfNormalize(GfVec4h *v, GfHalf eps=0.001)
Normalizes *v in place to unit length, returning the length before normalization.
GfVec4h GfCompDiv(GfVec4h const &v1, GfVec4h const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfHalf GfDot(GfVec4h const &v1, GfVec4h const &v2)
Returns the dot (inner) product of two vectors.
GfVec4h GfGetNormalized(GfVec4h const &v, GfHalf eps=0.001)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec4h GfCompMult(GfVec4h const &v1, GfVec4h const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfVec4h GfGetProjection(GfVec4h const &a, GfVec4h const &b)
Returns the projection of a onto b.
GfHalf GfGetLength(GfVec4h const &v)
Returns the geometric length of v.