diff --git a/libs/geom/tests/point.cpp b/libs/geom/tests/point.cpp index 48fb3770..9b0952c7 100644 --- a/libs/geom/tests/point.cpp +++ b/libs/geom/tests/point.cpp @@ -105,3 +105,13 @@ test_case(geom_point_distance) expect_equal(distance_sqr(p1, p2), 169.f); expect_close(distance(p1, p2), 13.f, 1e-6); } + +test_case(geom_point_lerp) +{ + point p1{1.f, 2.f, 3.f}; + point p2{5.f, 6.f, 7.f}; + + expect_equal((lerp(p1, p2, 0.25f)), (point{2.f, 3.f, 4.f})); + expect_equal((lerp(p1, p2, 0.5f )), (point{3.f, 4.f, 5.f})); + expect_equal((lerp(p1, p2, 0.75f)), (point{4.f, 5.f, 6.f})); +} diff --git a/libs/geom/tests/vector.cpp b/libs/geom/tests/vector.cpp index 97340e3d..4f194274 100644 --- a/libs/geom/tests/vector.cpp +++ b/libs/geom/tests/vector.cpp @@ -1,6 +1,7 @@ #include #include +#include using namespace psemek::geom; @@ -147,3 +148,28 @@ test_case(geom_vector_length) expect_equal(length_sqr(v), 169.f); expect_close(length(v), 13.f, 1e-6); } + +test_case(geom_vector_lerp) +{ + vector v1{1.f, 2.f, 3.f}; + vector v2{5.f, 6.f, 7.f}; + + expect_equal((lerp(v1, v2, 0.25f)), (vector{2.f, 3.f, 4.f})); + expect_equal((lerp(v1, v2, 0.5f )), (vector{3.f, 4.f, 5.f})); + expect_equal((lerp(v1, v2, 0.75f)), (vector{4.f, 5.f, 6.f})); +} + +test_case(geom_vector_slerp) +{ + vector v1{1.f, 0.f}; + vector v2{0.f, 1.f}; + + for (int i = 0; i <= 9; ++i) + { + // 10-degree steps + auto s = slerp(v1, v2, i / 9.f); + expect_close((length(s)), 1.f, 1e-6); + expect_gequal((det(v1, s)), 0.f); + expect_gequal((det(s, v2)), 0.f); + } +}