11#ifndef PXR_BASE_GF_VEC4H_H
12#define PXR_BASE_GF_VEC4H_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 = 4;
58 : _data{ value, value, value, value }
64 : _data{ s0, s1, s2, s3 }
71 : _data{ p[0], p[1], p[2], p[3] }
129 return Set(a[0], a[1], a[2], a[3]);
135 GfHalf const *GetArray()
const {
return data(); }
148 return _data[0] == other[0] &&
149 _data[1] == other[1] &&
150 _data[2] == other[2] &&
151 _data[3] == other[3];
153 bool operator!=(
GfVec4h const &other)
const {
154 return !(*
this == other);
170 return GfVec4h(-_data[0], -_data[1], -_data[2], -_data[3]);
175 _data[0] += other[0];
176 _data[1] += other[1];
177 _data[2] += other[2];
178 _data[3] += other[3];
187 _data[0] -= other[0];
188 _data[1] -= other[1];
189 _data[2] -= other[2];
190 _data[3] -= other[3];
205 GfVec4h operator*(
double s)
const {
218 return *
this *= (1.0 / s);
220 GfVec4h operator/(
double s)
const {
221 return *
this * (1.0 / s);
226 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
234 return v * (*
this * v);
248 return *
this * *
this;
268 *
this /= (length > eps) ? length : eps;
274 normalized.Normalize(eps);
288PXR_NAMESPACE_CLOSE_SCOPE
294PXR_NAMESPACE_OPEN_SCOPE
372 return v.GetNormalized(eps);
401 return delta.
GetLengthSq() <= tolerance * tolerance;
406PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
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.
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.
GfHalf ScalarType
Scalar element type and dimension.
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
Default constructor does no initialization.
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 &, 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,...
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.