[nnm] No Nonsense Math 0.5.0
A No-Nonsense, C++ 17, single-header-only Math library geared towards graphics programming.
Loading...
Searching...
No Matches
nnm::Vector2i< Int > Class Template Reference

#include <nnm.hpp>

Classes

struct  Hash

Public Member Functions

constexpr Vector2i ()
template<typename Real>
constexpr Vector2i (const Vector2< Real > &vector)
constexpr Vector2i (const Int x, const Int y)
constexpr Vector2i abs () const
constexpr Vector2i clamp (const Vector2i &min, const Vector2i &max) const
constexpr Int manhattan_distance (const Vector2i &to) const
constexpr Int length_sqrd () const
constexpr Int dot (const Vector2i &other) const
constexpr Int cross (const Vector2i &other) const
constexpr bool parallel (const Vector2i &other) const
constexpr bool perpendicular (const Vector2i &other) const
constexpr Vector2i arbitrary_perpendicular () const
constexpr Int max () const
constexpr Int abs_max () const
constexpr Int min () const
constexpr Int abs_min () const
constexpr uint8_t max_index () const
constexpr uint8_t abs_max_index () const
constexpr uint8_t min_index () const
constexpr uint8_t abs_min_index () const
const Int * begin () const
const Int * end () const
Int * begin ()
Int * end ()
constexpr const Int & at (const uint8_t index) const
constexpr Int & at (const uint8_t index)
constexpr const Int & operator[] (const uint8_t index) const
constexpr Int & operator[] (const uint8_t index)
constexpr bool operator== (const Vector2i &other) const
constexpr bool operator!= (const Vector2i &other) const
constexpr Vector2i operator+ (const Vector2i &other) const
constexpr Vector2ioperator+= (const Vector2i &other)
constexpr Vector2i operator- (const Vector2i &other) const
constexpr Vector2ioperator-= (const Vector2i &other)
constexpr Vector2i operator* (const Vector2i &other) const
constexpr Vector2ioperator*= (const Vector2i &other)
constexpr Vector2i operator* (const Int value) const
constexpr Vector2ioperator*= (const Int value)
constexpr Vector2i operator/ (const Vector2i &other) const
constexpr Vector2ioperator/= (const Vector2i &other)
constexpr Vector2i operator/ (const Int value) const
constexpr Vector2ioperator/= (const Int value)
constexpr Vector2i operator% (const Vector2i &other) const
constexpr Vector2ioperator%= (const Vector2i &other)
constexpr Vector2i operator% (const Int value) const
constexpr Vector2ioperator%= (const Int value)
constexpr Vector2i operator+ () const
constexpr Vector2i operator- () const
constexpr bool operator< (const Vector2i &other) const
constexpr operator bool () const

Static Public Member Functions

static constexpr Vector2i all (Int value)
static constexpr Vector2i zero ()
static constexpr Vector2i one ()
static constexpr Vector2i axis_x ()
static constexpr Vector2i axis_y ()

Public Attributes

Int x
Int y

Detailed Description

template<typename Int>
class nnm::Vector2i< Int >

2-dimensional vector with integer components.

Template Parameters
IntInteger value.

Constructor & Destructor Documentation

◆ Vector2i() [1/3]

template<typename Int>
nnm::Vector2i< Int >::Vector2i ( )
inlineconstexpr

Initializes all components to zero.

◆ Vector2i() [2/3]

template<typename Int>
template<typename Real>
nnm::Vector2i< Int >::Vector2i ( const Vector2< Real > & vector)
inlineexplicitconstexpr

Casts one integer vector into another

Template Parameters
RealInteger type.
Parameters
vectorVector to cast from.

◆ Vector2i() [3/3]

template<typename Int>
nnm::Vector2i< Int >::Vector2i ( const Int x,
const Int y )
inlineconstexpr

Initialize with specific components.

Parameters
xX value.
yY value.

Member Function Documentation

◆ abs()

template<typename Int>
Vector2i nnm::Vector2i< Int >::abs ( ) const
inlinenodiscardconstexpr

Component-wise absolute value.

Returns
Resulting vector.

◆ abs_max()

template<typename Int>
Int nnm::Vector2i< Int >::abs_max ( ) const
inlinenodiscardconstexpr

Absolute-value maximum component.

Returns
Result.

◆ abs_max_index()

template<typename Int>
uint8_t nnm::Vector2i< Int >::abs_max_index ( ) const
inlinenodiscardconstexpr

Index of the absolute-value maximum component.

Returns
Resulting index.

◆ abs_min()

template<typename Int>
Int nnm::Vector2i< Int >::abs_min ( ) const
inlinenodiscardconstexpr

Absolute-value minimum component.

Returns
Result.

◆ abs_min_index()

template<typename Int>
uint8_t nnm::Vector2i< Int >::abs_min_index ( ) const
inlinenodiscardconstexpr

Index of the absolute-value minimum component.

Returns
Resulting index.

◆ all()

template<typename Int>
constexpr Vector2i nnm::Vector2i< Int >::all ( Int value)
inlinestaticconstexpr

