MeshLib C++ Docs
Loading...
Searching...
No Matches
MR::Vector2< T > Struct Template Reference

#include <MRVector2.h>

Public Types

using ValueType = T
 
using MatrixType = Matrix2<T>
 
using SymMatrixType = SymMatrix2<T>
 

Public Member Functions

constexpr Vector2 () noexcept
 
 Vector2 (NoInit) noexcept
 
constexpr Vector2 (T x, T y) noexcept
 
template<typename U >
 MR_REQUIRES_IF_SUPPORTED (std::constructible_from< T, U >) explicit const expr Vector2(const Vector3< U > &v) noexcept
 
template<typename U >
 MR_REQUIRES_IF_SUPPORTED (!std::is_same_v< T, U >) const expr explicit Vector2(const Vector2< U > &v) noexcept
 
constexpr const T & operator[] (int e) const noexcept
 
constexpr T & operator[] (int e) noexcept
 
lengthSq () const
 
auto length () const
 
Vector2 normalized () const MR_REQUIRES_IF_SUPPORTED(!std
 
Vector2 furthestBasisVector() const MR_REQUIRES_IF_SUPPORTED(!std constexpr Vector2 perpendicular () const MR_REQUIRES_IF_SUPPORTED(!std
 returns one of 2 basis unit vector that makes the biggest angle with the direction specified by this
 
bool isFinite () const MR_REQUIRES_IF_SUPPORTED(std
 

Static Public Member Functions

static constexpr Vector2 diagonal (T a) noexcept
 
static constexpr Vector2 plusX () noexcept
 
static constexpr Vector2 plusY () noexcept
 
static constexpr Vector2 minusX () noexcept MR_REQUIRES_IF_SUPPORTED(!std
 
static constexpr Vector2 minusY () noexcept MR_REQUIRES_IF_SUPPORTED(!std
 

Public Attributes

x
 
y
 

Static Public Attributes

static constexpr int elements = 2
 

Friends

constexpr bool operator== (const Vector2< T > &a, const Vector2< T > &b)
 
constexpr bool operator!= (const Vector2< T > &a, const Vector2< T > &b)
 
constexpr const Vector2< T > & operator+ (const Vector2< T > &a)
 NOTE: We use std::declval() in the operators below because libclang 18 in our binding generator is bugged and chokes on decltyping a.x and such. TODO fix this when we update libclang.
 
constexpr auto operator- (const Vector2< T > &a) -> Vector2< decltype(-std::declval< T >())>
 
constexpr auto operator+ (const Vector2< T > &a, const Vector2< T > &b) -> Vector2< decltype(std::declval< T >()+std::declval< T >())>
 
constexpr auto operator- (const Vector2< T > &a, const Vector2< T > &b) -> Vector2< decltype(std::declval< T >() - std::declval< T >())>
 
constexpr auto operator* (T a, const Vector2< T > &b) -> Vector2< decltype(std::declval< T >() *std::declval< T >())>
 
constexpr auto operator* (const Vector2< T > &b, T a) -> Vector2< decltype(std::declval< T >() *std::declval< T >())>
 
constexpr auto operator/ (Vector2< T > b, T a) -> Vector2< decltype(std::declval< T >()/std::declval< T >())>
 
constexpr Vector2< T > & operator+= (Vector2< T > &a, const Vector2< T > &b)
 
constexpr Vector2< T > & operator-= (Vector2< T > &a, const Vector2< T > &b)
 
constexpr Vector2< T > & operator*= (Vector2< T > &a, T b)
 
constexpr Vector2< T > & operator/= (Vector2< T > &a, T b)
 
std::ostream & operator<< (std::ostream &s, const Vector2 &vec)
 
std::istream & operator>> (std::istream &s, Vector2 &vec)
 

Related Symbols

(Note that these are not member symbols.)

template<typename T >
distanceSq (const Vector2< T > &a, const Vector2< T > &b)
 squared distance between two points, which is faster to compute than just distance
 
template<typename T >
distance (const Vector2< T > &a, const Vector2< T > &b)
 distance between two points, better use distanceSq for higher performance
 
template<typename T >
cross (const Vector2< T > &a, const Vector2< T > &b)
 cross product
 
template<typename T >
auto dot (const Vector2< T > &a, const Vector2< T > &b) -> decltype(a.x *b.x)
 dot product
 
template<typename T >
sqr (const Vector2< T > &a)
 squared length
 
template<typename T >
Vector2< T > mult (const Vector2< T > &a, const Vector2< T > &b)
 per component multiplication
 
template<typename T >
Vector2< T > div (const Vector2< T > &a, const Vector2< T > &b)
 per component division
 
template<typename T >
angle (const Vector2< T > &a, const Vector2< T > &b)
 angle in radians between two vectors
 
template<typename T >
MR_BIND_IGNORE_PY auto begin (const Vector2< T > &v)
 We don't need to bind those functions in Python, because this doesn't prevent __iter__ from being generated for the type.
 

Detailed Description

template<typename T>
struct MR::Vector2< T >

two-dimensional vector

Member Typedef Documentation

◆ MatrixType

template<typename T >
using MR::Vector2< T >::MatrixType = Matrix2<T>

◆ SymMatrixType

template<typename T >
using MR::Vector2< T >::SymMatrixType = SymMatrix2<T>

◆ ValueType

template<typename T >
using MR::Vector2< T >::ValueType = T

Constructor & Destructor Documentation

◆ Vector2() [1/3]

template<typename T >
MR::Vector2< T >::Vector2 ( )
inlineconstexprnoexcept

◆ Vector2() [2/3]

template<typename T >
MR::Vector2< T >::Vector2 ( NoInit )
inlineexplicitnoexcept

◆ Vector2() [3/3]

template<typename T >
MR::Vector2< T >::Vector2 ( T x,
T y )
inlineconstexprnoexcept

Member Function Documentation

◆ diagonal()

template<typename T >
static constexpr Vector2 MR::Vector2< T >::diagonal ( T a)
inlinestaticconstexprnoexcept

◆ isFinite()

template<typename T >
bool MR::Vector2< T >::isFinite ( ) const
inlinenodiscard

◆ length()

template<typename T >
auto MR::Vector2< T >::length ( ) const
inline

Calling sqrt this way to hopefully support boost.multiprecision numbers. Returning auto to not break on integral types.

◆ lengthSq()

template<typename T >
T MR::Vector2< T >::lengthSq ( ) const
inline

◆ minusX()

template<typename T >
static constexpr Vector2 MR::Vector2< T >::minusX ( )
inlinestaticconstexprnoexcept

◆ minusY()

template<typename T >
static constexpr Vector2 MR::Vector2< T >::minusY ( )
inlinestaticconstexprnoexcept

◆ MR_REQUIRES_IF_SUPPORTED() [1/2]

template<typename T >
template<typename U >
MR::Vector2< T >::MR_REQUIRES_IF_SUPPORTED ( !std::is_same_v< T, U > ) const &
inlinenoexcept

Here T == U doesn't seem to cause any issues in the C++ code, but we're still disabling it because it somehow gets emitted when generating the bindings, and looks out of place there.

◆ MR_REQUIRES_IF_SUPPORTED() [2/2]

template<typename T >
template<typename U >
MR::Vector2< T >::MR_REQUIRES_IF_SUPPORTED ( std::constructible_from< T, U > ) const &
inlinenoexcept

◆ normalized()

template<typename T >
Vector2 MR::Vector2< T >::normalized ( ) const
inline

◆ operator[]() [1/2]

template<typename T >
const T & MR::Vector2< T >::operator[] ( int e) const
inlineconstexprnoexcept

◆ operator[]() [2/2]

template<typename T >
T & MR::Vector2< T >::operator[] ( int e)
inlineconstexprnoexcept

◆ perpendicular()

template<typename T >
Vector2 furthestBasisVector() const MR_REQUIRES_IF_SUPPORTED(!std constexpr Vector2 MR::Vector2< T >::perpendicular ( ) const
inlineconstexpr

returns one of 2 basis unit vector that makes the biggest angle with the direction specified by this

returns same length vector orthogonal to this (rotated 90 degrees counter-clockwise)

◆ plusX()

template<typename T >
static constexpr Vector2 MR::Vector2< T >::plusX ( )
inlinestaticconstexprnoexcept

◆ plusY()

template<typename T >
static constexpr Vector2 MR::Vector2< T >::plusY ( )
inlinestaticconstexprnoexcept

Friends And Related Symbol Documentation

◆ angle()

template<typename T >
T angle ( const Vector2< T > & a,
const Vector2< T > & b )
related

angle in radians between two vectors

this version is slower and less precise return std::acos( std::clamp( dot( a.normalized(), b.normalized() ), T(-1), T(1) ) );

◆ begin()

template<typename T >
MR_BIND_IGNORE_PY auto begin ( const Vector2< T > & v)
related

We don't need to bind those functions in Python, because this doesn't prevent __iter__ from being generated for the type.

◆ cross()

template<typename T >
T cross ( const Vector2< T > & a,
const Vector2< T > & b )
related

cross product

◆ distance()

template<typename T >
T distance ( const Vector2< T > & a,
const Vector2< T > & b )
related

distance between two points, better use distanceSq for higher performance

◆ distanceSq()

template<typename T >
T distanceSq ( const Vector2< T > & a,
const Vector2< T > & b )
related

squared distance between two points, which is faster to compute than just distance

◆ div()

template<typename T >
Vector2< T > div ( const Vector2< T > & a,
const Vector2< T > & b )
related

per component division

◆ dot()

template<typename T >
auto dot ( const Vector2< T > & a,
const Vector2< T > & b ) -> decltype( a.x * b.x )
related

dot product

◆ mult()

template<typename T >
Vector2< T > mult ( const Vector2< T > & a,
const Vector2< T > & b )
related

per component multiplication

◆ operator!=

template<typename T >
bool operator!= ( const Vector2< T > & a,
const Vector2< T > & b )
friend

◆ operator* [1/2]

template<typename T >
auto operator* ( const Vector2< T > & b,
T a ) -> Vector2<decltype( std::declval<T>() * std::declval<T>() )>
friend

◆ operator* [2/2]

template<typename T >
auto operator* ( T a,
const Vector2< T > & b ) -> Vector2<decltype( std::declval<T>() * std::declval<T>() )>
friend

◆ operator*=

template<typename T >
Vector2< T > & operator*= ( Vector2< T > & a,
T b )
friend

◆ operator+ [1/2]

template<typename T >
const Vector2< T > & operator+ ( const Vector2< T > & a)
friend

NOTE: We use std::declval() in the operators below because libclang 18 in our binding generator is bugged and chokes on decltyping a.x and such. TODO fix this when we update libclang.

◆ operator+ [2/2]

template<typename T >
auto operator+ ( const Vector2< T > & a,
const Vector2< T > & b ) -> Vector2<decltype( std::declval<T>() + std::declval<T>() )>
friend

◆ operator+=

template<typename T >
Vector2< T > & operator+= ( Vector2< T > & a,
const Vector2< T > & b )
friend

◆ operator- [1/2]

template<typename T >
auto operator- ( const Vector2< T > & a) -> Vector2<decltype( -std::declval<T>() )>
friend

◆ operator- [2/2]

template<typename T >
auto operator- ( const Vector2< T > & a,
const Vector2< T > & b ) -> Vector2<decltype( std::declval<T>() - std::declval<T>() )>
friend

◆ operator-=

template<typename T >
Vector2< T > & operator-= ( Vector2< T > & a,
const Vector2< T > & b )
friend

◆ operator/

template<typename T >
auto operator/ ( Vector2< T > b,
T a ) -> Vector2<decltype( std::declval<T>() / std::declval<T>() )>
friend

◆ operator/=

template<typename T >
Vector2< T > & operator/= ( Vector2< T > & a,
T b )
friend

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream & s,
const Vector2< T > & vec )
friend

◆ operator==

template<typename T >
bool operator== ( const Vector2< T > & a,
const Vector2< T > & b )
friend

◆ operator>>

template<typename T >
std::istream & operator>> ( std::istream & s,
Vector2< T > & vec )
friend

◆ sqr()

template<typename T >
T sqr ( const Vector2< T > & a)
related

squared length

Member Data Documentation

◆ elements

template<typename T >
int MR::Vector2< T >::elements = 2
staticconstexpr

◆ x

template<typename T >
T MR::Vector2< T >::x

◆ y

template<typename T >
T MR::Vector2< T >::y

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