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" 42 #include <boost/functional/hash.hpp> 49 PXR_NAMESPACE_OPEN_SCOPE
69 static const size_t dimension = 4;
76 : _data{ value, value, value, value }
82 : _data{ s0, s1, s2, s3 }
89 : _data{ p[0], p[1], p[2], p[3] }
147 return Set(a[0], a[1], a[2], a[3]);
153 GfHalf const *GetArray()
const {
return data(); }
162 boost::hash_combine(h, vec[0]);
163 boost::hash_combine(h, vec[1]);
164 boost::hash_combine(h, vec[2]);
165 boost::hash_combine(h, vec[3]);
171 return _data[0] == other[0] &&
172 _data[1] == other[1] &&
173 _data[2] == other[2] &&
174 _data[3] == other[3];
176 bool operator!=(
GfVec4h const &other)
const {
177 return !(*
this == other);
193 return GfVec4h(-_data[0], -_data[1], -_data[2], -_data[3]);
198 _data[0] += other[0];
199 _data[1] += other[1];
200 _data[2] += other[2];
201 _data[3] += other[3];
210 _data[0] -= other[0];
211 _data[1] -= other[1];
212 _data[2] -= other[2];
213 _data[3] -= other[3];
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 _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
257 return v * (*
this * v);
271 return *
this * *
this;
291 *
this /= (length > eps) ? length : eps;
297 normalized.Normalize(eps);
311 PXR_NAMESPACE_CLOSE_SCOPE
317 PXR_NAMESPACE_OPEN_SCOPE
395 return v.GetNormalized(eps);
424 return delta.
GetLengthSq() <= tolerance * tolerance;
429 PXR_NAMESPACE_CLOSE_SCOPE
431 #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.
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.