11#ifndef PXR_BASE_GF_VEC2D_H
12#define PXR_BASE_GF_VEC2D_H
18#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/traits.h"
31PXR_NAMESPACE_OPEN_SCOPE
50 static const size_t dimension = 2;
129 return Set(a[0], a[1]);
137 double const *
data()
const {
return &x; }
138 double *
data() {
return &x; }
139 double const *GetArray()
const {
return data(); }
152 return x == other.x &&
155 bool operator!=(
GfVec2d const &other)
const {
156 return !(*
this == other);
201 GfVec2d operator*(
double s)
const {
214 return *
this *= (1.0 / s);
216 GfVec2d operator/(
double s)
const {
217 return *
this * (1.0 / s);
222 return x * v.x + y * v.y;
230 return v * (*
this * v);
244 return *
this * *
this;
264 *
this /= (length > eps) ? length : eps;
270 normalized.Normalize(eps);
299 template <
class Vec = GfVec2d>
constexpr Vec xy()
const;
300 template <
class Vec = GfVec2d>
constexpr Vec yx()
const;
308PXR_NAMESPACE_CLOSE_SCOPE
315PXR_NAMESPACE_OPEN_SCOPE
340 static_assert(std::is_same<Vec, GfVec2d>::value);
348 static_assert(std::is_same<Vec, GfVec2d>::value);
400 return v.GetNormalized(eps);
429 return delta.
GetLengthSq() <= tolerance * tolerance;
434PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 2 double components.
constexpr GfVec2d(double value)
Initialize all elements to a single value.
double GetLengthSq() const
Squared length.
GfVec2d & operator*=(double s)
Multiplication by scalar.
GfVec2d & operator/=(double s)
Division by scalar.
GF_API bool operator==(class GfVec2h const &other) const
Equality comparison.
double const * data() const
Direct data access.
constexpr GfVec2d(double s0, double s1)
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.
GfVec2d & Set(double const *a)
Set all elements with a pointer to data.
double ScalarType
Scalar element type and dimension.
static GfVec2d XAxis()
Create a unit vector along the X-axis.
constexpr GfVec2d(Scl const *p)
Construct with pointer to values.
GfVec2d & operator-=(GfVec2d const &other)
Subtraction.
double operator*(GfVec2d const &v) const
See GfDot().
GfVec2d()=default
GfVec2d value-initializes to zero and performs no default initialization, like float or double.
GF_API bool operator==(class GfVec2f const &other) const
Equality comparison.
GfVec2d & operator+=(GfVec2d const &other)
Addition.
GfVec2d GetProjection(GfVec2d const &v) const
Returns the projection of this onto v.
GfVec2d & Set(double s0, double s1)
Set all elements with passed arguments.
bool operator==(GfVec2d const &other) const
Equality comparison.
GfVec2d operator-() const
Create a vec with negated elements.
double const & operator[](size_t i) const
Indexing.
GfVec2d GetComplement(GfVec2d const &b) const
Returns the orthogonal complement of this->GetProjection(b).
double GetLength() const
Length.
static GfVec2d Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
GF_API bool operator==(class GfVec2i const &other) const
Equality comparison.
static GfVec2d YAxis()
Create a unit vector along the Y-axis.
friend size_t hash_value(GfVec2d const &vec)
Hash.
Basic type for a vector of 2 float components.
Basic type for a vector of 2 GfHalf components.
Basic type for a vector of 2 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 &, GfVec2d const &)
Output a GfVec2d.
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
double GfDot(GfVec2d const &v1, GfVec2d const &v2)
Returns the dot (inner) product of two vectors.
GfVec2d GfGetNormalized(GfVec2d const &v, double eps=GF_MIN_VECTOR_LENGTH)
Returns a normalized (unit-length) vector with the same direction as v.
GfVec2d GfCompDiv(GfVec2d const &v1, GfVec2d const &v2)
Returns component-wise quotient of vectors v1 and v2.
bool GfIsClose(GfVec2d const &v1, GfVec2d const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
GfVec2d GfGetComplement(GfVec2d const &a, GfVec2d const &b)
Returns the orthogonal complement of a.GetProjection(b).
double GfNormalize(GfVec2d *v, double eps=GF_MIN_VECTOR_LENGTH)
Normalizes *v in place to unit length, returning the length before normalization.
double GfGetLength(GfVec2d const &v)
Returns the geometric length of v.
GfVec2d GfCompMult(GfVec2d const &v1, GfVec2d const &v2)
Returns component-wise multiplication of vectors v1 and v2.
GfVec2d GfGetProjection(GfVec2d const &a, GfVec2d const &b)
Returns the projection of a onto b.