Smartcar Shield
Functions
smartcarlib::utils Namespace Reference

Functions

template<typename AnyNumber >
constexpr AnyNumber getAbsolute (AnyNumber number)
 Gets the absolute of the supplied number. More...
 
template<typename AnyNumber >
constexpr AnyNumber getConstrain (AnyNumber number, AnyNumber min, AnyNumber max)
 Limit the number between a range. More...
 
template<typename AnyNumber >
AnyNumber getMedian (AnyNumber unsortedNumbers[], const unsigned int &arraySize)
 Gets the median value out of the supplied number array. More...
 
template<typename AnyNumber >
constexpr AnyNumber getMap (AnyNumber valueToMap, AnyNumber fromLow, AnyNumber fromHigh, AnyNumber toLow, AnyNumber toHigh)
 Maps a value from a range to another. More...
 
constexpr bool areAlmostEqual (float a, float b)
 Compares two floating point numbers. More...
 

Function Documentation

◆ areAlmostEqual()

constexpr bool smartcarlib::utils::areAlmostEqual ( float  a,
float  b 
)
constexpr

Compares two floating point numbers.

Parameters
aThe first floating point number to compare
bThe second floating point number to compare
Returns
true if the two numbers are amost equal, false otherwise

Example:

bool result = smartcarlib::utils::areAlmostEqual(0.000001, 0,0000012);
// `result` is `true`

Definition at line 124 of file Utilities.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAbsolute()

template<typename AnyNumber >
constexpr AnyNumber smartcarlib::utils::getAbsolute ( AnyNumber  number)
constexpr

Gets the absolute of the supplied number.

Parameters
numberThe number to get the absolute of
Returns
The absolute value

Example:

int num = -5;
// `num` is now `5`

Definition at line 24 of file Utilities.hpp.

Here is the caller graph for this function:

◆ getConstrain()

template<typename AnyNumber >
constexpr AnyNumber smartcarlib::utils::getConstrain ( AnyNumber  number,
AnyNumber  min,
AnyNumber  max 
)
constexpr

Limit the number between a range.

Parameters
numberThe number to limit
minThe minimum limit of the range
maxThe maximum limit of the range
Returns
The number unchanged if it was within the range, otherwise the lower limit of the range if it was smaller or the higher limit if it was larger

Example:

int num = -5;
// `num` is now `0`

Definition at line 46 of file Utilities.hpp.

Here is the caller graph for this function:

◆ getMap()

template<typename AnyNumber >
constexpr AnyNumber smartcarlib::utils::getMap ( AnyNumber  valueToMap,
AnyNumber  fromLow,
AnyNumber  fromHigh,
AnyNumber  toLow,
AnyNumber  toHigh 
)
constexpr

Maps a value from a range to another.

Implemented as a templetized map of Arduino.

Parameters
valueToMapThe value to be mapped
fromLowThe lower limit of the initial range
fromHighThe upper limit of the initial range
toLowThe lower limit of the final range
toHighThe higher limit of the final range
Returns
The mapped value if initial range valid otherwise the lower limit of the target range

Example:

int num = 3;
// Scale a `num` from 0-10 to 0-100
num = smartcarlib::utils::getMap(num, 0, 10, 0, 100);
// `num` is now `30`

Definition at line 104 of file Utilities.hpp.

Here is the caller graph for this function:

◆ getMedian()

template<typename AnyNumber >
AnyNumber smartcarlib::utils::getMedian ( AnyNumber  unsortedNumbers[],
const unsigned int &  arraySize 
)

Gets the median value out of the supplied number array.

Parameters
unsortedNumbersAn array containing numbers
arraySizeAmount of numbers contained in the array
Returns
Median number of the supplied array

Example:

const int ARRAY_SIZE = 5;
int array[ARRAY_SIZE] = {0, 3, 4, 1, 15};
int median = smartcarlib::utils::getMedian(array, ARRAY_SIZE);
// `median` is `3`

Definition at line 66 of file Utilities.hpp.

Here is the caller graph for this function:
smartcarlib::utils::getMedian
AnyNumber getMedian(AnyNumber unsortedNumbers[], const unsigned int &arraySize)
Gets the median value out of the supplied number array.
Definition: Utilities.hpp:66
smartcarlib::utils::getMap
constexpr AnyNumber getMap(AnyNumber valueToMap, AnyNumber fromLow, AnyNumber fromHigh, AnyNumber toLow, AnyNumber toHigh)
Maps a value from a range to another.
Definition: Utilities.hpp:104
smartcarlib::utils::getAbsolute
constexpr AnyNumber getAbsolute(AnyNumber number)
Gets the absolute of the supplied number.
Definition: Utilities.hpp:24
smartcarlib::utils::areAlmostEqual
constexpr bool areAlmostEqual(float a, float b)
Compares two floating point numbers.
Definition: Utilities.hpp:124
smartcarlib::utils::getConstrain
constexpr AnyNumber getConstrain(AnyNumber number, AnyNumber min, AnyNumber max)
Limit the number between a range.
Definition: Utilities.hpp:46