README: moved image

This commit is contained in:
Jan Mrna
2025-11-03 05:05:52 +01:00
parent 25a246f3ff
commit 55350a9a3b
2 changed files with 217 additions and 235 deletions

View File

@@ -1,7 +1,5 @@
# Pathfinding demo # Pathfinding demo
![C++ pathfinding demo](./docs/img/screenshot_1.png)
This is a demo of pathfinding on a 2D grid. It consists of 2 main parts: This is a demo of pathfinding on a 2D grid. It consists of 2 main parts:
* python notes and implementation * python notes and implementation
@@ -23,6 +21,8 @@ Contains the same demo as the standalone script and some notes. Since Github sup
## C++ ## C++
![C++ pathfinding demo](./docs/img/screenshot_1.png)
### Windows ### Windows
#### Dependencies #### Dependencies

View File

@@ -9,7 +9,6 @@
#include "math.hpp" #include "math.hpp"
#include "positional_container.hpp" #include "positional_container.hpp"
TEST(vec, DefaultConstruction) { TEST(vec, DefaultConstruction) {
// Test that default-constucted vector // Test that default-constucted vector
// has all elements equal to zero // has all elements equal to zero
@@ -58,12 +57,8 @@ TEST(vec, ArrayConstruction) {
ASSERT_FLOAT_EQ(arr3[2], 3.5f); ASSERT_FLOAT_EQ(arr3[2], 3.5f);
} }
TEST(vec, equalEpsilon) { TEST(vec, equalEpsilon) {
// Test equalEpsilon // Test equalEpsilon
// TODO just an ad-hoc test,
// can possibly fail for other machines.
// This needs some work
vec3 v1{1.0f, 2.0f, 3.0f}; vec3 v1{1.0f, 2.0f, 3.0f};
vec3 v2{0.999999f, 1.9999999f, 2.9999999f}; vec3 v2{0.999999f, 1.9999999f, 2.9999999f};
ASSERT_EQ(v1, v2); ASSERT_EQ(v1, v2);
@@ -112,8 +107,7 @@ TEST(vec, LogPrint) {
LOG_DEBUG("uvec4 ", uv4); LOG_DEBUG("uvec4 ", uv4);
} }
TEST(vec, Add) TEST(vec, Add) {
{
// Test operator+ with float vectors // Test operator+ with float vectors
vec3 v1{1.0f, 2.0f, 3.0f}; vec3 v1{1.0f, 2.0f, 3.0f};
vec3 v2{4.0f, 5.0f, 6.0f}; vec3 v2{4.0f, 5.0f, 6.0f};
@@ -138,8 +132,7 @@ TEST(vec, Add)
ASSERT_FLOAT_EQ(v1[2], 3.0f); ASSERT_FLOAT_EQ(v1[2], 3.0f);
} }
TEST(vec, Sub) TEST(vec, Sub) {
{
// Test operator- with float vectors // Test operator- with float vectors
vec3 v1{5.0f, 7.0f, 9.0f}; vec3 v1{5.0f, 7.0f, 9.0f};
vec3 v2{1.0f, 2.0f, 3.0f}; vec3 v2{1.0f, 2.0f, 3.0f};
@@ -173,8 +166,7 @@ TEST(vec, Sub)
ASSERT_FLOAT_EQ(negative_result[2], -3.0f); ASSERT_FLOAT_EQ(negative_result[2], -3.0f);
} }
TEST(vec, ScalarAddition) TEST(vec, ScalarAddition) {
{
// Test operator+ with float vector and scalar // Test operator+ with float vector and scalar
vec3 v1{1.0f, 2.0f, 3.0f}; vec3 v1{1.0f, 2.0f, 3.0f};
vec3 result = v1 + 5.0f; vec3 result = v1 + 5.0f;
@@ -213,8 +205,7 @@ TEST(vec, ScalarAddition)
ASSERT_FLOAT_EQ(zero_result[2], 3.0f); ASSERT_FLOAT_EQ(zero_result[2], 3.0f);
} }
TEST(vec, ScalarSubtraction) TEST(vec, ScalarSubtraction) {
{
// Test operator- with float vector and scalar // Test operator- with float vector and scalar
vec3 v1{10.0f, 15.0f, 20.0f}; vec3 v1{10.0f, 15.0f, 20.0f};
vec3 result = v1 - 5.0f; vec3 result = v1 - 5.0f;
@@ -253,8 +244,7 @@ TEST(vec, ScalarSubtraction)
ASSERT_FLOAT_EQ(negative_vals_result[2], -2.0f); ASSERT_FLOAT_EQ(negative_vals_result[2], -2.0f);
} }
TEST(vec, ScalarMultiplication) TEST(vec, ScalarMultiplication) {
{
// Test scalar * vector with float vectors // Test scalar * vector with float vectors
vec3 v1{2.0f, 3.0f, 4.0f}; vec3 v1{2.0f, 3.0f, 4.0f};
vec3 result = v1 * 2.5f; vec3 result = v1 * 2.5f;
@@ -293,8 +283,7 @@ TEST(vec, ScalarMultiplication)
ASSERT_FLOAT_EQ(negative_result[2], -6.0f); ASSERT_FLOAT_EQ(negative_result[2], -6.0f);
} }
TEST(vec, ScalarDivision) TEST(vec, ScalarDivision) {
{
// Test vector / scalar with float vectors // Test vector / scalar with float vectors
vec3 v1{10.0f, 15.0f, 20.0f}; vec3 v1{10.0f, 15.0f, 20.0f};
vec3 result = v1 / 2.5f; vec3 result = v1 / 2.5f;
@@ -333,8 +322,7 @@ TEST(vec, ScalarDivision)
ASSERT_FLOAT_EQ(fractional_result[2], 6.0f); ASSERT_FLOAT_EQ(fractional_result[2], 6.0f);
} }
TEST(vec, AdditionAssignment) TEST(vec, AdditionAssignment) {
{
// Test operator+= with float vectors // Test operator+= with float vectors
vec3 v1{1.0f, 2.0f, 3.0f}; vec3 v1{1.0f, 2.0f, 3.0f};
vec3 v2{4.0f, 5.0f, 6.0f}; vec3 v2{4.0f, 5.0f, 6.0f};
@@ -372,8 +360,7 @@ TEST(vec, AdditionAssignment)
ASSERT_FLOAT_EQ(v4[2], 5.0f); ASSERT_FLOAT_EQ(v4[2], 5.0f);
} }
TEST(vec, SubtractionAssignment) TEST(vec, SubtractionAssignment) {
{
// Test operator-= with float vectors // Test operator-= with float vectors
vec3 v1{10.0f, 15.0f, 20.0f}; vec3 v1{10.0f, 15.0f, 20.0f};
vec3 v2{3.0f, 5.0f, 7.0f}; vec3 v2{3.0f, 5.0f, 7.0f};
@@ -407,8 +394,7 @@ TEST(vec, SubtractionAssignment)
ASSERT_FLOAT_EQ(v3[2], -3.0f); ASSERT_FLOAT_EQ(v3[2], -3.0f);
} }
TEST(vec, LengthSquared) TEST(vec, LengthSquared) {
{
// Test LengthSquared with float vectors // Test LengthSquared with float vectors
vec3 v1{3.0f, 4.0f, 0.0f}; vec3 v1{3.0f, 4.0f, 0.0f};
ASSERT_FLOAT_EQ(v1.LengthSquared(), 25.0f); // 3² + 4² + 0² = 25 ASSERT_FLOAT_EQ(v1.LengthSquared(), 25.0f); // 3² + 4² + 0² = 25
@@ -421,8 +407,7 @@ TEST(vec, LengthSquared)
ASSERT_FLOAT_EQ(zero.LengthSquared(), 0.0f); ASSERT_FLOAT_EQ(zero.LengthSquared(), 0.0f);
} }
TEST(vec, Length) TEST(vec, Length) {
{
// Test Length with float vectors // Test Length with float vectors
vec3 v1{3.0f, 4.0f, 0.0f}; vec3 v1{3.0f, 4.0f, 0.0f};
ASSERT_FLOAT_EQ(v1.Length(), 5.0f); // sqrt(3² + 4² + 0²) = 5 ASSERT_FLOAT_EQ(v1.Length(), 5.0f); // sqrt(3² + 4² + 0²) = 5
@@ -435,8 +420,7 @@ TEST(vec, Length)
ASSERT_FLOAT_EQ(zero.Length(), 0.0f); ASSERT_FLOAT_EQ(zero.Length(), 0.0f);
} }
TEST(vec, Normalize) TEST(vec, Normalize) {
{
// Test Normalize with float vectors // Test Normalize with float vectors
vec3 v1{3.0f, 4.0f, 0.0f}; vec3 v1{3.0f, 4.0f, 0.0f};
v1.Normalize(); v1.Normalize();
@@ -455,8 +439,7 @@ TEST(vec, Normalize)
ASSERT_TRUE(zero[2] == 0.0f); ASSERT_TRUE(zero[2] == 0.0f);
} }
TEST(vec, GetNormalized) TEST(vec, GetNormalized) {
{
// Test GetNormalized with float vectors // Test GetNormalized with float vectors
const vec3 v1{3.0f, 4.0f, 0.0f}; const vec3 v1{3.0f, 4.0f, 0.0f};
vec3 normalized = v1.GetNormalized(); vec3 normalized = v1.GetNormalized();
@@ -486,16 +469,14 @@ TEST(vec, GetNormalized)
ASSERT_FLOAT_EQ(zero[2], 0.0f); ASSERT_FLOAT_EQ(zero[2], 0.0f);
} }
TEST(vec, GetOrthogonal) TEST(vec, GetOrthogonal) {
{
const vec2 v1{5.0f, 1.0f}; const vec2 v1{5.0f, 1.0f};
auto v2 = v1.GetOrthogonal(); auto v2 = v1.GetOrthogonal();
ASSERT_FLOAT_EQ(v2[0], -1.0f); ASSERT_FLOAT_EQ(v2[0], -1.0f);
ASSERT_FLOAT_EQ(v2[1], 5.0f); ASSERT_FLOAT_EQ(v2[1], 5.0f);
} }
TEST(vec, DistanceTo) TEST(vec, DistanceTo) {
{
// Test DistanceTo with 3D vectors // Test DistanceTo with 3D vectors
vec3 v1{0.0f, 0.0f, 0.0f}; vec3 v1{0.0f, 0.0f, 0.0f};
vec3 v2{3.0f, 4.0f, 0.0f}; vec3 v2{3.0f, 4.0f, 0.0f};
@@ -922,7 +903,8 @@ TEST(SimpleContainer, WeakPtrValidAfterGet) {
TEST(SimpleContainer, UpdateAll) { TEST(SimpleContainer, UpdateAll) {
// Test that UpdateAll properly updates item positions // Test that UpdateAll properly updates item positions
// For SimpleContainer, Update is a no-op but Get should still find moved items // For SimpleContainer, Update is a no-op but Get should still find moved
// items
SimpleContainer<TestEntity> container; SimpleContainer<TestEntity> container;
auto item1 = std::make_shared<TestEntity>(10.0f, 10.0f); auto item1 = std::make_shared<TestEntity>(10.0f, 10.0f);