Loading...
Searching...
No Matches
GfVec2f Class Reference

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

#include <vec2f.h>

Public Types

typedef float ScalarType
 Scalar element type and dimension.
 

Public Member Functions

 GfVec2f ()=default
 GfVec2f value-initializes to zero and performs no default initialization, like float or double.
 
constexpr GfVec2f (float value)
 Initialize all elements to a single value.
 
constexpr GfVec2f (float s0, float s1)
 Initialize all elements with explicit arguments.
 
template<class Scl >
constexpr GfVec2f (Scl const *p)
 Construct with pointer to values.
 
 GfVec2f (class GfVec2d const &other)
 Construct from GfVec2d.
 
 GfVec2f (class GfVec2h const &other)
 Implicitly convert from GfVec2h.
 
 GfVec2f (class GfVec2i const &other)
 Implicitly convert from GfVec2i.
 
GfVec2fSet (float s0, float s1)
 Set all elements with passed arguments.
 
GfVec2fSet (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== (GfVec2f const &other) const
 Equality comparison.
 
bool operator!= (GfVec2f const &other) const
 
GF_API bool operator== (class GfVec2d const &other) const
 Equality comparison.
 
GF_API bool operator== (class GfVec2h const &other) const
 Equality comparison.
 
GF_API bool operator== (class GfVec2i const &other) const
 Equality comparison.
 
GfVec2f operator- () const
 Create a vec with negated elements.
 
GfVec2foperator+= (GfVec2f const &other)
 Addition.
 
GfVec2foperator-= (GfVec2f const &other)
 Subtraction.
 
GfVec2foperator*= (double s)
 Multiplication by scalar.
 
GfVec2f operator* (double s) const
 
GfVec2foperator/= (double s)
 Division by scalar.
 
GfVec2f operator/ (double s) const
 
float operator* (GfVec2f const &v) const
 See GfDot().
 
GfVec2f GetProjection (GfVec2f const &v) const
 Returns the projection of this onto v.
 
GfVec2f GetComplement (GfVec2f 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.
 
GfVec2f GetNormalized (float eps=GF_MIN_VECTOR_LENGTH) const
 
Swizzles

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

For example yx() returns GfVec2f(y, x).

Every permutation of 2 to 2 of the 2 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 yx () const
 

Static Public Member Functions

static GfVec2f XAxis ()
 Create a unit vector along the X-axis.
 
static GfVec2f YAxis ()
 Create a unit vector along the Y-axis.
 
static GfVec2f Axis (size_t i)
 Create a unit vector along the i-th axis, zero-based.
 

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
 

Static Public Attributes

static const size_t dimension = 2
 

Friends

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

Detailed Description

Basic type for a vector of 2 float components.

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

Definition at line 45 of file vec2f.h.

Member Typedef Documentation

◆ ScalarType

float ScalarType

Scalar element type and dimension.

Definition at line 49 of file vec2f.h.

Constructor & Destructor Documentation

◆ GfVec2f() [1/7]

GfVec2f ( )
default

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

◆ GfVec2f() [2/7]

GfVec2f ( float value)
inlineexplicitconstexpr

Initialize all elements to a single value.

Definition at line 71 of file vec2f.h.

◆ GfVec2f() [3/7]

GfVec2f ( float s0,
float s1 )
inlineconstexpr

Initialize all elements with explicit arguments.

Definition at line 77 of file vec2f.h.

◆ GfVec2f() [4/7]

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

Construct with pointer to values.

Definition at line 84 of file vec2f.h.

◆ GfVec2f() [5/7]

GfVec2f ( class GfVec2d const & other)
inlineexplicit

Construct from GfVec2d.

Definition at line 318 of file vec2f.h.

◆ GfVec2f() [6/7]

GfVec2f ( class GfVec2h const & other)
inline

Implicitly convert from GfVec2h.

Definition at line 324 of file vec2f.h.

◆ GfVec2f() [7/7]

GfVec2f ( class GfVec2i const & other)
inline

Implicitly convert from GfVec2i.

Definition at line 330 of file vec2f.h.

Member Function Documentation

◆ Axis()

static GfVec2f 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 2.

Definition at line 113 of file vec2f.h.

◆ data() [1/2]

float * data ( )
inline

Definition at line 138 of file vec2f.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 137 of file vec2f.h.

◆ GetArray()

float const * GetArray ( ) const
inline

Definition at line 139 of file vec2f.h.

◆ GetComplement()

GfVec2f GetComplement ( GfVec2f const & b) const
inline

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

That is:

*this - this->GetProjection(b)
GfVec2f GetProjection(GfVec2f const &v) const
Returns the projection of this onto v.
Definition vec2f.h:229

Definition at line 238 of file vec2f.h.

◆ GetLength()

float GetLength ( ) const
inline

Length.

Definition at line 248 of file vec2f.h.

◆ GetLengthSq()

float GetLengthSq ( ) const
inline

Squared length.

Definition at line 243 of file vec2f.h.

◆ GetNormalized()

GfVec2f GetNormalized ( float eps = GF_MIN_VECTOR_LENGTH) const
inline

Definition at line 268 of file vec2f.h.

◆ GetProjection()

GfVec2f GetProjection ( GfVec2f const & v) const
inline

Returns the projection of this onto v.

That is:

v * (*this * v)

Definition at line 229 of file vec2f.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 260 of file vec2f.h.

◆ operator!=()

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

Definition at line 155 of file vec2f.h.

◆ operator*() [1/2]

GfVec2f operator* ( double s) const
inline

Definition at line 201 of file vec2f.h.

◆ operator*() [2/2]

float operator* ( GfVec2f const & v) const
inline

See GfDot().

Definition at line 221 of file vec2f.h.

◆ operator*=()

GfVec2f & operator*= ( double s)
inline

Multiplication by scalar.

Definition at line 196 of file vec2f.h.

◆ operator+=()

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

Addition.

Definition at line 176 of file vec2f.h.

◆ operator-()

GfVec2f operator- ( ) const
inline

Create a vec with negated elements.

Definition at line 171 of file vec2f.h.

◆ operator-=()

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

Subtraction.

Definition at line 186 of file vec2f.h.

◆ operator/()

GfVec2f operator/ ( double s) const
inline

Definition at line 216 of file vec2f.h.

◆ operator/=()

GfVec2f & operator/= ( double s)
inline

Division by scalar.

Definition at line 210 of file vec2f.h.

◆ operator==() [1/4]

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

Equality comparison.

◆ operator==() [2/4]

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

Equality comparison.

◆ operator==() [3/4]

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

Equality comparison.

◆ operator==() [4/4]

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

Equality comparison.

Definition at line 151 of file vec2f.h.

◆ operator[]() [1/2]

float & operator[] ( size_t i)
inline

Definition at line 143 of file vec2f.h.

◆ operator[]() [2/2]

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

Indexing.

Definition at line 142 of file vec2f.h.

◆ Set() [1/2]

GfVec2f & Set ( float const * a)
inline

Set all elements with a pointer to data.

Definition at line 128 of file vec2f.h.

◆ Set() [2/2]

GfVec2f & Set ( float s0,
float s1 )
inline

Set all elements with passed arguments.

Definition at line 121 of file vec2f.h.

◆ XAxis()

static GfVec2f XAxis ( )
inlinestatic

Create a unit vector along the X-axis.

Definition at line 98 of file vec2f.h.

◆ xy()

Vec xy ( ) const
constexpr

Definition at line 338 of file vec2f.h.

◆ YAxis()

static GfVec2f YAxis ( )
inlinestatic

Create a unit vector along the Y-axis.

Definition at line 105 of file vec2f.h.

◆ yx()

Vec yx ( ) const
constexpr

Definition at line 346 of file vec2f.h.

Friends And Related Symbol Documentation

◆ hash_value

size_t hash_value ( GfVec2f const & vec)
friend

Hash.

Definition at line 146 of file vec2f.h.

◆ operator*

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

Definition at line 204 of file vec2f.h.

◆ operator+

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

Definition at line 181 of file vec2f.h.

◆ operator-

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

Definition at line 191 of file vec2f.h.

Member Data Documentation

◆ dimension

const size_t dimension = 2
static

Definition at line 50 of file vec2f.h.

◆ x

float x

Definition at line 63 of file vec2f.h.

◆ y

float y

Definition at line 63 of file vec2f.h.


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