Loading...
Searching...
No Matches
GfVec3f Class Reference

Basic type for a vector of 3 float components. More...

#include <vec3f.h>

Public Types

typedef float ScalarType
 Scalar element type and dimension.
 

Public Member Functions

 GfVec3f ()=default
 GfVec3f value-initializes to zero and performs no default initialization, like float or double.
 
constexpr GfVec3f (float value)
 Initialize all elements to a single value.
 
constexpr GfVec3f (float s0, float s1, float s2)
 Initialize all elements with explicit arguments.
 
template<class Scl >
constexpr GfVec3f (Scl const *p)
 Construct with pointer to values.
 
 GfVec3f (class GfVec3d const &other)
 Construct from GfVec3d.
 
 GfVec3f (class GfVec3h const &other)
 Implicitly convert from GfVec3h.
 
 GfVec3f (class GfVec3i const &other)
 Implicitly convert from GfVec3i.
 
GfVec3fSet (float s0, float s1, float s2)
 Set all elements with passed arguments.
 
GfVec3fSet (float const *a)
 Set all elements with a pointer to data.
 
float const * data () const
 Direct data access.
 
float * data ()
 
float const * GetArray () const
 
float const & operator[] (size_t i) const
 Indexing.
 
float & operator[] (size_t i)
 
bool operator== (GfVec3f const &other) const
 Equality comparison.
 
bool operator!= (GfVec3f const &other) const
 
GF_API bool operator== (class GfVec3d const &other) const
 Equality comparison.
 
GF_API bool operator== (class GfVec3h const &other) const
 Equality comparison.
 
GF_API bool operator== (class GfVec3i const &other) const
 Equality comparison.
 
GfVec3f operator- () const
 Create a vec with negated elements.
 
GfVec3foperator+= (GfVec3f const &other)
 Addition.
 
GfVec3foperator-= (GfVec3f const &other)
 Subtraction.
 
GfVec3foperator*= (double s)
 Multiplication by scalar.
 
GfVec3f operator* (double s) const
 
GfVec3foperator/= (double s)
 Division by scalar.
 
GfVec3f operator/ (double s) const
 
float operator* (GfVec3f const &v) const
 See GfDot().
 
GfVec3f GetProjection (GfVec3f const &v) const
 Returns the projection of this onto v.
 
GfVec3f GetComplement (GfVec3f const &b) const
 Returns the orthogonal complement of this->GetProjection(b).
 
float GetLengthSq () const
 Squared length.
 
float GetLength () const
 Length.
 
float Normalize (float eps=GF_MIN_VECTOR_LENGTH)
 Normalizes the vector in place to unit length, returning the length before normalization.
 
GfVec3f GetNormalized (float eps=GF_MIN_VECTOR_LENGTH) const
 
GF_API void BuildOrthonormalFrame (GfVec3f *v1, GfVec3f *v2, float eps=GF_MIN_VECTOR_LENGTH) const
 Sets v1 and v2 to unit vectors such that v1, v2 and *this are mutually orthogonal.
 
Swizzles

Each accessor returns a new vector built from this one's components, in the order named.

For example zyx() returns GfVec3f(z, y, x).

Every permutation of 2 to 3 of the 3 components is available. Repeated components (xx, xyy) are not; nor are single-component swizzles, which are just the components themselves.

The results are ordinary GfVecs, so all the usual operators, GfDot() and so on apply to them. They are values, not references into this vector, so they cannot be assigned through.

constexpr GfVec2f xy () const
 
constexpr GfVec2f xz () const
 
constexpr GfVec2f yx () const
 
constexpr GfVec2f yz () const
 
constexpr GfVec2f zx () const
 
constexpr GfVec2f zy () const
 
constexpr GfVec3f xyz () const
 
constexpr GfVec3f xzy () const
 
constexpr GfVec3f yxz () const
 
constexpr GfVec3f yzx () const
 
constexpr GfVec3f zxy () const
 
constexpr GfVec3f zyx () const
 

Static Public Member Functions

static GfVec3f XAxis ()
 Create a unit vector along the X-axis.
 
static GfVec3f YAxis ()
 Create a unit vector along the Y-axis.
 
static GfVec3f ZAxis ()
 Create a unit vector along the Z-axis.
 
static GfVec3f Axis (size_t i)
 Create a unit vector along the i-th axis, zero-based.
 
static GF_API bool OrthogonalizeBasis (GfVec3f *tx, GfVec3f *ty, GfVec3f *tz, const bool normalize, double eps=GF_MIN_ORTHO_TOLERANCE)
 Orthogonalize and optionally normalize a set of basis vectors.
 

Public Attributes

Vector Components

The vector's components, which are also its storage.

These are public and directly readable and writable.

The components are contiguous and in declaration order, so &x points to dimension values. See data() and operator[]().

For multi-component access see the swizzle accessors below, which return a new vector by value.

float x
 
float y
 
float z
 

Static Public Attributes

static const size_t dimension = 3
 

Friends

size_t hash_value (GfVec3f const &vec)
 Hash.
 
