FdkBaseLib 2.1.1
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
fdk::Vec2< T > Class Template Reference

#include <Vec2.h>

Public Types

using value_type = T
 
using reference = T &
 
using const_reference = const T &
 

Public Member Functions

 Vec2 ()=default
 Default constructor leaves garbage in contents.
 
template<typename S >
 Vec2 (const Vec2< S > &b)
 Copy constructor supports type conversion.
 
 Vec2 (T a)
 Constructor that sets all components to a single value.
 
 Vec2 (T a, T b)
 Constructor that sets separate components.
 
template<typename S >
 Vec2 (S *v)
 Constructor from an array of 2 numbers.
 
template<typename S >
 Vec2 (const S *v)
 
 operator Vec2< fdk::half > () const
 Returns value as a specific type:
 
 operator Vec2< float > () const
 
 operator Vec2< double > () const
 
 operator Vec2< int > () const
 
Vec2< fdk::halfasVec2h () const
 
Vec2< float > asVec2f () const
 
Vec2< double > asVec2d () const
 
Vec2< int > asVec2i () const
 
T & operator[] (int n)
 
const T & operator[] (int n) const
 
T * array ()
 Returns a pointer to the first element.
 
const T * array () const
 
void set (T d)
 Set all components to a single value.
 
void set (T a, T b)
 Set all components.
 
void setToZero ()
 Set components to 0.
 
void setToOne ()
 Set components to 1.
 
void clear ()
 Type-specific clear. Sets all components to 0.
 
void append (fdk::Hash &hash) const
 Add this to a fdk::Hash object.
 
template<typename S >
Vec2 operator* (const Mat4< S > &m) const
 
template<typename S >
Vec2operator*= (const Mat4< S > &m)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec2 operator* (S d) const
 
Vec2 operator* (const Vec2 &v) const
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec2operator*= (S d)
 
Vec2operator*= (const Vec2 &v)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec2 operator/ (S d) const
 
Vec2 operator/ (const Vec2 &v) const
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec2operator/= (S d)
 
Vec2operator/= (const Vec2 &v)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec2 operator+ (S d) const
 
Vec2 operator+ (const Vec2 &v) const
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec2operator+= (S d)
 
Vec2operator+= (const Vec2 &v)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec2 operator- (S d) const
 
Vec2 operator- (const Vec2 &v) const
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > = true>
Vec2operator-= (S d)
 
Vec2operator-= (const Vec2 &v)
 
Vec2 operator- () const
 
void negate ()
 
bool operator== (const Vec2 &v) const
 
bool operator!= (const Vec2 &v) const
 
bool operator== (T d) const
 
bool operator!= (T d) const
 
bool operator< (const Vec2 &v) const
 Fairly arbitrary operator so you can store these in ordered arrays.
 
length () const
 Also known as the absolute value or magnitude of the vector.
 
lengthSquared () const
 Same as this dot this, length() squared.
 
distanceBetween (const Vec2 &v) const
 Same as (this-v).length()
 
distanceSquared (const Vec2 &v) const
 Same as (this-v).lengthSquared()
 
dot (const Vec2 &v) const
 Dot product.
 
cross (const Vec2 &v) const
 Returns the Z component of the cross product, Ux * Vy - Uy * Vx.
 
normalize ()
 Change the vector to be unit length. Returns the original length.
 
Vec2 normalized () const
 
Vec2 inverted () const
 
template<typename S >
Vec2 clamped (S min, S max) const
 
Vec2 clamped () const
 
minimumComponent () const
 Returns the minimum element.
 
Vec2 minimum (const Vec2 &v) const
 
maximumComponent () const
 Returns the maximum element.
 
Vec2 maximum (const Vec2 &v) const
 
largestAxis () const
 Returns the absolute value of the largest element.
 
template<typename S >
Vec2< T > interpolateTo (const Vec2< T > &b, S t) const
 Linear-interpolate between this Vec2 and another at t, where t=0..1.
 
template<typename S >
Vec2< T > lerpClampedTo (const Vec2< T > &b, S t) const
 
template<typename S >
Vec2< T > lerpUnclampedTo (const Vec2< T > &b, S t) const
 
bool isZero () const
 
bool notZero () const
 
bool greaterThanZero () const
 
void roundIfNearlyZero (T threshold=std::numeric_limits< T >::epsilon())
 Round off each element if nearly one or zero within the type's epsilon default or user-provided threshold.
 
void roundIfNearlyOne (T threshold=std::numeric_limits< T >::epsilon())
 
template<typename S >
Vec2< T > operator* (const Mat4< S > &m) const
 
template<typename S >
Vec2< T > & operator*= (const Mat4< S > &m)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > >
Vec2< T > & operator*= (S d)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > >
Vec2< T > & operator/= (S d)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > >
Vec2< T > & operator+= (S d)
 
template<typename S , std::enable_if_t< fdk::is_arithmetic< S >, bool > >
Vec2< T > & operator-= (S d)
 

Public Attributes

x
 
y
 the data
 

Static Public Attributes

static constexpr uint8_t kNumElements = 2
 
static constexpr uint8_t X = 0
 
static constexpr uint8_t Y = 1
 
static const Vec2 XAxis
 
static const Vec2 YAxis
 

Detailed Description

template<typename T>
class fdk::Vec2< T >

2-component vector

Member Function Documentation

◆ normalized()

template<typename T >
Vec2< T > fdk::Vec2< T >::normalized
inline

Returns the normalized unit vector form of this vector. If this vector is null, then a null vector is returned.



©2024 The Foundry Visionmongers, Ltd. All Rights Reserved.
www.foundry.com