28 #ifndef PXR_BASE_GF_VEC4F_H
29 #define PXR_BASE_GF_VEC4F_H
36 #include "pxr/base/gf/api.h"
38 #include "pxr/base/gf/traits.h"
41 #include <boost/functional/hash.hpp>
48 PXR_NAMESPACE_OPEN_SCOPE
68 static const size_t dimension = 4;
75 : _data{ value, value, value, value }
80 constexpr
GfVec4f(
float s0,
float s1,
float s2,
float s3)
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]);
150 float const *
data()
const {
return _data; }
151 float *
data() {
return _data; }
152 float const *GetArray()
const {
return data(); }
156 float &
operator[](
size_t i) {
return _data[i]; }
161 boost::hash_combine(h, vec[0]);
162 boost::hash_combine(h, vec[1]);
163 boost::hash_combine(h, vec[2]);
164 boost::hash_combine(h, vec[3]);
170 return _data[0] == other[0] &&
171 _data[1] == other[1] &&
172 _data[2] == other[2] &&
173 _data[3] == other[3];
175 bool operator!=(
GfVec4f const &other)
const {
176 return !(*
this == other);
192 return GfVec4f(-_data[0], -_data[1], -_data[2], -_data[3]);
197 _data[0] += other[0];
198 _data[1] += other[1];
199 _data[2] += other[2];
200 _data[3] += other[3];
209 _data[0] -= other[0];
210 _data[1] -= other[1];
211 _data[2] -= other[2];
212 _data[3] -= other[3];
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 _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
256 return v * (*
this * v);
270 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_VEC4F_H
Basic type for a vector of 4 int components.
GfVec4f & Set(float s0, float s1, float s2, float s3)
Set all elements with passed arguments.
GfVec4f()=default
Default constructor does no initialization.
static GfVec4f XAxis()
Create a unit vector along the X-axis.
GfVec2d GfGetProjection(GfVec2d const &a, GfVec2d const &b)
Returns the projection of a onto b.
static GfVec4f WAxis()
Create a unit vector along the W-axis.
bool GfIsClose(double a, double b, double epsilon)
Returns true if a and b are with epsilon of each other.
decltype(std::declval< Left >()*std::declval< Right >()) GfCompMult(Left left, Right right)
Returns component-wise multiplication of vectors.
Assorted mathematical utility functions.
float const * data() const
Direct data access.
Basic type for a vector of 4 double components.
float ScalarType
Scalar element type and dimension.
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.
GfVec4f & operator*=(double s)
Multiplication by scalar.
float const & operator[](size_t i) const
Indexing.
static GfVec4f ZAxis()
Create a unit vector along the Z-axis.
float operator*(GfVec4f const &v) const
See GfDot().
Basic type for a vector of 4 GfHalf components.
constexpr GfVec4f(float value)
Initialize all elements to a single value.
GfVec2d GfGetNormalized(GfVec2d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
float GetLength() const
Length.
decltype(std::declval< Left >()/std::declval< Right >()) GfCompDiv(Left left, Right right)
Returns component-wise quotient of vectors.
GfVec4f & operator+=(GfVec4f const &other)
Addition.
decltype(std::declval< Left >()*std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
constexpr GfVec4f(Scl const *p)
Construct with pointer to values.
GfVec4f & operator-=(GfVec4f const &other)
Subtraction.
double GfNormalize(GfVec2d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization. ...
static GfVec4f Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
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].
float Normalize(float eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
GfVec4f & Set(float const *a)
Set all elements with a pointer to data.
GfVec4f operator-() const
Create a vec with negated elements.
static GfVec4f YAxis()
Create a unit vector along the Y-axis.
Defines useful mathematical limits.
friend size_t hash_value(GfVec4f const &vec)
Hash.
double GfGetLength(GfVec2d const &v)
Returns the geometric length of v.
float GetLengthSq() const
Squared length.
bool operator==(GfVec4f const &other) const
Equality comparison.
GfVec4f GetComplement(GfVec4f const &b) const
Returns the orthogonal complement of this->GetProjection(b).
GfVec2d GfGetComplement(GfVec2d const &a, GfVec2d const &b)
Returns the orthogonal complement of a.GetProjection(b).
constexpr GfVec4f(float s0, float s1, float s2, float s3)
Initialize all elements with explicit arguments.
GfVec4f & operator/=(double s)
Division by scalar.
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately...
GfVec4f GetProjection(GfVec4f const &v) const
Returns the projection of this onto v.