GfVec3f operator+ (GfVec3f const &l, GfVec3f const &r)
 
GfVec3f operator- (GfVec3f const &l, GfVec3f const &r)
 
GfVec3f operator* (double s, GfVec3f const &v)
 

Detailed Description

Basic type for a vector of 3 float components.

Represents a vector of 3 components of type float. It is intended to be fast and simple.

Definition at line 46 of file vec3f.h.

Member Typedef Documentation

◆ ScalarType

float ScalarType

Scalar element type and dimension.

Definition at line 50 of file vec3f.h.

Constructor & Destructor Documentation

◆ GfVec3f() [1/7]

GfVec3f ( )
default

GfVec3f value-initializes to zero and performs no default initialization, like float or double.

◆ GfVec3f() [2/7]

GfVec3f ( float value)
inlineexplicitconstexpr

Initialize all elements to a single value.

Definition at line 72 of file vec3f.h.

◆ GfVec3f() [3/7]

GfVec3f ( float s0,
float s1,
float s2 )
inlineconstexpr

Initialize all elements with explicit arguments.

Definition at line 78 of file vec3f.h.

◆ GfVec3f() [4/7]

template<class Scl >
GfVec3f ( Scl const * p)
inlineexplicitconstexpr

Construct with pointer to values.

Definition at line 85 of file vec3f.h.

◆ GfVec3f() [5/7]

GfVec3f ( class GfVec3d const & other)
inlineexplicit

Construct from GfVec3d.

Definition at line 377 of file vec3f.h.

◆ GfVec3f() [6/7]

GfVec3f ( class GfVec3h const & other)
inline

Implicitly convert from GfVec3h.

Definition at line 384 of file vec3f.h.

◆ GfVec3f() [7/7]

GfVec3f ( class GfVec3i const & other)
inline

Implicitly convert from GfVec3i.

Definition at line 391 of file vec3f.h.

Member Function Documentation

◆ Axis()

static GfVec3f Axis ( size_t i)
inlinestatic

Create a unit vector along the i-th axis, zero-based.

Return the zero vector if i is greater than or equal to 3.

Definition at line 121 of file vec3f.h.

◆ BuildOrthonormalFrame()

GF_API void BuildOrthonormalFrame ( GfVec3f * v1,
GfVec3f * v2,
float eps = GF_MIN_VECTOR_LENGTH ) const

Sets v1 and v2 to unit vectors such that v1, v2 and *this are mutually orthogonal.

If the length L of *this is smaller than eps, then v1 and v2 will have magnitude L/eps. As a result, the function delivers a continuous result as *this shrinks in length.

◆ data() [1/2]

float * data ( )
inline

Definition at line 147 of file vec3f.h.

◆ data() [2/2]

float const * data ( ) const
inline

Direct data access.

data() is the only member that relies on the components being contiguous; every other member either names them directly or goes through here.

Definition at line 146 of file vec3f.h.

◆ GetArray()

float const * GetArray ( ) const
inline

Definition at line 148 of file vec3f.h.

◆ GetComplement()

GfVec3f GetComplement ( GfVec3f const & b) const
inline

Returns the orthogonal complement of this->GetProjection(b).

That is:

*this - this->GetProjection(b)
GfVec3f GetProjection(GfVec3f const &v) const
Returns the projection of this onto v.
Definition vec3f.h:242

Definition at line 251 of file vec3f.h.

◆ GetLength()

float GetLength ( ) const
inline

Length.

Definition at line 261 of file vec3f.h.

◆ GetLengthSq()

float GetLengthSq ( ) const
inline

Squared length.

Definition at line 256 of file vec3f.h.

◆ GetNormalized()

GfVec3f GetNormalized ( float eps = GF_MIN_VECTOR_LENGTH) const
inline

Definition at line 281 of file vec3f.h.

◆ GetProjection()

GfVec3f GetProjection ( GfVec3f const & v) const
inline

Returns the projection of this onto v.

That is:

v * (*this * v)

Definition at line 242 of file vec3f.h.

◆ Normalize()

float Normalize ( float eps = GF_MIN_VECTOR_LENGTH)
inline

Normalizes the vector in place to unit length, returning the length before normalization.

If the length of the vector is smaller than eps, then the vector is set to vector/eps. The original length of the vector is returned. See also GfNormalize().

Definition at line 273 of file vec3f.h.

◆ operator!=()

bool operator!= ( GfVec3f const & other) const
inline

Definition at line 165 of file vec3f.h.

◆ operator*() [1/2]

GfVec3f operator* ( double s) const
inline

Definition at line 214 of file vec3f.h.

◆ operator*() [2/2]

float operator* ( GfVec3f const & v) const
inline

See GfDot().

Definition at line 234 of file vec3f.h.

◆ operator*=()

GfVec3f & operator*= ( double s)
inline

Multiplication by scalar.

Definition at line 208 of file vec3f.h.

◆ operator+=()

GfVec3f & operator+= ( GfVec3f const & other)
inline

Addition.

Definition at line 186 of file vec3f.h.

◆ operator-()

