28 #ifndef PXR_BASE_GF_VEC4H_H 29 #define PXR_BASE_GF_VEC4H_H 36 #include "pxr/base/gf/api.h" 38 #include "pxr/base/gf/traits.h" 48 PXR_NAMESPACE_OPEN_SCOPE
68 static const size_t dimension = 4;
75 : _data{ value, value, value, value }
81 : _data{ s0, s1, s2, s3 }
88 : _data{ p[0], p[1], p[2], p[3] }
146 return Set(a[0], a[1], a[2], a[3]);
152 GfHalf const *GetArray()
const {
return data(); }
165 return _data[0] == other[0] &&
166 _data[1] == other[1] &&
167 _data[2] == other[2] &&
168 _data[3] == other[3];
170 bool operator!=(
GfVec4h const &other)
const {
171 return !(*
this == other);
187 return GfVec4h(-_data[0], -_data[1], -_data[2], -_data[3]);
192 _data[0] += other[0];
193 _data[1] += other[1];
194 _data[2] += other[2];
195 _data[3] += other[3];
204 _data[0] -= other[0];
205 _data[1] -= other[1];
206 _data[2] -= other[2];
207 _data[3] -= other[3];
222 GfVec4h operator*(
double s)
const {
235 return *
this *= (1.0 / s);
237 GfVec4h operator/(
double s)
const {
238 return *
this * (1.0 / s);
243 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
251 return v * (*
this * v);
265 return *
this * *
this;
285 *
this /= (length > eps) ? length : eps;
291 normalized.Normalize(eps);
305 PXR_NAMESPACE_CLOSE_SCOPE
311 PXR_NAMESPACE_OPEN_SCOPE
389 return v.GetNormalized(eps);
418 return delta.
GetLengthSq() <= tolerance * tolerance;
423 PXR_NAMESPACE_CLOSE_SCOPE
425 #endif // PXR_BASE_GF_VEC4H_H Basic type for a vector of 4 int components.
GfVec4h GfGetNormalized(GfVec4h const &v, GfHalf eps=0.001)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec4h & operator-=(GfVec4h const &other)
Subtraction.
GfVec4h & Set(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3)
Set all elements with passed arguments.
pxr_half::half GfHalf
A 16-bit floating point data type.
Assorted mathematical utility functions.
This header serves to simply bring in the half float datatype and provide a hash_value function.
GfVec4h GfGetProjection(GfVec4h const &a, GfVec4h const &b)
Returns the projection of a onto b.
Basic type for a vector of 4 double components.
GfVec4h GfCompDiv(GfVec4h const &v1, GfVec4h const &v2)
Returns component-wise quotient of vectors v1 and v2.
Low-level utilities for informing users of various internal and external diagnostic conditions.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
constexpr GfVec4h(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3)
Initialize all elements with explicit arguments.
static GfVec4h YAxis()
Create a unit vector along the Y-axis.
friend size_t hash_value(GfVec4h const &vec)
Hash.
Basic type for a vector of 4 GfHalf components.
GfHalf GfGetLength(GfVec4h const &v)
Returns the geometric length of v.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
GfHalf GetLength() const
Length.
GfVec4h & operator+=(GfVec4h const &other)
Addition.
GfVec4h & operator/=(double s)
Division by scalar.
GfVec4h GfCompMult(GfVec4h const &v1, GfVec4h const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfHalf Normalize(GfHalf eps=0.001)
Normalizes the vector in place to unit length, returning the length before normalization.
bool operator==(GfVec4h const &other) const
Equality comparison.
GfHalf GfDot(GfVec4h const &v1, GfVec4h const &v2)
Returns the dot (inner) product of two vectors.
double GfSqrt(double f)
Return sqrt(f).
static GfVec4h ZAxis()
Create a unit vector along the Z-axis.
GfVec4h GetComplement(GfVec4h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
static GfVec4h XAxis()
Create a unit vector along the X-axis.
GfHalf GetLengthSq() const
Squared length.
GfVec4h GetProjection(GfVec4h const &v) const
Returns the projection of this onto v.
Basic type for a vector of 4 float components.
GfVec4h GfGetComplement(GfVec4h const &a, GfVec4h const &b)
Returns the orthogonal complement of a.GetProjection(b).
static GfVec4h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfHalf const & operator[](size_t i) const
Indexing.
GfVec4h & Set(GfHalf const *a)
Set all elements with a pointer to data.
GfVec4h()=default
Default constructor does no initialization.
GfHalf const * data() const
Direct data access.
GfHalf ScalarType
Scalar element type and dimension.
GF_API std::ostream & operator<<(std::ostream &, GfVec4h const &)
Output a GfVec4h.
constexpr GfVec4h(GfHalf value)
Initialize all elements to a single value.
Defines useful mathematical limits.
static GfVec4h WAxis()
Create a unit vector along the W-axis.
GfHalf GfNormalize(GfVec4h *v, GfHalf eps=0.001)
Normalizes *v in place to unit length, returning the length before normalization.
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...
GfVec4h operator-() const
Create a vec with negated elements.
GfVec4h & operator *=(double s)
Multiplication by scalar.
constexpr GfVec4h(Scl const *p)
Construct with pointer to values.