MochiEngine
Loading...
Searching...
No Matches
Math utilities

Functions

bool Mochi::Math::Approx (const float &a, const float &b)
 Checks if two floats are the "same" for logic purposes, comparing their difference with a really small number.
float Mochi::Math::Max (const float &a, const float &b)
 Returns the maximum number between two numbers.
float Mochi::Math::Min (const float &a, const float &b)
 Returns the minimum number between two numbers.
float Mochi::Math::Clamp (const float &value, const float &min, const float &max)
 Returns a value between min and max, the closest to value.
float Mochi::Math::Clamp01 (const float &value)
 Does a Clamp having 0 as min and 1 and max.
float Mochi::Math::MoveTowards (const float &a, const float &b, const float &dt, const float &speed)
 Increases or reduces a value to approach a second value, with a defined speed.
float Mochi::Math::Repeat (const float &t, const float &length)
 Similar to doing a module, but with floats.
float Mochi::Math::Lerp (const float &a, const float &b, const float &t)
 Gives a number between a range defined by a proportion t.
float Mochi::Math::InverseLerp (const float &a, const float &b, const float &val)
 Gives the proportional position of a value in a range.

Detailed Description

List of useful math methods useful in many contexts.

Utils/MathUtils.h

Function Documentation

◆ Approx()

bool Mochi::Math::Approx ( const float & a,
const float & b )
inline

Checks if two floats are the "same" for logic purposes, comparing their difference with a really small number.

Parameters
aFirst number
bSecond number
Returns
True if they are the same or almost the same.

◆ Clamp()

float Mochi::Math::Clamp ( const float & value,
const float & min,
const float & max )
inline

Returns a value between min and max, the closest to value.

Parameters
valueThe reference value.
minThe minimum result.
maxThe maximum result.
Returns
Min if value was smaller than min, max if it was bigger than max, an value otherwise.

◆ Clamp01()

float Mochi::Math::Clamp01 ( const float & value)
inline

Does a Clamp having 0 as min and 1 and max.

Parameters
valueThe reference value.
Returns
0 if value was smaller than 0, 1 if the value was bigger than 1, the value otherwise.

◆ InverseLerp()

float Mochi::Math::InverseLerp ( const float & a,
const float & b,
const float & val )
inline

Gives the proportional position of a value in a range.

Parameters
aStart of the range.
bEnd of the range.
valValue in the range.
Returns
The proportional position of the value between 0 and 1. It can be less than 0 or greater than 1 if val was outside the range.

◆ Lerp()

float Mochi::Math::Lerp ( const float & a,
const float & b,
const float & t )
inline

Gives a number between a range defined by a proportion t.

Parameters
aStart of the range.
bEnd of the range.
tThe proportion, between 0 and 1
Returns
The proportional value in the range. It can be outside the range of if t is less than 0 or greater than 1.

◆ Max()

float Mochi::Math::Max ( const float & a,
const float & b )
inline

Returns the maximum number between two numbers.

Parameters
aFirst number.
bSecond number.
Returns
The biggest of the two numbers.

◆ Min()

float Mochi::Math::Min ( const float & a,
const float & b )
inline

Returns the minimum number between two numbers.

Parameters
aFirst number.
bSecond number.
Returns
The smallest of the two numbers.

◆ MoveTowards()

float Mochi::Math::MoveTowards ( const float & a,
const float & b,
const float & dt,
const float & speed )
inline

Increases or reduces a value to approach a second value, with a defined speed.

Parameters
aThe base value
bThe target value
dtHow much time passes moving a to b for the calculations of this operation.
speedThe speed at which a moves.
Returns
b if the operation equals of exceeds b value, or the result of a moved.

◆ Repeat()

float Mochi::Math::Repeat ( const float & t,
const float & length )
inline

Similar to doing a module, but with floats.

Parameters
tThe value to check.
lengthThe module.
Returns
The final value.