diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl index c83aee440..8855eae38 100644 --- a/include/Nazara/Math/OrientedBox.inl +++ b/include/Nazara/Math/OrientedBox.inl @@ -103,9 +103,9 @@ template NzOrientedBox& NzOrientedBox::Set(const NzOrientedBox& orientedBox) { for (unsigned int i = 0; i <= nzBoxCorner_Max; ++i) - m_corners[i].Set(orientedBox.m_corners[i]); + m_corners[i].Set(orientedBox(i)); - localBox = orientedBox.localBox; + localBox.Set(orientedBox.localBox); return *this; } @@ -151,7 +151,7 @@ NzVector3& NzOrientedBox::operator()(unsigned int i) if (i > nzBoxCorner_Max) { NzStringStream ss; - ss << "Index out of range: (" << i << " >= 3)"; + ss << "Index out of range: (" << i << " >= " << nzBoxCorner_Max << ")"; NazaraError(ss); throw std::out_of_range(ss.ToString()); @@ -168,7 +168,7 @@ NzVector3 NzOrientedBox::operator()(unsigned int i) const if (i > nzBoxCorner_Max) { NzStringStream ss; - ss << "Index out of range: (" << i << " >= 3)"; + ss << "Index out of range: (" << i << " >= " << nzBoxCorner_Max << ")"; NazaraError(ss); throw std::out_of_range(ss.ToString()); diff --git a/tests/Nazara/Math/OrientedBox.cpp b/tests/Nazara/Math/OrientedBox.cpp new file mode 100644 index 000000000..c5b650c7d --- /dev/null +++ b/tests/Nazara/Math/OrientedBox.cpp @@ -0,0 +1,46 @@ +#include +#include + +SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]") +{ + GIVEN("Two center and unit oriented boxes") + { + NzOrientedBoxf firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f); + NzOrientedBoxf secondCenterAndUnit(NzOrientedBox(NzVector3i::Zero(), NzVector3i::Unit())); + + firstCenterAndUnit.Update(NzMatrix4f::Identity()); + + WHEN("We compare them") + { + THEN("They are the same") + { + REQUIRE(firstCenterAndUnit == secondCenterAndUnit); + } + } + + WHEN("We ask if they are valid") + { + THEN("They are valid") + { + CHECK(firstCenterAndUnit.IsValid()); + CHECK(secondCenterAndUnit.IsValid()); + } + } + + WHEN("We multiply them") + { + THEN("Results are different between operator * and update(ScaleMatrix) but corners are the same") + { + firstCenterAndUnit *= 2.f; + firstCenterAndUnit.Update(NzMatrix4f::Identity()); + secondCenterAndUnit.Update(NzMatrix4f::Scale(NzVector3f::Unit() * 2.f)); + + REQUIRE(firstCenterAndUnit != secondCenterAndUnit); + for (unsigned int i = 0; i <= nzBoxCorner_Max; ++i) + { + REQUIRE(firstCenterAndUnit(i) == secondCenterAndUnit(i)); + } + } + } + } +}