OpenVDB 11.0.0

Loading...
Searching...
No Matches
Vec2< T > Class Template Reference

`#include <openvdb/math/Vec2.h>`

Inheritance diagram for Vec2< T >:

## Public Types
using | value_type = T
using | ValueType = T

## Public Member Functions
| Vec2 ()=default
| Vec2 (T val)
| Construct a vector all of whose components have the given value.
| Vec2 (T x, T y)
| Constructor with two arguments, e.g. Vec2f v(1,2,3);.
template<typename Source>
| Vec2 (Source *a)
| Constructor with array argument, e.g. float a[2]; Vec2f v(a);.
template<typename Source>
| Vec2 (const Tuple< 2, Source > &t)
| Conversion constructor.
template<typename Other>
| Vec2 (Other val, typename std::enable_if< std::is_arithmetic< Other >::value, Conversion >::type=Conversion{})
| Construct a vector all of whose components have the given value, which may be of an arithmetic type different from this vector's value type.
T & | x ()
| Reference to the component, e.g. v.x() = 4.5f;.
T & | y ()
T | x () const
| Get the component, e.g. float f = v.y();.
T | y () const
T & | operator() (int i)
| Alternative indexed reference to the elements.
T | operator() (int i) const
| Alternative indexed constant reference to the elements,.
T * | asPointer ()
const T * | asPointer () const
const Vec2< T > & | init (T x=0, T y=0)
const Vec2< T > & | setZero ()
| Set "this" vector to zero.
template<typename Source>
const Vec2< T > & | operator= (const Vec2< Source > &v)
| Assignment operator.
bool | operator== (const Vec2< T > &v) const
| Equality operator, does exact floating point comparisons.
bool | operator!= (const Vec2< T > &v) const
| Inequality operator, does exact floating point comparisons.
bool | eq (const Vec2< T > &v, T eps=static_cast< T >(1.0e-7)) const
| Test if "this" vector is equivalent to vector v with tolerance of eps.
Vec2< T > | operator- () const
| Negation operator, for e.g. v1 = -v2;.
template<typename T0, typename T1>
const Vec2< T > & | add (const Vec2< T0 > &v1, const Vec2< T1 > &v2)
template<typename T0, typename T1>
const Vec2< T > & | sub (const Vec2< T0 > &v1, const Vec2< T1 > &v2)
template<typename T0, typename T1>
const Vec2< T > & | scale (T0 scalar, const Vec2< T1 > &v)
template<typename T0, typename T1>
const Vec2< T > & | div (T0 scalar, const Vec2< T1 > &v)
T | dot (const Vec2< T > &v) const
| Dot product.
T | length () const
| Length of the vector.
T | lengthSqr () const
const Vec2< T > & | exp ()
const Vec2< T > & | log ()
T | sum () const
| Return the sum of all the vector components.
T | product () const
| Return the product of all the vector components.
bool | normalize (T eps=static_cast< T >(1.0e-8))
| this = normalized this
Vec2< T > | unit (T eps=0) const
| return normalized this, throws if null vector
Vec2< T > | unit (T eps, T &len) const
| return normalized this and length, throws if null vector
Vec2< T > | unitSafe () const
| return normalized this, or (1, 0) if this is null vector
template<typename S>
const Vec2< T > & | operator*= (S scalar)
| Multiply each element of this vector by scalar.
template<typename S>
const Vec2< T > & | operator*= (const Vec2< S > &v1)
| Multiply each element of this vector by the corresponding element of the given vector.
template<typename S>
const Vec2< T > & | operator/= (S scalar)
| Divide each element of this vector by scalar.
template<typename S>
const Vec2< T > & | operator/= (const Vec2< S > &v1)
| Divide each element of this vector by the corresponding element of the given vector.
template<typename S>
const Vec2< T > & | operator+= (S scalar)
| Add scalar to each element of this vector.
template<typename S>
const Vec2< T > & | operator+= (const Vec2< S > &v1)
| Add each element of the given vector to the corresponding element of this vector.
template<typename S>
const Vec2< T > & | operator-= (S scalar)
| Subtract scalar from each element of this vector.
template<typename S>
const Vec2< T > & | operator-= (const Vec2< S > &v1)
| Subtract each element of the given vector from the corresponding element of this vector.
T | component (const Vec2< T > &onto, T eps=static_cast< T >(1.0e-8)) const
Vec2< T > | projection (const Vec2< T > &onto, T eps=static_cast< T >(1.0e-8)) const
Vec2< T > | getArbPerpendicular () const
T | operator[] (IdxT i) const