Vector with all components to a value.

Parameters
valueValue to initialize all components with.
Returns
Resulting vector.

◆ arbitrary_perpendicular()

template<typename Int>
Vector2i nnm::Vector2i< Int >::arbitrary_perpendicular ( ) const
inlinenodiscardconstexpr

Returns a vector that is perpendicular to this vector. There are multiple possible perpendicular vectors so an arbitrary perpendicular vector is returned and no assumptions should be made on which solution is returned.

Returns
Resulting perpendicular vector.

◆ at() [1/2]

template<typename Int>
Int & nnm::Vector2i< Int >::at ( const uint8_t index)
inlineconstexpr

Reference to component at index.

Parameters
indexIndex.
Returns
Resulting reference.

◆ at() [2/2]

template<typename Int>
const Int & nnm::Vector2i< Int >::at ( const uint8_t index) const
inlinenodiscardconstexpr

Constant reference to component at index.

Parameters
indexIndex.
Returns
Resulting constant reference.

◆ axis_x()

template<typename Int>
constexpr Vector2i nnm::Vector2i< Int >::axis_x ( )
inlinestaticconstexpr

Normalized vector that points in the direction of the positive x-axis.

Returns
Resulting vector.

◆ axis_y()

template<typename Int>
constexpr Vector2i nnm::Vector2i< Int >::axis_y ( )
inlinestaticconstexpr

Normalized vector that points in the direction of the positive y-axis.

Returns
Resulting vector.

◆ begin() [1/2]

template<typename Int>
Int * nnm::Vector2i< Int >::begin ( )
inline

Start iterator.

Returns
Iterator.

◆ begin() [2/2]

template<typename Int>
const Int * nnm::Vector2i< Int >::begin ( ) const
inlinenodiscard

Start constant iterator.

Returns
Constant iterator.

◆ clamp()

template<typename Int>
Vector2i nnm::Vector2i< Int >::clamp ( const Vector2i< Int > & min,
const Vector2i< Int > & max ) const
inlinenodiscardconstexpr

Component-wise clamp.

Parameters
minMinimum.
maxMaximum.
Returns
Resulting vector.

◆ cross()

template<typename Int>
Int nnm::Vector2i< Int >::cross ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Vector cross product

Parameters
otherOther vector.
Returns
Result.

◆ dot()

template<typename Int>
Int nnm::Vector2i< Int >::dot ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Vector dot product.

Parameters
otherOther vector.
Returns
Result.

◆ end() [1/2]

template<typename Int>
Int * nnm::Vector2i< Int >::end ( )
inline

End iterator.

Returns
Iterator.

◆ end() [2/2]

template<typename Int>
const Int * nnm::Vector2i< Int >::end ( ) const
inlinenodiscard

End constant iterator.

Returns
Constant iterator.

◆ length_sqrd()

template<typename Int>
Int nnm::Vector2i< Int >::length_sqrd ( ) const
inlinenodiscardconstexpr

Squared length of the vector.

Returns
Resulting length.

◆ manhattan_distance()

template<typename Int>
Int nnm::Vector2i< Int >::manhattan_distance ( const Vector2i< Int > & to) const
inlinenodiscardconstexpr

Distance between the position of this vector to another vector along the grid defined by the x and y axes.

Parameters
toPosition to.
Returns
Resulting distance.

◆ max()

template<typename Int>
Int nnm::Vector2i< Int >::max ( ) const
inlinenodiscardconstexpr

Maximum component

Returns
Result.

◆ max_index()

template<typename Int>
uint8_t nnm::Vector2i< Int >::max_index ( ) const
inlinenodiscardconstexpr

Index of the maximum component.

Returns
Resulting index.

◆ min()

template<typename Int>
Int nnm::Vector2i< Int >::min ( ) const
inlinenodiscardconstexpr

Minimum component.

Returns
Result.

◆ min_index()

template<typename Int>
uint8_t nnm::Vector2i< Int >::min_index ( ) const
inlinenodiscardconstexpr

Index of the minimum component.

Returns
Resulting index.

◆ one()

template<typename Int>
constexpr Vector2i nnm::Vector2i< Int >::one ( )
inlinestaticconstexpr

Vector with all components to one.

Returns
Resulting vector.

◆ operator bool()

template<typename Int>
nnm::Vector2i< Int >::operator bool ( ) const
inlineexplicitnodiscardconstexpr

Evaluates to false if all components are zero, true otherwise.

◆ operator!=()

template<typename Int>
bool nnm::Vector2i< Int >::operator!= ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Component-wise inequality.

Parameters
otherOther vector.
Returns
True if not equal, false otherwise.

