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"
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
GfVec4d(
double s0,
double s1,
double s2,
double 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 double const *
data()
const {
return _data; }
151 double *
data() {
return _data; }
152 double const *GetArray()
const {
return data(); }
155 double const &
operator[](
size_t i)
const {
return _data[i]; }
156 double &
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!=(
GfVec4d const &other)
const {
176 return !(*
this == other);
192 return GfVec4d(-_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 GfVec4d operator*(
double s)
const {
240 return *
this *= (1.0 / s);
242 GfVec4d 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_VEC4D_H
Basic type for a vector of 4 int components.
double ScalarType
Scalar element type and dimension.
GfVec4d GetComplement(GfVec4d const &b) const
Returns the orthogonal complement of this->GetProjection(b).
static GfVec4d XAxis()
Create a unit vector along the X-axis.
constexpr GfVec4d(double value)
Initialize all elements to a single value.
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.
double const * data() const
Direct data access.
GfVec4d & operator/=(double s)
Division by scalar.
decltype(std::declval< Left >()*std::declval< Right >()) GfCompMult(Left left, Right right)
Returns component-wise multiplication of vectors.
static GfVec4d YAxis()
Create a unit vector along the Y-axis.
Assorted mathematical utility functions.
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.
GfVec4d operator-() const
Create a vec with negated elements.
GfVec4d GetProjection(GfVec4d const &v) const
Returns the projection of this onto v.
Basic type for a vector of 4 GfHalf components.
GfVec2d GfGetNormalized(GfVec2d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec4d & operator-=(GfVec4d const &other)
Subtraction.
constexpr GfVec4d(double s0, double s1, double s2, double s3)
Initialize all elements with explicit arguments.
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
GfVec4d & Set(double s0, double s1, double s2, double s3)
Set all elements with passed arguments.
decltype(std::declval< Left >()/std::declval< Right >()) GfCompDiv(Left left, Right right)
Returns component-wise quotient of vectors.
static GfVec4d ZAxis()
Create a unit vector along the Z-axis.
decltype(std::declval< Left >()*std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
double GfNormalize(GfVec2d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization. ...
static GfVec4d Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Basic type for a vector of 4 float components.
static GfVec4d WAxis()
Create a unit vector along the W-axis.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
double GetLengthSq() const
Squared length.
GfVec4d & operator*=(double s)
Multiplication by scalar.
double const & operator[](size_t i) const
Indexing.
Defines useful mathematical limits.
constexpr GfVec4d(Scl const *p)
Construct with pointer to values.
double GetLength() const
Length.
GfVec4d & Set(double const *a)
Set all elements with a pointer to data.
double GfGetLength(GfVec2d const &v)
Returns the geometric length of v.
bool operator==(GfVec4d const &other) const
Equality comparison.
GfVec4d()=default
Default constructor does no initialization.
GfVec4d & operator+=(GfVec4d const &other)
Addition.
GfVec2d GfGetComplement(GfVec2d const &a, GfVec2d const &b)
Returns the orthogonal complement of a.GetProjection(b).
friend size_t hash_value(GfVec4d const &vec)
Hash.
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately...
double operator*(GfVec4d const &v) const
See GfDot().