## Static Public Member Functions
static unsigned | numRows ()
static unsigned | numColumns ()
static unsigned | numElements ()
static Vec2< T > | zero ()
| Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();.
static Vec2< T > | ones ()

## Static Public Attributes
static const int | size

## Compatibility
These are mostly for backwards compatibility with functions that take old-style Vs (which are just arrays).
void | toV (S *v) const
| Copies this tuple into an array of a compatible type.
value_type * | asV ()
| Exposes the internal array. Be careful when using this function.
std::string | str () const
void | write (std::ostream &os) const
| Copies this tuple into an array of a compatible type.
void | read (std::istream &is)
| Copies this tuple into an array of a compatible type.
bool | isNan () const
| True if a Nan is present in this tuple.
bool | isInfinite () const
| True if an Inf is present in this tuple.
bool | isFinite () const
| True if no Nan or Inf values are present.
bool | isZero () const
| True if all elements are exactly zero.
T | mm [SIZE]
| Copies this tuple into an array of a compatible type.

## Member Typedef Documentation

## ◆ value_type

template<typename T>

using value_type = T

## ◆ ValueType

template<typename T>

using ValueType = T

## Constructor & Destructor Documentation

## ◆ Vec2() [1/6]

template<typename T>

Vec2 | ( |  | ) |
| default

Trivial constructor, the vector is NOT initialized

Note
  destructor, copy constructor, assignment operator and move constructor are left to be defined by the compiler (default)

## ◆ Vec2() [2/6]

template<typename T>

Vec2 | ( | T | val | ) |
| inline explicit

Construct a vector all of whose components have the given value.

## ◆ Vec2() [3/6]

template<typename T>

Vec2 | ( | T | x,
|  | T | y )
| inline

Constructor with two arguments, e.g. Vec2f v(1,2,3);.

## ◆ Vec2() [4/6]

template<typename T>
template<typename Source>

Vec2 | ( | Source * | a | ) |
| inline

Constructor with array argument, e.g. float a[2]; Vec2f v(a);.

## ◆ Vec2() [5/6]

template<typename T>
template<typename Source>

Vec2 | ( | const Tuple< 2, Source > & | t | ) |
| inline explicit

Conversion constructor.

## ◆ Vec2() [6/6]

template<typename T>
template<typename Other>

Vec2 | ( | Other | val,
|  | typename std::enable_if< std::is_arithmetic< Other >::value, Conversion >::type | = Conversion{} )
| inline explicit

Construct a vector all of whose components have the given value, which may be of an arithmetic type different from this vector's value type.

Type conversion warnings are suppressed.

## Member Function Documentation

## ◆ add()

template<typename T>
template<typename T0, typename T1>

const Vec2< T > & add | ( | const Vec2< T0 > & | v1,
|  | const Vec2< T1 > & | v2 )
| inline

this = v1 + v2 "this", v1 and v2 need not be distinct objects, e.g. v.add(v1,v);

## ◆ asPointer() [1/2]

template<typename T>

T * asPointer | ( |  | ) |
| inline

## ◆ asPointer() [2/2]

template<typename T>

const T * asPointer | ( |  | ) | const
| inline

## ◆ asV()

value_type * asV | ( |  | ) |
| inline inherited

Exposes the internal array. Be careful when using this function.

## ◆ component()

template<typename T>

T component | ( | const Vec2< T > & | onto,
|  | T | eps = static_cast<T>(1.0e-8) ) const
| inline

Returns the scalar component of v in the direction of onto, onto need not be unit. e.g float c = Vec2f::component(v1,v2);

## ◆ div()

template<typename T>
template<typename T0, typename T1>

const Vec2< T > & div | ( | T0 | scalar,
|  | const Vec2< T1 > & | v )
| inline

## ◆ dot()