GfVec3f operator- ( ) const
inline

Create a vec with negated elements.

Definition at line 181 of file vec3f.h.

◆ operator-=()

GfVec3f & operator-= ( GfVec3f const & other)
inline

Subtraction.

Definition at line 197 of file vec3f.h.

◆ operator/()

GfVec3f operator/ ( double s) const
inline

Definition at line 229 of file vec3f.h.

◆ operator/=()

GfVec3f & operator/= ( double s)
inline

Division by scalar.

Definition at line 223 of file vec3f.h.

◆ operator==() [1/4]

GF_API bool operator== ( class GfVec3d const & other) const

Equality comparison.

◆ operator==() [2/4]

GF_API bool operator== ( class GfVec3h const & other) const

Equality comparison.

◆ operator==() [3/4]

GF_API bool operator== ( class GfVec3i const & other) const

Equality comparison.

◆ operator==() [4/4]

bool operator== ( GfVec3f const & other) const
inline

Equality comparison.

Definition at line 160 of file vec3f.h.

◆ operator[]() [1/2]

float & operator[] ( size_t i)
inline

Definition at line 152 of file vec3f.h.

◆ operator[]() [2/2]

float const & operator[] ( size_t i) const
inline

Indexing.

Definition at line 151 of file vec3f.h.

◆ OrthogonalizeBasis()

static GF_API bool OrthogonalizeBasis ( GfVec3f * tx,
GfVec3f * ty,
GfVec3f * tz,
const bool normalize,
double eps = GF_MIN_ORTHO_TOLERANCE )
static

Orthogonalize and optionally normalize a set of basis vectors.

This uses an iterative method that is very stable even when the vectors are far from orthogonal (close to colinear). The number of iterations and thus the computation time does increase as the vectors become close to colinear, however. Returns a bool specifying whether the solution converged after a number of iterations. If it did not converge, the returned vectors will be as close as possible to orthogonal within the iteration limit. Colinear vectors will be unaltered, and the method will return false.

◆ Set() [1/2]

GfVec3f & Set ( float const * a)
inline

Set all elements with a pointer to data.

Definition at line 137 of file vec3f.h.

◆ Set() [2/2]

GfVec3f & Set ( float s0,
float s1,
float s2 )
inline

Set all elements with passed arguments.

Definition at line 129 of file vec3f.h.

◆ XAxis()

static GfVec3f XAxis ( )
inlinestatic

Create a unit vector along the X-axis.

Definition at line 99 of file vec3f.h.

◆ xy()

Vec xy ( ) const
constexpr

Definition at line 400 of file vec3f.h.

◆ xyz()

Vec xyz ( ) const
constexpr

Definition at line 448 of file vec3f.h.

◆ xz()

Vec xz ( ) const
constexpr

Definition at line 408 of file vec3f.h.

◆ xzy()

Vec xzy ( ) const
constexpr

Definition at line 456 of file vec3f.h.

◆ YAxis()

static GfVec3f YAxis ( )
inlinestatic

Create a unit vector along the Y-axis.

Definition at line 106 of file vec3f.h.

◆ yx()

Vec yx ( ) const
constexpr

Definition at line 416 of file vec3f.h.

◆ yxz()

Vec yxz ( ) const
constexpr

Definition at line 464 of file vec3f.h.

◆ yz()

Vec yz ( ) const
constexpr

Definition at line 424 of file vec3f.h.

◆ yzx()

Vec yzx ( ) const
constexpr

Definition at line 472 of file vec3f.h.

◆ ZAxis()

static GfVec3f ZAxis ( )
inlinestatic

Create a unit vector along the Z-axis.

Definition at line 113 of file vec3f.h.

◆ zx()

Vec zx ( ) const
constexpr

Definition at line 432 of file vec3f.h.

◆ zxy()

Vec zxy ( ) const
constexpr

Definition at line 480 of file vec3f.h.

◆ zy()

Vec zy ( ) const
constexpr

Definition at line 440 of file vec3f.h.

◆ zyx()

Vec zyx ( ) const
constexpr

Definition at line 488 of file vec3f.h.

Friends And Related Symbol Documentation

◆ hash_value

size_t hash_value ( GfVec3f const & vec)
friend

Hash.

Definition at line 155 of file vec3f.h.

◆ operator*

GfVec3f operator* ( double s,
GfVec3f const & v )
friend

Definition at line 217 of file vec3f.h.

◆ operator+

GfVec3f operator+ ( GfVec3f const & l,
GfVec3f const & r )
friend

Definition at line 192 of file vec3f.h.

◆ operator-

GfVec3f operator- ( GfVec3f const & l,
GfVec3f const & r )
friend

Definition at line 203 of file vec3f.h.

Member Data Documentation

◆ dimension

const size_t dimension = 3
static

Definition at line 51 of file vec3f.h.

◆ x

float x

Definition at line 64 of file vec3f.h.

◆ y

float y

Definition at line 64 of file vec3f.h.

◆ z

float z

Definition at line 64 of file vec3f.h.


The documentation for this class was generated from the following file: