11#ifndef PXR_BASE_GF_VEC4D_H
12#define PXR_BASE_GF_VEC4D_H
18#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/traits.h"
31PXR_NAMESPACE_OPEN_SCOPE
52 static const size_t dimension = 4;
74 : x(value), y(value), z(value), w(value)
79 constexpr GfVec4d(
double s0,
double s1,
double s2,
double s3)
80 : x(s0), y(s1), z(s2), w(s3)
87 : x(p[0]), y(p[1]), z(p[2]), w(p[3])
147 return Set(a[0], a[1], a[2], a[3]);
155 double const *
data()
const {
return &x; }
156 double *
data() {
return &x; }
157 double const *GetArray()
const {
return data(); }
170 return x == other.x &&
175 bool operator!=(
GfVec4d const &other)
const {
176 return !(*
this == other);
192 return GfVec4d(-x, -y, -z, -w);
227 GfVec4d operator*(
double s)
const {
240 return *
this *= (1.0 / s);
242 GfVec4d operator/(
double s)
const {
243 return *
this * (1.0 / s);
248 return x * v.x + y * v.y + z * v.z + w * v.w;
256 return v * (*
this * v);
270 return *
this * *
this;
290 *
this /= (length > eps) ? length : eps;
296 normalized.Normalize(eps);
353 constexpr GfVec4d xyzw()
const;
354 constexpr GfVec4d xywz()
const;
355 constexpr GfVec4d xzyw()
const;
356 constexpr GfVec4d xzwy()
const;
357 constexpr GfVec4d xwyz()
const;
358 constexpr GfVec4d xwzy()
const;
359 constexpr GfVec4d yxzw()
const;
360 constexpr GfVec4d yxwz()
const;
361 constexpr GfVec4d yzxw()
const;
362 constexpr GfVec4d yzwx()
const;
363 constexpr GfVec4d ywxz()
const;
364 constexpr GfVec4d ywzx()
const;
365 constexpr GfVec4d zxyw()
const;
366 constexpr GfVec4d zxwy()
const;
367 constexpr GfVec4d zyxw()
const;
368 constexpr GfVec4d zywx()
const;
369 constexpr GfVec4d zwxy()
const;
370 constexpr GfVec4d zwyx()
const;
371 constexpr GfVec4d wxyz()
const;
372 constexpr GfVec4d wxzy()
const;
373 constexpr GfVec4d wyxz()
const;
374 constexpr GfVec4d wyzx()
const;
375 constexpr GfVec4d wzxy()
const;
376 constexpr GfVec4d wzyx()
const;
383 template <
class Vec = GfVec2d>
constexpr Vec xy()
const;
384 template <
class Vec = GfVec2d>
constexpr Vec xz()
const;
385 template <
class Vec = GfVec2d>
constexpr Vec xw()
const;
386 template <
class Vec = GfVec2d>
constexpr Vec yx()
const;
387 template <
class Vec = GfVec2d>
constexpr Vec yz()
const;
388 template <
class Vec = GfVec2d>
constexpr Vec yw()
const;
389 template <
class Vec = GfVec2d>
constexpr Vec zx()
const;
390 template <
class Vec = GfVec2d>
constexpr Vec zy()
const;
391 template <
class Vec = GfVec2d>
constexpr Vec zw()
const;
392 template <
class Vec = GfVec2d>
constexpr Vec wx()
const;
393 template <
class Vec = GfVec2d>
constexpr Vec wy()
const;
394 template <
class Vec = GfVec2d>
constexpr Vec wz()
const;
395 template <
class Vec = GfVec3d>
constexpr Vec xyz()
const;
396 template <
class Vec = GfVec3d>
constexpr Vec xyw()
const;
397 template <
class Vec = GfVec3d>
constexpr Vec xzy()
const;
398 template <
class Vec = GfVec3d>
constexpr Vec xzw()
const;
399 template <
class Vec = GfVec3d>
constexpr Vec xwy()
const;
400 template <
class Vec = GfVec3d>
constexpr Vec xwz()
const;
401 template <
class Vec = GfVec3d>
constexpr Vec yxz()
const;
402 template <
class Vec = GfVec3d>
constexpr Vec yxw()
const;
403 template <
class Vec = GfVec3d>
constexpr Vec yzx()
const;
404 template <
class Vec = GfVec3d>
constexpr Vec yzw()
const;
405 template <
class Vec = GfVec3d>
constexpr Vec ywx()
const;
406 template <
class Vec = GfVec3d>
constexpr Vec ywz()
const;
407 template <
class Vec = GfVec3d>
constexpr Vec zxy()
const;
408 template <
class Vec = GfVec3d>
constexpr Vec zxw()
const;
409 template <
class Vec = GfVec3d>
constexpr Vec zyx()
const;
410 template <
class Vec = GfVec3d>
constexpr Vec zyw()
const;
411 template <
class Vec = GfVec3d>
constexpr Vec zwx()
const;
412 template <
class Vec = GfVec3d>
constexpr Vec zwy()
const;
413 template <
class Vec = GfVec3d>
constexpr Vec wxy()
const;
414 template <
class Vec = GfVec3d>
constexpr Vec wxz()
const;
415 template <
class Vec = GfVec3d>
constexpr Vec wyx()
const;
416 template <
class Vec = GfVec3d>
constexpr Vec wyz()
const;
417 template <
class Vec = GfVec3d>
constexpr Vec wzx()
const;
418 template <
class Vec = GfVec3d>
constexpr Vec wzy()
const;
419 template <
class Vec = GfVec4d>
constexpr Vec xyzw()
const;
420 template <
class Vec = GfVec4d>
constexpr Vec xywz()
const;
421 template <
class Vec = GfVec4d>
constexpr Vec xzyw()
const;
422 template <
class Vec = GfVec4d>
constexpr Vec xzwy()
const;
423 template <
class Vec = GfVec4d>
constexpr Vec xwyz()
const;
424 template <
class Vec = GfVec4d>
constexpr Vec xwzy()
const;
425 template <
class Vec = GfVec4d>
constexpr Vec yxzw()
const;
426 template <
class Vec = GfVec4d>
constexpr Vec yxwz()
const;
427 template <
class Vec = GfVec4d>
constexpr Vec yzxw()
const;
428 template <
class Vec = GfVec4d>
constexpr Vec yzwx()
const;
429 template <
class Vec = GfVec4d>
constexpr Vec ywxz()
const;
430 template <
class Vec = GfVec4d>
constexpr Vec ywzx()
const;
431 template <
class Vec = GfVec4d>
constexpr Vec zxyw()
const;
432 template <
class Vec = GfVec4d>
constexpr Vec zxwy()
const;
433 template <
class Vec = GfVec4d>
constexpr Vec zyxw()
const;
434 template <
class Vec = GfVec4d>
constexpr Vec zywx()
const;
435 template <
class Vec = GfVec4d>
constexpr Vec zwxy()
const;
436 template <
class Vec = GfVec4d>
constexpr Vec zwyx()
const;
437 template <
class Vec = GfVec4d>
constexpr Vec wxyz()
const;
438 template <
class Vec = GfVec4d>
constexpr Vec wxzy()
const;
439 template <
class Vec = GfVec4d>
constexpr Vec wyxz()
const;
440 template <
class Vec = GfVec4d>
constexpr Vec wyzx()
const;
441 template <
class Vec = GfVec4d>
constexpr Vec wzxy()
const;
442 template <
class Vec = GfVec4d>
constexpr Vec wzyx()
const;
450PXR_NAMESPACE_CLOSE_SCOPE
461PXR_NAMESPACE_OPEN_SCOPE
492 static_assert(std::is_same<Vec, GfVec2d>::value);
500 static_assert(std::is_same<Vec, GfVec2d>::value);
508 static_assert(std::is_same<Vec, GfVec2d>::value);
516 static_assert(std::is_same<Vec, GfVec2d>::value);
524 static_assert(std::is_same<Vec, GfVec2d>::value);
532 static_assert(std::is_same<Vec, GfVec2d>::value);
540 static_assert(std::is_same<Vec, GfVec2d>::value);
548 static_assert(std::is_same<Vec, GfVec2d>::value);
556 static_assert(std::is_same<Vec, GfVec2d>::value);
564 static_assert(std::is_same<Vec, GfVec2d>::value);
572 static_assert(std::is_same<Vec, GfVec2d>::value);
580 static_assert(std::is_same<Vec, GfVec2d>::value);
588 static_assert(std::is_same<Vec, GfVec3d>::value);
596 static_assert(std::is_same<Vec, GfVec3d>::value);
604 static_assert(std::is_same<Vec, GfVec3d>::value);
612 static_assert(std::is_same<Vec, GfVec3d>::value);
620 static_assert(std::is_same<Vec, GfVec3d>::value);
628 static_assert(std::is_same<Vec, GfVec3d>::value);
636 static_assert(std::is_same<Vec, GfVec3d>::value);
644 static_assert(std::is_same<Vec, GfVec3d>::value);
652 static_assert(std::is_same<Vec, GfVec3d>::value);
660 static_assert(std::is_same<Vec, GfVec3d>::value);
668 static_assert(std::is_same<Vec, GfVec3d>::value);
676 static_assert(std::is_same<Vec, GfVec3d>::value);
684 static_assert(std::is_same<Vec, GfVec3d>::value);
692 static_assert(std::is_same<Vec, GfVec3d>::value);
700 static_assert(std::is_same<Vec, GfVec3d>::value);
708 static_assert(std::is_same<Vec, GfVec3d>::value);
716 static_assert(std::is_same<Vec, GfVec3d>::value);
724 static_assert(std::is_same<Vec, GfVec3d>::value);
732 static_assert(std::is_same<Vec, GfVec3d>::value);
740 static_assert(std::is_same<Vec, GfVec3d>::value);
748 static_assert(std::is_same<Vec, GfVec3d>::value);
756 static_assert(std::is_same<Vec, GfVec3d>::value);
764 static_assert(std::is_same<Vec, GfVec3d>::value);
772 static_assert(std::is_same<Vec, GfVec3d>::value);
780 static_assert(std::is_same<Vec, GfVec4d>::value);
781 return Vec(x, y, z, w);
788 static_assert(std::is_same<Vec, GfVec4d>::value);
789 return Vec(x, y, w, z);
796 static_assert(std::is_same<Vec, GfVec4d>::value);
797 return Vec(x, z, y, w);
804 static_assert(std::is_same<Vec, GfVec4d>::value);
805 return Vec(x, z, w, y);
812 static_assert(std::is_same<Vec, GfVec4d>::value);
813 return Vec(x, w, y, z);
820 static_assert(std::is_same<Vec, GfVec4d>::value);
821 return Vec(x, w, z, y);
828 static_assert(std::is_same<Vec, GfVec4d>::value);
829 return Vec(y, x, z, w);
836 static_assert(std::is_same<Vec, GfVec4d>::value);
837 return Vec(y, x, w, z);
844 static_assert(std::is_same<Vec, GfVec4d>::value);
845 return Vec(y, z, x, w);
852 static_assert(std::is_same<Vec, GfVec4d>::value);
853 return Vec(y, z, w, x);
860 static_assert(std::is_same<Vec, GfVec4d>::value);
861 return Vec(y, w, x, z);
868 static_assert(std::is_same<Vec, GfVec4d>::value);
869 return Vec(y, w, z, x);
876 static_assert(std::is_same<Vec, GfVec4d>::value);
877 return Vec(z, x, y, w);
884 static_assert(std::is_same<Vec, GfVec4d>::value);
885 return Vec(z, x, w, y);
892 static_assert(std::is_same<Vec, GfVec4d>::value);
893 return Vec(z, y, x, w);
900 static_assert(std::is_same<Vec, GfVec4d>::value);
901 return Vec(z, y, w, x);
908 static_assert(std::is_same<Vec, GfVec4d>::value);
909 return Vec(z, w, x, y);
916 static_assert(std::is_same<Vec, GfVec4d>::value);
917 return Vec(z, w, y, x);
924 static_assert(std::is_same<Vec, GfVec4d>::value);
925 return Vec(w, x, y, z);
932 static_assert(std::is_same<Vec, GfVec4d>::value);
933 return Vec(w, x, z, y);
940 static_assert(std::is_same<Vec, GfVec4d>::value);
941 return Vec(w, y, x, z);
948 static_assert(std::is_same<Vec, GfVec4d>::value);
949 return Vec(w, y, z, x);
956 static_assert(std::is_same<Vec, GfVec4d>::value);
957 return Vec(w, z, x, y);
964 static_assert(std::is_same<Vec, GfVec4d>::value);
965 return Vec(w, z, y, x);
1020 return v.GetNormalized(eps);
1049 return delta.
GetLengthSq() <= tolerance * tolerance;
1054PXR_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 3 double components.
Basic type for a vector of 4 double components.
GfVec4d operator-() const
Create a vec with negated elements.
bool operator==(GfVec4d const &other) const
Equality comparison.
double GetLengthSq() const
Squared length.
constexpr GfVec4d(Scl const *p)
Construct with pointer to values.
static GfVec4d XAxis()
Create a unit vector along the X-axis.
GfVec4d & operator-=(GfVec4d const &other)
Subtraction.
static GfVec4d ZAxis()
Create a unit vector along the Z-axis.
double const * data() const
Direct data access.
friend size_t hash_value(GfVec4d const &vec)
Hash.
static GfVec4d YAxis()
Create a unit vector along the Y-axis.
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
GfVec4d & Set(double const *a)
Set all elements with a pointer to data.
static GfVec4d Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfVec4d GetComplement(GfVec4d const &b) const
Returns the orthogonal complement of this->GetProjection(b).
double ScalarType
Scalar element type and dimension.
constexpr GfVec4d(double s0, double s1, double s2, double s3)
Initialize all elements with explicit arguments.
static GfVec4d WAxis()
Create a unit vector along the W-axis.
GF_API bool operator==(class GfVec4f const &other) const
Equality comparison.
GfVec4d GetProjection(GfVec4d const &v) const
Returns the projection of this onto v.
GfVec4d & operator*=(double s)
Multiplication by scalar.
GF_API bool operator==(class GfVec4i const &other) const
Equality comparison.
GF_API bool operator==(class GfVec4h const &other) const
Equality comparison.
constexpr GfVec4d(double value)
Initialize all elements to a single value.
double const & operator[](size_t i) const
Indexing.
GfVec4d()=default
GfVec4d value-initializes to zero and performs no default initialization, like float or double.
GfVec4d & Set(double s0, double s1, double s2, double s3)
Set all elements with passed arguments.
GfVec4d & operator/=(double s)
Division by scalar.
double GetLength() const
Length.
double operator*(GfVec4d const &v) const
See GfDot().
GfVec4d & operator+=(GfVec4d const &other)
Addition.
Basic type for a vector of 4 float components.
Basic type for a vector of 4 GfHalf components.
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).
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.
GF_API std::ostream & operator<<(std::ostream &, GfVec4d const &)
Output a GfVec4d.
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
GfVec4d GfGetNormalized(GfVec4d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec4d GfGetProjection(GfVec4d const &a, GfVec4d const &b)
Returns the projection of a onto b.
GfVec4d GfCompMult(GfVec4d const &v1, GfVec4d const &v2)
Returns component-wise multiplication of vectors v1 and v2.
double GfDot(GfVec4d const &v1, GfVec4d const &v2)
Returns the dot (inner) product of two vectors.
bool GfIsClose(GfVec4d const &v1, GfVec4d const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
double GfNormalize(GfVec4d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
GfVec4d GfCompDiv(GfVec4d const &v1, GfVec4d const &v2)
Returns component-wise quotient of vectors v1 and v2.
double GfGetLength(GfVec4d const &v)
Returns the geometric length of v.
GfVec4d GfGetComplement(GfVec4d const &a, GfVec4d const &b)
Returns the orthogonal complement of a.GetProjection(b).