template<typename T>

T dot | ( | const Vec2< T > & | v | ) | const
| inline

Dot product.

## ◆ eq()

template<typename T>

bool eq | ( | const Vec2< T > & | v,
|  | T | eps = static_cast<T>(1.0e-7) ) const
| inline

Test if "this" vector is equivalent to vector v with tolerance of eps.

## ◆ exp()

template<typename T>

const Vec2< T > & exp | ( |  | ) |
| inline

Return a reference to itsef after the exponent has been applied to all the vector components.

## ◆ getArbPerpendicular()

template<typename T>

Vec2< T > getArbPerpendicular | ( |  | ) | const
| inline

Return an arbitrary unit vector perpendicular to v Vector v must be a unit vector e.g. v.normalize(); Vec2f n = Vec2f::getArbPerpendicular(v);

## ◆ init()

template<typename T>

const Vec2< T > & init | ( | T | x = 0,
|  | T | y = 0 )
| inline

"this" vector gets initialized to [x, y, z], calling v.init(); has same effect as calling v = Vec2::zero();

## ◆ isFinite()

bool isFinite | ( |  | ) | const
| inline inherited

True if no Nan or Inf values are present.

## ◆ isInfinite()

bool isInfinite | ( |  | ) | const
| inline inherited

True if an Inf is present in this tuple.

## ◆ isNan()

bool isNan | ( |  | ) | const
| inline inherited

True if a Nan is present in this tuple.

## ◆ isZero()

bool isZero | ( |  | ) | const
| inline inherited

True if all elements are exactly zero.

## ◆ length()

template<typename T>

T length | ( |  | ) | const
| inline

Length of the vector.

## ◆ lengthSqr()

template<typename T>

T lengthSqr | ( |  | ) | const
| inline

Squared length of the vector, much faster than length() as it does not involve square root

## ◆ log()

template<typename T>

const Vec2< T > & log | ( |  | ) |
| inline

Return a reference to itself after log has been applied to all the vector components.

## ◆ normalize()

template<typename T>

bool normalize | ( | T | eps = static_cast<T>(1.0e-8) | ) |
| inline

this = normalized this

## ◆ numColumns()

template<typename T>

unsigned numColumns | ( |  | ) |
| inline static

## ◆ numElements()

template<typename T>

unsigned numElements | ( |  | ) |
| inline static

## ◆ numRows()

template<typename T>

unsigned numRows | ( |  | ) |
| inline static

## ◆ ones()

template<typename T>

Vec2< T > ones | ( |  | ) |
| inline static

## ◆ operator!=()

template<typename T>

bool operator!= | ( | const Vec2< T > & | v | ) | const
| inline

Inequality operator, does exact floating point comparisons.

## ◆ operator()() [1/2]

template<typename T>

T & operator() | ( | int | i | ) |
| inline

Alternative indexed reference to the elements.

## ◆ operator()() [2/2]

template<typename T>

T operator() | ( | int | i | ) | const
| inline

Alternative indexed constant reference to the elements,.

## ◆ operator*=() [1/2]

template<typename T>
template<typename S>

const Vec2< T > & operator*= | ( | const Vec2< S > & | v1 | ) |
| inline

Multiply each element of this vector by the corresponding element of the given vector.

## ◆ operator*=() [2/2]

template<typename T>
template<typename S>

const Vec2< T > & operator*= | ( | S | scalar | ) |
| inline

Multiply each element of this vector by scalar.

## ◆ operator+=() [1/2]

template<typename T>
template<typename S>

const Vec2< T > & operator+= | ( | const Vec2< S > & | v1 | ) |
| inline

Add each element of the given vector to the corresponding element of this vector.

## ◆ operator+=() [2/2]

template<typename T>
template<typename S>

const Vec2< T > & operator+= | ( | S | scalar | ) |
| inline

Add scalar to each element of this vector.

## ◆ operator-()

template<typename T>

Vec2< T > operator- | ( |  | ) | const
| inline

Negation operator, for e.g. v1 = -v2;.

## ◆ operator-=() [1/2]

template<typename T>
template<typename S>

const Vec2< T > & operator-= | ( | const Vec2< S > & | v1 | ) |
| inline

