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" 47 PXR_NAMESPACE_OPEN_SCOPE
67 static const size_t dimension = 4;
74 : _data{ value, value, value, value }
79 constexpr
GfVec4f(
float s0,
float s1,
float s2,
float s3)
80 : _data{ s0, s1, s2, s3 }
87 : _data{ p[0], p[1], p[2], p[3] }
145 return Set(a[0], a[1], a[2], a[3]);
149 float const *
data()
const {
return _data; }
150 float *
data() {
return _data; }
151 float const *GetArray()
const {
return data(); }
155 float &
operator[](
size_t i) {
return _data[i]; }
164 return _data[0] == other[0] &&
165 _data[1] == other[1] &&
166 _data[2] == other[2] &&
167 _data[3] == other[3];
169 bool operator!=(
GfVec4f const &other)
const {
170 return !(*
this == other);
186 return GfVec4f(-_data[0], -_data[1], -_data[2], -_data[3]);
191 _data[0] += other[0];
192 _data[1] += other[1];
193 _data[2] += other[2];
194 _data[3] += other[3];
203 _data[0] -= other[0];
204 _data[1] -= other[1];
205 _data[2] -= other[2];
206 _data[3] -= other[3];
221 GfVec4f operator*(
double s)
const {
234 return *
this *= (1.0 / s);
236 GfVec4f operator/(
double s)
const {
237 return *
this * (1.0 / s);
242 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
250 return v * (*
this * v);
264 return *
this * *
this;
284 *
this /= (length > eps) ? length : eps;
290 normalized.Normalize(eps);
304 PXR_NAMESPACE_CLOSE_SCOPE
310 PXR_NAMESPACE_OPEN_SCOPE
388 return v.GetNormalized(eps);
417 return delta.
GetLengthSq() <= tolerance * tolerance;
422 PXR_NAMESPACE_CLOSE_SCOPE
424 #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.
float GetLengthSq() const
Squared length.
static GfVec4f WAxis()
Create a unit vector along the W-axis.
float const & operator[](size_t i) const
Indexing.
Assorted mathematical utility functions.
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,...
bool operator==(GfVec4f const &other) const
Equality comparison.
GfVec4f GfGetNormalized(GfVec4f const &v, float eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
static GfVec4f ZAxis()
Create a unit vector along the Z-axis.
float GfNormalize(GfVec4f *v, float eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
Basic type for a vector of 4 GfHalf components.
constexpr GfVec4f(float value)
Initialize all elements to a single value.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
float GetLength() const
Length.
GfVec4f & operator+=(GfVec4f const &other)
Addition.
constexpr GfVec4f(Scl const *p)
Construct with pointer to values.
GfVec4f & operator-=(GfVec4f const &other)
Subtraction.
GF_API std::ostream & operator<<(std::ostream &, GfVec4f const &)
Output a GfVec4f.
float GfGetLength(GfVec4f const &v)
Returns the geometric length of v.
double GfSqrt(double f)
Return sqrt(f).
GfVec4f operator-() const
Create a vec with negated elements.
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.
float Normalize(float eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
GfVec4f GetComplement(GfVec4f const &b) const
Returns the orthogonal complement of this->GetProjection(b).
bool GfIsClose(GfVec4f const &v1, GfVec4f const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
GfVec4f & Set(float const *a)
Set all elements with a pointer to data.
GfVec4f & operator *=(double s)
Multiplication by scalar.
GfVec4f GfGetProjection(GfVec4f const &a, GfVec4f const &b)
Returns the projection of a onto b.
float GfDot(GfVec4f const &v1, GfVec4f const &v2)
Returns the dot (inner) product of two vectors.
static GfVec4f YAxis()
Create a unit vector along the Y-axis.
Defines useful mathematical limits.
friend size_t hash_value(GfVec4f const &vec)
Hash.
float const * data() const
Direct data access.
GfVec4f GfGetComplement(GfVec4f const &a, GfVec4f const &b)
Returns the orthogonal complement of a.GetProjection(b).
GfVec4f GfCompDiv(GfVec4f const &v1, GfVec4f const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfVec4f GetProjection(GfVec4f const &v) const
Returns the projection of this onto v.
constexpr GfVec4f(float s0, float s1, float s2, float s3)
Initialize all elements with explicit arguments.
GfVec4f GfCompMult(GfVec4f const &v1, GfVec4f const &v2)
Returns component-wise multiplication of vectors v1 and v2.
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.