[FEAT] add dot and cross

This commit is contained in:
NADAL Jean-Baptiste
2024-01-30 15:55:42 +01:00
parent 65e26baf5f
commit 3d3b8b7f02
3 changed files with 73 additions and 4 deletions

View File

@@ -64,6 +64,18 @@ TEST_CASE("a tuple with w=0 is a vector", "[Tuple]")
/* ------------------------------------------------------------------------- */
TEST_CASE("Tuple could be copy", "[Tuple]")
{
Tuple p = Tuple::Point(4, -4, 3);
Tuple n;
n = p;
REQUIRE(n == p);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("Point() creates tuples with w=1", "[Tuple][Point]")
{
Tuple p = Tuple::Point(4, -4, 3);
@@ -231,3 +243,24 @@ TEST_CASE("The magnitude of a normalized vector", "[Tuple][Normalize]")
REQUIRE(norm.magnitude() == 1);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("The dot product of two tuples", "[Tuple][Dot]")
{
Tuple a = Tuple::Vector(1, 2, 3);
Tuple b = Tuple::Vector(2, 3, 4);
REQUIRE(a.dot(b) == 20);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("The cross product of two vector", "[Tuple][Cross]")
{
Tuple a = Tuple::Vector(1, 2, 3);
Tuple b = Tuple::Vector(2, 3, 4);
REQUIRE(a.cross(b) == Tuple::Vector(-1, 2, -1));
REQUIRE(b.cross(a) == Tuple::Vector(1, -2, 1));
}