11#ifndef PXR_BASE_GF_VEC4D_H
12#define PXR_BASE_GF_VEC4D_H
19#include "pxr/base/gf/api.h"
21#include "pxr/base/gf/traits.h"
30PXR_NAMESPACE_OPEN_SCOPE
50 static const size_t dimension = 4;
57 : _data{ value, value, value, value }
62 constexpr GfVec4d(
double s0,
double s1,
double s2,
double s3)
63 : _data{ s0, s1, s2, s3 }
70 : _data{ p[0], p[1], p[2], p[3] }
128 return Set(a[0], a[1], a[2], a[3]);
132 double const *
data()
const {
return _data; }
133 double *
data() {
return _data; }
134 double const *GetArray()
const {
return data(); }
137 double const &
operator[](
size_t i)
const {
return _data[i]; }
138 double &
operator[](
size_t i) {
return _data[i]; }
147 return _data[0] == other[0] &&
148 _data[1] == other[1] &&
149 _data[2] == other[2] &&
150 _data[3] == other[3];
152 bool operator!=(
GfVec4d const &other)
const {
153 return !(*
this == other);
169 return GfVec4d(-_data[0], -_data[1], -_data[2], -_data[3]);
174 _data[0] += other[0];
175 _data[1] += other[1];
176 _data[2] += other[2];
177 _data[3] += other[3];
186 _data[0] -= other[0];
187 _data[1] -= other[1];
188 _data[2] -= other[2];
189 _data[3] -= other[3];
204 GfVec4d operator*(
double s)
const {
217 return *
this *= (1.0 / s);
219 GfVec4d operator/(
double s)
const {
220 return *
this * (1.0 / s);
225 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
233 return v * (*
this * v);
247 return *
this * *
this;
267 *
this /= (length > eps) ? length : eps;
273 normalized.Normalize(eps);
287PXR_NAMESPACE_CLOSE_SCOPE
293PXR_NAMESPACE_OPEN_SCOPE
371 return v.GetNormalized(eps);
400 return delta.
GetLengthSq() <= tolerance * tolerance;
405PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 4 double components.
GfVec4d operator-() const
Create a vec with negated elements.
bool operator==(GfVec4d const &other) const
Equality comparison.
double GetLengthSq() const
Squared length.
constexpr GfVec4d(Scl const *p)
Construct with pointer to values.
static GfVec4d XAxis()
Create a unit vector along the X-axis.
GfVec4d & operator-=(GfVec4d const &other)
Subtraction.
static GfVec4d ZAxis()
Create a unit vector along the Z-axis.
double ScalarType
Scalar element type and dimension.
double const * data() const
Direct data access.
friend size_t hash_value(GfVec4d const &vec)
Hash.
static GfVec4d YAxis()
Create a unit vector along the Y-axis.
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
GfVec4d & Set(double const *a)
Set all elements with a pointer to data.
static GfVec4d Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfVec4d GetComplement(GfVec4d const &b) const
Returns the orthogonal complement of this->GetProjection(b).
constexpr GfVec4d(double s0, double s1, double s2, double s3)
Initialize all elements with explicit arguments.
static GfVec4d WAxis()
Create a unit vector along the W-axis.
GF_API bool operator==(class GfVec4f const &other) const
Equality comparison.
GfVec4d GetProjection(GfVec4d const &v) const
Returns the projection of this onto v.
GfVec4d & operator*=(double s)
Multiplication by scalar.
GF_API bool operator==(class GfVec4i const &other) const
Equality comparison.
GF_API bool operator==(class GfVec4h const &other) const
Equality comparison.
constexpr GfVec4d(double value)
Initialize all elements to a single value.
double const & operator[](size_t i) const
Indexing.
GfVec4d()=default
Default constructor does no initialization.
GfVec4d & Set(double s0, double s1, double s2, double s3)
Set all elements with passed arguments.
GfVec4d & operator/=(double s)
Division by scalar.
double GetLength() const
Length.
double operator*(GfVec4d const &v) const
See GfDot().
GfVec4d & operator+=(GfVec4d const &other)
Addition.
Basic type for a vector of 4 float components.
Basic type for a vector of 4 GfHalf components.
Basic type for a vector of 4 int components.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Assorted mathematical utility functions.
double GfSqrt(double f)
Return sqrt(f).
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
GfVec4d GfGetNormalized(GfVec4d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec4d GfGetProjection(GfVec4d const &a, GfVec4d const &b)
Returns the projection of a onto b.
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.
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...
double GfNormalize(GfVec4d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
GfVec4d GfCompDiv(GfVec4d const &v1, GfVec4d const &v2)
Returns component-wise quotient of vectors v1 and v2.
double GfGetLength(GfVec4d const &v)
Returns the geometric length of v.
GfVec4d GfGetComplement(GfVec4d const &a, GfVec4d const &b)
Returns the orthogonal complement of a.GetProjection(b).