From 6f227026b9aefebf017ad9bfa525dd6af7c2614e Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Thu, 23 Jan 2025 12:14:56 +0100 Subject: [PATCH] remove Math --- inc/Math.hpp | 5 --- src/App.cpp | 39 +++++++++++++++++++++++- src/Math.cpp | 64 --------------------------------------- src/canvas/BackGround.cpp | 20 +++++++++++- src/canvas/Circle.cpp | 2 -- src/canvas/Tree.cpp | 1 - 6 files changed, 57 insertions(+), 74 deletions(-) delete mode 100644 inc/Math.hpp delete mode 100644 src/Math.cpp diff --git a/inc/Math.hpp b/inc/Math.hpp deleted file mode 100644 index bc5533f..0000000 --- a/inc/Math.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -Color ColorAdd(Color c1, Color c2); -Color ColorAddValue(Color c, int add); -Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom); \ No newline at end of file diff --git a/src/App.cpp b/src/App.cpp index b461495..ccbbca9 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -2,7 +2,6 @@ #include #include "App.hpp" -#include "Math.hpp" #include #include @@ -10,6 +9,44 @@ #define TOP (1 - pos) #define BOTTOM pos +Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom) +{ + float br = box.width / box.height; + float tr = textW / textH; + + Rectangle ret = {0, 0, 0, 0}; + + float hm = box.height * margin; + float wm = box.width * margin; + + ret.height = box.height - hm; + ret.width = box.width - wm; + + if (br < tr) + { + // bolj kvadrat izracunaj visino iz sirine + ret.height = ret.width / tr; + } + else + { + // bolj podolgovat izracunaj sirino iz visine + ret.width = ret.height * tr; + } + + if (topOrBottom) + { + ret.y = box.y + hm; + } + else + { + ret.y = box.y + box.height - hm - ret.height; + } + + ret.x = box.x + wm; + + return ret; +} + // Dimentions for font size 20 // DISLIKE 83 // LIKE 46 diff --git a/src/Math.cpp b/src/Math.cpp deleted file mode 100644 index 525318f..0000000 --- a/src/Math.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include - -#include "Math.hpp" -#include "values/mrand.hpp" - -#include - -Color ColorAddValue(Color c, int add) -{ - int r = std::clamp(c.r + add, 0, 255); - int g = std::clamp(c.g + add, 0, 255); - int b = std::clamp(c.b + add, 0, 255); - - return {(unsigned char)r, (unsigned char)g, (unsigned char)b, c.a}; -} - -Color ColorAdd(Color c1, Color c2) -{ - int r = std::clamp(c1.r + c2.r, 0, 255); - int g = std::clamp(c1.g + c2.g, 0, 255); - int b = std::clamp(c1.b + c2.b, 0, 255); - int a = std::clamp(c1.a + c2.a, 0, 255); - - return {(unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a}; -} - -Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom) -{ - float br = box.width / box.height; - float tr = textW / textH; - - Rectangle ret = {0, 0, 0, 0}; - - float hm = box.height * margin; - float wm = box.width * margin; - - ret.height = box.height - hm; - ret.width = box.width - wm; - - if (br < tr) - { - // bolj kvadrat izracunaj visino iz sirine - ret.height = ret.width / tr; - } - else - { - // bolj podolgovat izracunaj sirino iz visine - ret.width = ret.height * tr; - } - - if (topOrBottom) - { - ret.y = box.y + hm; - } - else - { - ret.y = box.y + box.height - hm - ret.height; - } - - ret.x = box.x + wm; - - return ret; -} \ No newline at end of file diff --git a/src/canvas/BackGround.cpp b/src/canvas/BackGround.cpp index a04315d..80d9c46 100644 --- a/src/canvas/BackGround.cpp +++ b/src/canvas/BackGround.cpp @@ -3,7 +3,6 @@ #include "canvas/BackGround.hpp" #include "canvas/BackGroundColors.hpp" #include "canvas/Circle.hpp" -#include "Math.hpp" #include "stb_perlin.h" #include @@ -28,6 +27,25 @@ constexpr static float mounten2max = 0.90; constexpr static float mounten3min = 0.90f; constexpr static float mounten3max = 0.95f; +Color ColorAddValue(Color c, int add) +{ + int r = std::clamp(c.r + add, 0, 255); + int g = std::clamp(c.g + add, 0, 255); + int b = std::clamp(c.b + add, 0, 255); + + return {(unsigned char)r, (unsigned char)g, (unsigned char)b, c.a}; +} + +Color ColorAdd(Color c1, Color c2) +{ + int r = std::clamp(c1.r + c2.r, 0, 255); + int g = std::clamp(c1.g + c2.g, 0, 255); + int b = std::clamp(c1.b + c2.b, 0, 255); + int a = std::clamp(c1.a + c2.a, 0, 255); + + return {(unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a}; +} + // Public void BackGround::init(int canvasSize) { diff --git a/src/canvas/Circle.cpp b/src/canvas/Circle.cpp index 9e42c48..2ac1967 100644 --- a/src/canvas/Circle.cpp +++ b/src/canvas/Circle.cpp @@ -1,8 +1,6 @@ #include "canvas/Circle.hpp" #include "sunShader.hpp" -#include "Math.hpp" - #include #include diff --git a/src/canvas/Tree.cpp b/src/canvas/Tree.cpp index 0880c39..e71057c 100644 --- a/src/canvas/Tree.cpp +++ b/src/canvas/Tree.cpp @@ -2,7 +2,6 @@ #include "canvas/Tree.hpp" #include "canvas/Circle.hpp" -#include "Math.hpp" #include #include