◆ operator%() [1/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator% ( const Int value) const
inlinenodiscardconstexpr

Component-wise remainder with value.

Parameters
valueValue.
Returns
Result.

◆ operator%() [2/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator% ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Component-wise remainder.

Parameters
otherOther vector.
Returns
Result.

◆ operator%=() [1/2]

template<typename Int>
Vector2i & nnm::Vector2i< Int >::operator%= ( const Int value)
inlineconstexpr

Component-wise remainder with value.

Parameters
valueValue.
Returns
Reference to this modified vector.

◆ operator%=() [2/2]

template<typename Int>
Vector2i & nnm::Vector2i< Int >::operator%= ( const Vector2i< Int > & other)
inlineconstexpr

Component-wise remainder.

Parameters
otherOther vector.
Returns
Reference to this modified vector.

◆ operator*() [1/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator* ( const Int value) const
inlinenodiscardconstexpr

Component-wise multiplication with value.

Parameters
valueValue.
Returns
Result.

◆ operator*() [2/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator* ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Component-wise multiplication.

Parameters
otherOther vector.
Returns
Result.

◆ operator*=() [1/2]

template<typename Int>
Vector2i & nnm::Vector2i< Int >::operator*= ( const Int value)
inlineconstexpr

Component-wise multiplication with value.

Parameters
valueValue.
Returns
Reference to this modified vector.

◆ operator*=() [2/2]

template<typename Int>
Vector2i & nnm::Vector2i< Int >::operator*= ( const Vector2i< Int > & other)
inlineconstexpr

Component-wise multiplication.

Parameters
otherOther vector.
Returns
Reference to this modified vector.

◆ operator+() [1/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator+ ( ) const
inlinenodiscardconstexpr

Unary plus. Does nothing but specified for symmetry with unary minus.

Returns
Result.

◆ operator+() [2/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator+ ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Component-wise addition.

Parameters
otherOther vector.
Returns
Result.

◆ operator+=()

template<typename Int>
Vector2i & nnm::Vector2i< Int >::operator+= ( const Vector2i< Int > & other)
inlineconstexpr

Component-wise addition.

Parameters
otherOther vector.
Returns
Reference to this modified vector.

◆ operator-() [1/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator- ( ) const
inlinenodiscardconstexpr

Component-wise negation.

Returns
Result.

◆ operator-() [2/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator- ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Component-wise subtraction.

Parameters
otherOther vector.
Returns
Result.

◆ operator-=()

template<typename Int>
Vector2i & nnm::Vector2i< Int >::operator-= ( const Vector2i< Int > & other)
inlineconstexpr

Component-wise subtraction.

Parameters
otherOther vector.
Returns
Reference to this modified vector.

◆ operator/() [1/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator/ ( const Int value) const
inlinenodiscardconstexpr

Component-wise division with value.

Parameters
valueValue.
Returns
Result.

◆ operator/() [2/2]

template<typename Int>
Vector2i nnm::Vector2i< Int >::operator/ ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Component-wise division.

Parameters
otherOther vector.
Returns
Result.

◆ operator/=() [1/2]

template<typename Int>
Vector2i & nnm::Vector2i< Int >::operator/= ( const Int value)
inlineconstexpr

Component-wise division with value.

Parameters
valueValue.
Returns
Reference to this modified vector.

◆ operator/=() [2/2]

template<typename Int>
Vector2i & nnm::Vector2i< Int >::operator/= ( const Vector2i< Int > & other)
inlineconstexpr

Component-wise division.

Parameters
otherOther vector.
Returns
Reference to this modified vector.

◆ operator<()

template<typename Int>
bool nnm::Vector2i< Int >::operator< ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Lexicographical comparison between components.

Parameters
otherOther vector.
Returns
True if less than, false otherwise.

◆ operator==()

template<typename Int>
bool nnm::Vector2i< Int >::operator== ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Component-wise equality.

Parameters
otherOther vector.
Returns
True if equal, false otherwise.

◆ operator[]() [1/2]

template<typename Int>
Int & nnm::Vector2i< Int >::operator[] ( const uint8_t index)
inlineconstexpr

Reference to component at index.

Parameters
indexIndex.
Returns
Resulting reference.

◆ operator[]() [2/2]

template<typename Int>
const Int & nnm::Vector2i< Int >::operator[] ( const uint8_t index) const
inlinenodiscardconstexpr

Constant reference to component at index.

Parameters
indexIndex.
Returns
Resulting constant reference.

◆ parallel()

template<typename Int>
bool nnm::Vector2i< Int >::parallel ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Determines if parallel to another vector.

Parameters
otherOther vector.
Returns
True if parallel, false otherwise.

◆ perpendicular()

template<typename Int>
bool nnm::Vector2i< Int >::perpendicular ( const Vector2i< Int > & other) const
inlinenodiscardconstexpr

Determines if perpendicular to another vector.

Parameters
otherOther vector.
Returns
True if parallel, false otherwise.

◆ zero()

template<typename Int>
constexpr Vector2i nnm::Vector2i< Int >::zero ( )
inlinestaticconstexpr

Vector with all components to zero.

Returns
Resulting vector.

Member Data Documentation

◆ x

template<typename Int>
Int nnm::Vector2i< Int >::x

◆ y

template<typename Int>
Int nnm::Vector2i< Int >::y

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