|
| 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.
|
List of useful math methods useful in many contexts.
Utils/MathUtils.h
◆ 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
-
| a | First number |
| b | Second 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
-
| value | The reference value. |
| min | The minimum result. |
| max | The 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
-
| value | The 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
-
| a | Start of the range. |
| b | End of the range. |
| val | Value 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
-
| a | Start of the range. |
| b | End of the range. |
| t | The 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
-
| a | First number. |
| b | Second 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
-
| a | First number. |
| b | Second 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
-
| a | The base value |
| b | The target value |
| dt | How much time passes moving a to b for the calculations of this operation. |
| speed | The 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
-
| t | The value to check. |
| length | The module. |
- Returns
- The final value.