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;
292 *
this /= (length > eps) ? length : eps;
298 normalized.Normalize(eps);
312 PXR_NAMESPACE_CLOSE_SCOPE
318 PXR_NAMESPACE_OPEN_SCOPE
396 return v.GetNormalized(eps);
425 return delta.
GetLengthSq() <= tolerance * tolerance;
430 PXR_NAMESPACE_CLOSE_SCOPE
432 #endif // PXR_BASE_GF_VEC4H_H
Basic type for a vector of 4 int components.
GfVec2d GfGetProjection(GfVec2d const &a, GfVec2d const &b)
Returns the projection of a onto b.
bool GfIsClose(double a, double b, double epsilon)
Returns true if a and b are with epsilon of each other.
GfVec4h & operator-=(GfVec4h const &other)
Subtraction.
GfVec4h & Set(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3)
Set all elements with passed arguments.
decltype(std::declval< Left >()*std::declval< Right >()) GfCompMult(Left left, Right right)
Returns component-wise multiplication of vectors.
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...
GfHalf operator*(GfVec4h const &v) const
See GfDot().
bool operator==(GfVec4h const &other) const
Equality comparison.
Basic type for a vector of 4 double components.
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, like GfVec2i, GfVec4d, etc and false for all other 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 GetLength() const
Length.
GfVec4h GetProjection(GfVec4h const &v) const
Returns the projection of this onto v.
GfVec2d GfGetNormalized(GfVec2d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
GfHalf GetLengthSq() const
Squared length.
decltype(std::declval< Left >()/std::declval< Right >()) GfCompDiv(Left left, Right right)
Returns component-wise quotient of vectors.
GfVec4h & operator+=(GfVec4h const &other)
Addition.
GfHalf const & operator[](size_t i) const
Indexing.
GfVec4h & operator/=(double s)
Division by scalar.
decltype(std::declval< Left >()*std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
GfHalf Normalize(GfHalf eps=0.001)
Normalizes the vector in place to unit length, returning the length before normalization.
double GfNormalize(GfVec2d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization. ...
GfVec4h & operator*=(double s)
Multiplication by scalar.
GfHalf const * data() const
Direct data access.
static GfVec4h ZAxis()
Create a unit vector along the Z-axis.
static GfVec4h XAxis()
Create a unit vector along the X-axis.
Basic type for a vector of 4 float components.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
static GfVec4h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfVec4h & Set(GfHalf const *a)
Set all elements with a pointer to data.
GfVec4h()=default
Default constructor does no initialization.
GfHalf ScalarType
Scalar element type and dimension.
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.
GfVec4h GetComplement(GfVec4h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
double GfGetLength(GfVec2d const &v)
Returns the geometric length of v.
GfVec2d GfGetComplement(GfVec2d const &a, GfVec2d const &b)
Returns the orthogonal complement of a.GetProjection(b).
GfVec4h operator-() const
Create a vec with negated elements.
constexpr GfVec4h(Scl const *p)
Construct with pointer to values.