Subtract each element of the given vector from the corresponding element of this vector.

## ◆ operator-=() [2/2]

template<typename T>
template<typename S>

const Vec2< T > & operator-= | ( | S | scalar | ) |
| inline

Subtract scalar from each element of this vector.

## ◆ operator/=() [1/2]

template<typename T>
template<typename S>

const Vec2< T > & operator/= | ( | const Vec2< S > & | v1 | ) |
| inline

Divide each element of this vector by the corresponding element of the given vector.

## ◆ operator/=() [2/2]

template<typename T>
template<typename S>

const Vec2< T > & operator/= | ( | S | scalar | ) |
| inline

Divide each element of this vector by scalar.

## ◆ operator=()

template<typename T>
template<typename Source>

const Vec2< T > & operator= | ( | const Vec2< Source > & | v | ) |
| inline

Assignment operator.

## ◆ operator==()

template<typename T>

bool operator== | ( | const Vec2< T > & | v | ) | const
| inline

Equality operator, does exact floating point comparisons.

## ◆ operator[]()

T operator[] | ( | IdxT | i | ) | const
| inline inherited

## ◆ product()

template<typename T>

T product | ( |  | ) | const
| inline

Return the product of all the vector components.

## ◆ projection()

template<typename T>

Vec2< T > projection | ( | const Vec2< T > & | onto,
|  | T | eps = static_cast<T>(1.0e-8) ) const
| inline

Return the projection of v onto the vector, onto need not be unit e.g. Vec2f v = Vec2f::projection(v,n);

## ◆ read()

void read | ( | std::istream & | is | ) |
| inline inherited

Copies this tuple into an array of a compatible type.

## ◆ scale()

template<typename T>
template<typename T0, typename T1>

const Vec2< T > & scale | ( | T0 | scalar,
|  | const Vec2< T1 > & | v )
| inline

this = scalar*v, v need not be a distinct object from "this", e.g. v.scale(1.5,v1);

## ◆ setZero()

template<typename T>

const Vec2< T > & setZero | ( |  | ) |
| inline

Set "this" vector to zero.

## ◆ str()

std::string str | ( |  | ) | const
| inline inherited

Returns
  string representation of Classname

## ◆ sub()

template<typename T>
template<typename T0, typename T1>

const Vec2< T > & sub | ( | const Vec2< T0 > & | v1,
|  | const Vec2< T1 > & | v2 )
| inline

this = v1 - v2 "this", v1 and v2 need not be distinct objects, e.g. v.sub(v1,v);

## ◆ sum()

template<typename T>

T sum | ( |  | ) | const
| inline

Return the sum of all the vector components.

## ◆ toV()

void toV | ( | S * | v | ) | const
| inline inherited

Copies this tuple into an array of a compatible type.

## ◆ unit() [1/2]

template<typename T>

Vec2< T > unit | ( | T | eps,
|  | T & | len ) const
| inline

return normalized this and length, throws if null vector

## ◆ unit() [2/2]

template<typename T>

Vec2< T > unit | ( | T | eps = 0 | ) | const
| inline

return normalized this, throws if null vector

## ◆ unitSafe()

template<typename T>

Vec2< T > unitSafe | ( |  | ) | const
| inline

return normalized this, or (1, 0) if this is null vector

## ◆ write()

void write | ( | std::ostream & | os | ) | const
| inline inherited

Copies this tuple into an array of a compatible type.

## ◆ x() [1/2]

template<typename T>

T & x | ( |  | ) |
| inline

Reference to the component, e.g. v.x() = 4.5f;.

## ◆ x() [2/2]

template<typename T>

T x | ( |  | ) | const
| inline

Get the component, e.g. float f = v.y();.

## ◆ y() [1/2]

template<typename T>

T & y | ( |  | ) |
| inline

## ◆ y() [2/2]

template<typename T>

T y | ( |  | ) | const
| inline

## ◆ zero()

template<typename T>

Vec2< T > zero | ( |  | ) |
| inline static

Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();.

## Member Data Documentation

## ◆ mm

T mm[SIZE]
| protected inherited

Copies this tuple into an array of a compatible type.

## ◆ size

const int size
| static inherited