commit 756194f6daa20b7338b7c5610327ab200b17a175
parent d1775b107b5d3f7ed2e1eb901f51de042cdfb92a
Author: Andrew Laack <andrew@laack.co>
Date: Tue, 15 Sep 2026 20:48:14 -0500
Small tweaks, added an assertion to verify square doesn't overflow
Diffstat:
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/background/src/main.cpp b/background/src/main.cpp
@@ -46,7 +46,7 @@ int main() {
ClearBackground(BLACK);
g.render();
EndDrawing();
- sleep(5);
+ sleep(1);
oneStepPrim(toVisit, visitedIndices, g);
}
diff --git a/background/src/utils.cpp b/background/src/utils.cpp
@@ -1,5 +1,6 @@
#include "../headers/utils.hpp"
#include <cstdint>
+#include <cassert>
#include <cstdlib>
float square(float x) {
@@ -17,5 +18,7 @@ Vector2 randomPosition(uint32_t xMax, uint32_t yMax) {
float distanceSquared(Vector2 v1, Vector2 v2) {
float xSquare = square(v1.x - v2.x);
float ySquare = square(v1.y - v2.y);
- return xSquare + ySquare;
+ float result = xSquare + ySquare;
+ assert(result >= 0);
+ return result;
}
diff --git a/background/tests/algo_test.cpp b/background/tests/algo_test.cpp
@@ -164,4 +164,3 @@ TEST_CASE( "Staircase Prim algorithm", "[Staircase prim algo]" ) {
}
}
-