diff --git a/libs/B-luga/include/B-luga/Maths/Maths.hpp b/libs/B-luga/include/B-luga/Maths/Maths.hpp index 2b84af8..40577da 100644 --- a/libs/B-luga/include/B-luga/Maths/Maths.hpp +++ b/libs/B-luga/include/B-luga/Maths/Maths.hpp @@ -21,9 +21,9 @@ class Maths { static constexpr int DECIMALS_TO_CONSERVE = 2; /** - * @brief Calculates a multiplier based on the DECIMALS_TO_CONSERVE constant. - * @return The calculated multiplier. - * @example If DECIMALS_TO_CONSERVE is 2, the function returns 100. + * @brief Calculates a multiplier based on the DECIMALS_TO_CONSERVE constant. + * @return The calculated multiplier. + * @example If DECIMALS_TO_CONSERVE is 2, the function returns 100. */ static constexpr int getMultiplier() { @@ -36,11 +36,11 @@ class Maths { } /** - * @brief convert a float to an int conserving the x first decimals - * @param normalFloat the float to convert - * @return int - * @example 99.99 -> 9999 for DECIMALS_TO_CONSERVE = 2 - * + * @brief convert a float to an int conserving the x first decimals + * @param normalFloat the float to convert + * @return int + * @example 99.99 -> 9999 for DECIMALS_TO_CONSERVE = 2 + * */ static int floatToIntConservingDecimals(const float normalFloat) { @@ -50,11 +50,11 @@ class Maths { } /** - * @brief convert an int to a float with x decimals - * @param decimalInt the int to convert - * @return float - * @example 9999 -> 99.99 for DECIMALS_TO_CONSERVE = 2 - * + * @brief convert an int to a float with x decimals + * @param decimalInt the int to convert + * @return float + * @example 9999 -> 99.99 for DECIMALS_TO_CONSERVE = 2 + * */ static float intToFloatConservingDecimals(const int decimalInt) { @@ -64,11 +64,11 @@ class Maths { } /** - * @brief remove the decimals of an int - * @param decimalInt the int to modify - * @return int - * @example 9999 -> 99 for DECIMALS_TO_CONSERVE = 2 - * + * @brief remove the decimals of an int + * @param decimalInt the int to modify + * @return int + * @example 9999 -> 99 for DECIMALS_TO_CONSERVE = 2 + * */ static int removeIntDecimals(const int decimalInt) { @@ -76,11 +76,11 @@ class Maths { } /** - * @brief add the x decimals to an int - * @param normalInt the int to modify - * @return int with x decimals - * @example 99 -> 9900 for DECIMALS_TO_CONSERVE = 2 - * + * @brief add the x decimals to an int + * @param normalInt the int to modify + * @return int with x decimals + * @example 99 -> 9900 for DECIMALS_TO_CONSERVE = 2 + * */ static int addIntDecimals(const int normalInt) { @@ -88,12 +88,12 @@ class Maths { } /** - * @brief addition of two ints with x decimals - * @param decimalInt decimalInt the first int - * @param otherDecimalInt decimalInt the second int - * @return the result of the addition - * @example 9999 + 9999 -> 199.98 for DECIMALS_TO_CONSERVE = 2 - * + * @brief addition of two ints with x decimals + * @param decimalInt decimalInt the first int + * @param otherDecimalInt decimalInt the second int + * @return the result of the addition + * @example 9999 + 9999 -> 199.98 for DECIMALS_TO_CONSERVE = 2 + * */ static int additionWithTwoIntDecimals(const int decimalInt, const int otherDecimalInt) { @@ -104,12 +104,12 @@ class Maths { } /** - * @brief subtraction of two ints with x decimals - * @param minuend int the substraction minuend - * @param subtrahend int the substraction subtrahend - * @return the result of the subtraction - * @example 9999 - 9999 -> 0 for DECIMALS_TO_CONSERVE = 2 - * + * @brief subtraction of two ints with x decimals + * @param minuend int the substraction minuend + * @param subtrahend int the substraction subtrahend + * @return the result of the subtraction + * @example 9999 - 9999 -> 0 for DECIMALS_TO_CONSERVE = 2 + * */ static int subtractionWithTwoIntDecimals(const int minuend, const int subtrahend) { @@ -120,11 +120,11 @@ class Maths { } /** - * @brief multiplication of two ints with x decimals - * @param decimalInt decimalInt the first int - * @param otherDecimalInt decimalInt the first int - * @return the result of the multiplication - * + * @brief multiplication of two ints with x decimals + * @param decimalInt decimalInt the first int + * @param otherDecimalInt decimalInt the first int + * @return the result of the multiplication + * */ static int multiplicationWithTwoIntDecimals(const int decimalInt, const int otherDecimalInt) { @@ -135,11 +135,11 @@ class Maths { } /** - * @brief division of two int with x decimals - * @param dividend decimalInt the first int - * @param divisor decimalInt the first int - * @return the result of the division - * + * @brief division of two int with x decimals + * @param dividend decimalInt the first int + * @param divisor decimalInt the first int + * @return the result of the division + * */ static int divisionWithTwoIntDecimals(const int dividend, const int divisor) { @@ -154,11 +154,11 @@ class Maths { } /** - * @brief addition with a decimal int and a normal int - * @param decimalInt decimalInt the decimal int that will be modified - * @param normalInt normalInt the normal int that will be added - * @return void - * @example 500 + 5 = 550 for DECIMALS_TO_CONSERVE = 2 + * @brief addition with a decimal int and a normal int + * @param decimalInt decimalInt the decimal int that will be modified + * @param normalInt normalInt the normal int that will be added + * @return void + * @example 500 + 5 = 550 for DECIMALS_TO_CONSERVE = 2 */ static void addNormalIntToDecimalInt(int &decimalInt, const int normalInt) { @@ -166,11 +166,11 @@ class Maths { } /** - * @brief subtraction with a decimal int and a normal int - * @param decimalInt decimalInt the decimal int that will be modified - * @param normalInt the normal int that will be subtracted - * @return void - * @example 550 - 5 = 500 for DECIMALS_TO_CONSERVE = 2 + * @brief subtraction with a decimal int and a normal int + * @param decimalInt decimalInt the decimal int that will be modified + * @param normalInt the normal int that will be subtracted + * @return void + * @example 550 - 5 = 500 for DECIMALS_TO_CONSERVE = 2 */ static void subNormalIntToDecimalInt(int &decimalInt, const int normalInt) { @@ -178,11 +178,11 @@ class Maths { } /** - * @brief add a float to an int with decimals - * @param decimalInt decimalInt the decimal int that will be modified - * @param normalFloat the normal float that will be added - * @return nothing - * @example 500 + 5.5 = 555 for DECIMALS_TO_CONSERVE = 2 + * @brief add a float to an int with decimals + * @param decimalInt decimalInt the decimal int that will be modified + * @param normalFloat the normal float that will be added + * @return nothing + * @example 500 + 5.5 = 555 for DECIMALS_TO_CONSERVE = 2 */ static void addFloatToDecimalInt(int &decimalInt, const float normalFloat) { @@ -190,14 +190,39 @@ class Maths { } /** - * @brief sub a float to an int with decimals - * @param decimalInt decimalInt the decimal int that will be modified - * @param normalFloat the normal float that will be subtracted - * @return nothing - * @example 500 - 5.5 = 445 for DECIMALS_TO_CONSERVE = 2 + * @brief sub a float to an int with decimals + * @param decimalInt decimalInt the decimal int that will be modified + * @param normalFloat the normal float that will be subtracted + * @return nothing + * @example 500 - 5.5 = 445 for DECIMALS_TO_CONSERVE = 2 */ static void subFloatToDecimalInt(int &decimalInt, const float normalFloat) { decimalInt -= floatToIntConservingDecimals(normalFloat); } + + /** + * @brief get the angle from a vector + * @param x the x of the vector + * @param y the y of the vector + * @return float + */ + float getAngleFromVector(const float x, const float y) + { + float angle = atan2(y, x) * 180.0F / static_cast(M_PI); + if (angle < 0) { + angle += 360; + } + return angle; + } + + /** + * @brief convert degrees to radians + * @param degrees the degrees to convert + * @return float + */ + float degreesToRadians(const float degrees) + { + return degrees * static_cast(M_PI) / 180; + } };