11#ifndef PXR_BASE_GF_VEC4F_H
12#define PXR_BASE_GF_VEC4F_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 GfVec4f(
float s0,
float s1,
float s2,
float 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 float const *
data()
const {
return _data; }
133 float *
data() {
return _data; }
134 float const *GetArray()
const {
return data(); }
138 float &
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!=(
GfVec4f const &other)
const {
153 return !(*
this == other);
169 return GfVec4f(-_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 GfVec4f operator*(
double s)
const {
217 return *
this *= (1.0 / s);
219 GfVec4f 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.
Basic type for a vector of 4 float components.
bool operator==(GfVec4f const &other) const
Equality comparison.
GfVec4f & Set(float const *a)
Set all elements with a pointer to data.
GfVec4f GetProjection(GfVec4f const &v) const
Returns the projection of this onto v.
GfVec4f & operator-=(GfVec4f const &other)
Subtraction.
static GfVec4f WAxis()
Create a unit vector along the W-axis.
friend size_t hash_value(GfVec4f const &vec)
Hash.
static GfVec4f ZAxis()
Create a unit vector along the Z-axis.
float GetLength() const
Length.
constexpr GfVec4f(Scl const *p)
Construct with pointer to values.
GfVec4f & operator/=(double s)
Division by scalar.
float Normalize(float eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
GfVec4f()=default
Default constructor does no initialization.
GfVec4f GetComplement(GfVec4f const &b) const
Returns the orthogonal complement of this->GetProjection(b).
float const & operator[](size_t i) const
Indexing.
float GetLengthSq() const
Squared length.
GfVec4f & Set(float s0, float s1, float s2, float s3)
Set all elements with passed arguments.
float operator*(GfVec4f const &v) const
See GfDot().
GfVec4f & operator+=(GfVec4f const &other)
Addition.
GF_API bool operator==(class GfVec4i const &other) const
Equality comparison.
constexpr GfVec4f(float value)
Initialize all elements to a single value.
GF_API bool operator==(class GfVec4h const &other) const
Equality comparison.
constexpr GfVec4f(float s0, float s1, float s2, float s3)
Initialize all elements with explicit arguments.
GF_API bool operator==(class GfVec4d const &other) const
Equality comparison.
static GfVec4f XAxis()
Create a unit vector along the X-axis.
static GfVec4f YAxis()
Create a unit vector along the Y-axis.
float const * data() const
Direct data access.
float ScalarType
Scalar element type and dimension.
static GfVec4f Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfVec4f operator-() const
Create a vec with negated elements.
GfVec4f & operator*=(double s)
Multiplication by scalar.
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,...
GfVec4f GfCompMult(GfVec4f const &v1, GfVec4f const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfVec4f GfGetComplement(GfVec4f const &a, GfVec4f const &b)
Returns the orthogonal complement of a.GetProjection(b).
float GfGetLength(GfVec4f const &v)
Returns the geometric length of v.
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...
float GfDot(GfVec4f const &v1, GfVec4f const &v2)
Returns the dot (inner) product of two vectors.
float GfNormalize(GfVec4f *v, float eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
GfVec4f GfCompDiv(GfVec4f const &v1, GfVec4f const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfVec4f GfGetNormalized(GfVec4f const &v, float eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec4f GfGetProjection(GfVec4f const &a, GfVec4f const &b)
Returns the projection of a onto b.