28 #ifndef PXR_BASE_GF_VEC4D_H 29 #define PXR_BASE_GF_VEC4D_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
GfVec4d(
double s0,
double s1,
double s2,
double 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 double const *
data()
const {
return _data; }
150 double *
data() {
return _data; }
151 double const *GetArray()
const {
return data(); }
154 double const &
operator[](
size_t i)
const {
return _data[i]; }
155 double &
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!=(
GfVec4d const &other)
const {
170 return !(*
this == other);
186 return GfVec4d(-_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 GfVec4d operator*(
double s)
const {
234 return *
this *= (1.0 / s);
236 GfVec4d 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_VEC4D_H Basic type for a vector of 4 int components.
double ScalarType
Scalar element type and dimension.
static GfVec4d XAxis()
Create a unit vector along the X-axis.
constexpr GfVec4d(double value)
Initialize all elements to a single value.
GfVec4d & operator *=(double s)
Multiplication by scalar.
GfVec4d & operator/=(double s)
Division by scalar.
static GfVec4d YAxis()
Create a unit vector along the Y-axis.
Assorted mathematical utility functions.
double const * data() const
Direct data access.
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,...
bool operator==(GfVec4d const &other) const
Equality comparison.
GfVec4d GfGetComplement(GfVec4d const &a, GfVec4d const &b)
Returns the orthogonal complement of a.GetProjection(b).
GfVec4d GfCompDiv(GfVec4d const &v1, GfVec4d const &v2)
Returns component-wise quotient of vectors v1 and v2.
Basic type for a vector of 4 GfHalf components.
GfVec4d GfGetProjection(GfVec4d const &a, GfVec4d const &b)
Returns the projection of a onto b.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
GfVec4d GetComplement(GfVec4d const &b) const
Returns the orthogonal complement of this->GetProjection(b).
GfVec4d & operator-=(GfVec4d const &other)
Subtraction.
constexpr GfVec4d(double s0, double s1, double s2, double s3)
Initialize all elements with explicit arguments.
double GetLengthSq() const
Squared length.
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
double const & operator[](size_t i) const
Indexing.
GfVec4d & Set(double s0, double s1, double s2, double s3)
Set all elements with passed arguments.
GfVec4d GfGetNormalized(GfVec4d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
double GfNormalize(GfVec4d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
static GfVec4d ZAxis()
Create a unit vector along the Z-axis.
GfVec4d GetProjection(GfVec4d const &v) const
Returns the projection of this onto v.
GF_API std::ostream & operator<<(std::ostream &, GfVec4d const &)
Output a GfVec4d.
double GfSqrt(double f)
Return sqrt(f).
double GfGetLength(GfVec4d const &v)
Returns the geometric length of v.
static GfVec4d Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
double GetLength() const
Length.
Basic type for a vector of 4 float components.
static GfVec4d WAxis()
Create a unit vector along the W-axis.
GfVec4d GfCompMult(GfVec4d const &v1, GfVec4d const &v2)
Returns component-wise multiplication of vectors v1 and v2.
double GfDot(GfVec4d const &v1, GfVec4d const &v2)
Returns the dot (inner) product of two vectors.
Defines useful mathematical limits.
constexpr GfVec4d(Scl const *p)
Construct with pointer to values.
GfVec4d & Set(double const *a)
Set all elements with a pointer to data.
GfVec4d()=default
Default constructor does no initialization.
GfVec4d & operator+=(GfVec4d const &other)
Addition.
bool GfIsClose(GfVec4d const &v1, GfVec4d const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
friend size_t hash_value(GfVec4d const &vec)
Hash.
GfVec4d operator-() const
Create a vec with negated elements.
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.