28 #ifndef PXR_BASE_GF_VEC3H_H 29 #define PXR_BASE_GF_VEC3H_H 36 #include "pxr/base/gf/api.h" 38 #include "pxr/base/gf/traits.h" 42 #include <boost/functional/hash.hpp> 49 PXR_NAMESPACE_OPEN_SCOPE
69 static const size_t dimension = 3;
76 : _data{ value, value, value }
89 : _data{ p[0], p[1], p[2] }
140 return Set(a[0], a[1], a[2]);
146 GfHalf const *GetArray()
const {
return data(); }
155 boost::hash_combine(h, vec[0]);
156 boost::hash_combine(h, vec[1]);
157 boost::hash_combine(h, vec[2]);
163 return _data[0] == other[0] &&
164 _data[1] == other[1] &&
165 _data[2] == other[2];
167 bool operator!=(
GfVec3h const &other)
const {
168 return !(*
this == other);
184 return GfVec3h(-_data[0], -_data[1], -_data[2]);
189 _data[0] += other[0];
190 _data[1] += other[1];
191 _data[2] += other[2];
200 _data[0] -= other[0];
201 _data[1] -= other[1];
202 _data[2] -= other[2];
216 GfVec3h operator*(
double s)
const {
229 return *
this *= (1.0 / s);
231 GfVec3h operator/(
double s)
const {
232 return *
this * (1.0 / s);
237 return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2];
245 return v * (*
this * v);
259 return *
this * *
this;
279 *
this /= (length > eps) ? length : eps;
285 normalized.Normalize(eps);
301 const bool normalize,
310 GfHalf eps = 0.001)
const;
322 PXR_NAMESPACE_CLOSE_SCOPE
328 PXR_NAMESPACE_OPEN_SCOPE
401 return v.GetNormalized(eps);
430 return delta.
GetLengthSq() <= tolerance * tolerance;
439 GfBuildOrthonormalFrame(
GfVec3h const &v0,
449 v1[1] * v2[2] - v1[2] * v2[1],
450 v1[2] * v2[0] - v1[0] * v2[2],
451 v1[0] * v2[1] - v1[1] * v2[0]);
468 PXR_NAMESPACE_CLOSE_SCOPE
470 #endif // PXR_BASE_GF_VEC3H_H GfVec3h GetComplement(GfVec3h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
GfVec3h GfCross(GfVec3h const &v1, GfVec3h const &v2)
Returns the cross product of v1 and v2.
GfHalf GfGetLength(GfVec3h const &v)
Returns the geometric length of v.
constexpr GfVec3h(GfHalf value)
Initialize all elements to a single value.
GfHalf const & operator[](size_t i) const
Indexing.
GfHalf Normalize(GfHalf eps=0.001)
Normalizes the vector in place to unit length, returning the length before normalization.
constexpr GfVec3h(Scl const *p)
Construct with pointer to values.
GfVec3h & operator+=(GfVec3h const &other)
Addition.
pxr_half::half GfHalf
A 16-bit floating point data type.
Assorted mathematical utility functions.
This header serves to simply bring in the half float datatype and provide a hash_value function.
Basic type for a vector of 3 float components.
static GfVec3h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GfHalf GfDot(GfVec3h const &v1, GfVec3h const &v2)
Returns the dot (inner) product of two vectors.
GfVec3h & operator-=(GfVec3h const &other)
Subtraction.
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,...
static GfVec3h XAxis()
Create a unit vector along the X-axis.
static GfVec3h ZAxis()
Create a unit vector along the Z-axis.
#define GF_MIN_ORTHO_TOLERANCE
This constant is used to determine when a set of basis vectors is close to orthogonal.
GfVec3h & operator *=(double s)
Multiplication by scalar.
GfVec3h & operator/=(double s)
Division by scalar.
static GfVec3h YAxis()
Create a unit vector along the Y-axis.
GfVec3h operator-() const
Create a vec with negated elements.
GfHalf GetLengthSq() const
Squared length.
GfVec3h GfCompDiv(GfVec3h const &v1, GfVec3h const &v2)
Returns component-wise quotient of vectors v1 and v2.
GfVec3h GfGetComplement(GfVec3h const &a, GfVec3h const &b)
Returns the orthogonal complement of a.GetProjection(b).
Basic type for a vector of 3 int components.
static GF_API bool OrthogonalizeBasis(GfVec3h *tx, GfVec3h *ty, GfVec3h *tz, const bool normalize, double eps=GF_MIN_ORTHO_TOLERANCE)
Orthogonalize and optionally normalize a set of basis vectors.
GF_API void BuildOrthonormalFrame(GfVec3h *v1, GfVec3h *v2, GfHalf eps=0.001) const
Sets v1 and v2 to unit vectors such that v1, v2 and *this are mutually orthogonal.
GfHalf ScalarType
Scalar element type and dimension.
GF_API std::ostream & operator<<(std::ostream &, GfVec3h const &)
Output a GfVec3h.
double GfSqrt(double f)
Return sqrt(f).
GfVec3h & Set(GfHalf s0, GfHalf s1, GfHalf s2)
Set all elements with passed arguments.
GfVec3h GetProjection(GfVec3h const &v) const
Returns the projection of this onto v.
GF_API GfVec3h GfSlerp(double alpha, GfVec3h const &v0, GfVec3h const &v1)
Spherical linear interpolation in three dimensions.
friend size_t hash_value(GfVec3h const &vec)
Hash.
bool GfIsClose(GfVec3h const &v1, GfVec3h const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
GfVec3h operator^(GfVec3h const &v1, GfVec3h const &v2)
Returns the cross product of v1 and v2.
GfVec3h & Set(GfHalf const *a)
Set all elements with a pointer to data.
Basic type for a vector of 3 double components.
Defines useful mathematical limits.
GfVec3h GfGetProjection(GfVec3h const &a, GfVec3h const &b)
Returns the projection of a onto b.
GfHalf GfNormalize(GfVec3h *v, GfHalf eps=0.001)
Normalizes *v in place to unit length, returning the length before normalization.
GfVec3h GfGetNormalized(GfVec3h const &v, GfHalf eps=0.001)
Returns a normalized (unit-length) vector with the same direction as v.
GfHalf GetLength() const
Length.
Basic type for a vector of 3 GfHalf components.
GfVec3h()=default
Default constructor does no initialization.
constexpr GfVec3h(GfHalf s0, GfHalf s1, GfHalf s2)
Initialize all elements with explicit arguments.
GfVec3h GfCompMult(GfVec3h const &v1, GfVec3h const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfHalf const * data() const
Direct data access.
bool operator==(GfVec3h const &other) const
Equality comparison.