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