Test box
No problem except indentation Former-commit-id: 58d711b48164363fd672c51c005e16eb5ce55e9e
This commit is contained in:
parent
f0660d5da8
commit
b4f926d3ca
|
|
@ -399,9 +399,9 @@ NzBox<T>& NzBox<T>::Transform(const NzMatrix4<T>& matrix, bool applyTranslation)
|
||||||
NzVector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation
|
NzVector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation
|
||||||
NzVector3<T> halfSize = GetLengths()/F(2.0);
|
NzVector3<T> halfSize = GetLengths()/F(2.0);
|
||||||
|
|
||||||
halfSize.Set(std::fabs(matrix(0,0))*halfSize.x + std::fabs(matrix(1,0))*halfSize.y + std::fabs(matrix(2,0))*halfSize.z,
|
halfSize.Set(std::abs(matrix(0,0))*halfSize.x + std::abs(matrix(1,0))*halfSize.y + std::abs(matrix(2,0))*halfSize.z,
|
||||||
std::fabs(matrix(0,1))*halfSize.x + std::fabs(matrix(1,1))*halfSize.y + std::fabs(matrix(2,1))*halfSize.z,
|
std::abs(matrix(0,1))*halfSize.x + std::abs(matrix(1,1))*halfSize.y + std::abs(matrix(2,1))*halfSize.z,
|
||||||
std::fabs(matrix(0,2))*halfSize.x + std::fabs(matrix(1,2))*halfSize.y + std::fabs(matrix(2,2))*halfSize.z);
|
std::abs(matrix(0,2))*halfSize.x + std::abs(matrix(1,2))*halfSize.y + std::abs(matrix(2,2))*halfSize.z);
|
||||||
|
|
||||||
return Set(center - halfSize, center + halfSize);
|
return Set(center - halfSize, center + halfSize);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
#include <Nazara/Math/Box.hpp>
|
||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
SCENARIO("Box", "[MATH][BOX]")
|
||||||
|
{
|
||||||
|
GIVEN("Two zero boxes")
|
||||||
|
{
|
||||||
|
NzBoxf firstZero(NzBoxf::Zero());
|
||||||
|
NzBoxf secondZero(NzVector3f::Zero(), NzVector3f::Zero());
|
||||||
|
|
||||||
|
WHEN("We multiply them")
|
||||||
|
{
|
||||||
|
firstZero = firstZero * 1.f;
|
||||||
|
secondZero = secondZero * NzVector3f::Unit() * 3.f;
|
||||||
|
|
||||||
|
THEN("They should stay the same")
|
||||||
|
{
|
||||||
|
REQUIRE(firstZero == secondZero);
|
||||||
|
CHECK(!firstZero.IsValid());
|
||||||
|
CHECK(!secondZero.IsValid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GIVEN("Two unit and center boxes")
|
||||||
|
{
|
||||||
|
NzBoxf firstCenterAndUnit(NzRectf(NzVector2f::Zero(), NzVector2f::Unit()));
|
||||||
|
NzBoxf secondCenterAndUnit(1.f, 1.f, 1.f);
|
||||||
|
|
||||||
|
WHEN("We ask for some informations")
|
||||||
|
{
|
||||||
|
THEN("These results are expected")
|
||||||
|
{
|
||||||
|
REQUIRE(firstCenterAndUnit.GetBoundingSphere() == NzSpheref(NzVector3f::Unit() * 0.5f, std::sqrt(3.f * 0.5f * 0.5f)));
|
||||||
|
REQUIRE(firstCenterAndUnit.GetCenter() == (NzVector3f::Unit() * 0.5f));
|
||||||
|
REQUIRE(firstCenterAndUnit.GetCorner(nzBoxCorner_FarLeftTop) == NzVector3f::UnitY());
|
||||||
|
REQUIRE(firstCenterAndUnit.GetLengths() == NzVector3f::Unit());
|
||||||
|
REQUIRE(firstCenterAndUnit.GetMaximum() == NzVector3f::Unit());
|
||||||
|
REQUIRE(firstCenterAndUnit.GetMinimum() == NzVector3f::Zero());
|
||||||
|
REQUIRE(firstCenterAndUnit.GetNegativeVertex(NzVector3f::Unit()) == NzVector3f::Zero());
|
||||||
|
REQUIRE(firstCenterAndUnit.GetPosition() == NzVector3f::Zero());
|
||||||
|
REQUIRE(firstCenterAndUnit.GetPositiveVertex(NzVector3f::Unit()) == NzVector3f::Unit());
|
||||||
|
REQUIRE(firstCenterAndUnit.GetRadius() == Approx(std::sqrt(3.f * 0.5f * 0.5f)));
|
||||||
|
REQUIRE(firstCenterAndUnit.GetSquaredBoundingSphere() == NzSpheref(NzVector3f::Unit() * 0.5f, 3.f * 0.5f * 0.5f));
|
||||||
|
REQUIRE(firstCenterAndUnit.GetSquaredRadius() == Approx(3.f * 0.5f * 0.5f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WHEN("We ask for the intersection between the two")
|
||||||
|
{
|
||||||
|
THEN("We should have a center and unit")
|
||||||
|
{
|
||||||
|
NzBoxf thirdCenterAndUnit;
|
||||||
|
CHECK(firstCenterAndUnit.Intersect(secondCenterAndUnit, &thirdCenterAndUnit));
|
||||||
|
REQUIRE(firstCenterAndUnit == secondCenterAndUnit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WHEN("We use the constructor of conversion")
|
||||||
|
{
|
||||||
|
THEN("Shouldn't be a problem")
|
||||||
|
{
|
||||||
|
NzBoxf tmp(NzBoxi(0, 0, 0, 1, 1, 1));
|
||||||
|
REQUIRE(tmp == firstCenterAndUnit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GIVEN("Two wrong box (negative width, height and depth")
|
||||||
|
{
|
||||||
|
NzBoxf firstWrongBox(-NzVector3f::Unit());
|
||||||
|
NzBoxf secondWrongBox(-NzVector3f::Unit());
|
||||||
|
|
||||||
|
WHEN("We check if valid")
|
||||||
|
{
|
||||||
|
THEN("Result if false")
|
||||||
|
{
|
||||||
|
CHECK(!firstWrongBox.IsValid());
|
||||||
|
CHECK(!secondWrongBox.IsValid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WHEN("We correct them")
|
||||||
|
{
|
||||||
|
firstWrongBox.ExtendTo(NzVector3f::Unit());
|
||||||
|
secondWrongBox.Transform(NzMatrix4f::Scale(-NzVector3f::Unit()));
|
||||||
|
|
||||||
|
THEN("They should be valid")
|
||||||
|
{
|
||||||
|
CHECK(firstWrongBox.IsValid());
|
||||||
|
CHECK(secondWrongBox.IsValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
AND_WHEN("We ask if they contain boxes")
|
||||||
|
{
|
||||||
|
THEN("These results are expected")
|
||||||
|
{
|
||||||
|
CHECK(firstWrongBox.Contains(0.f, 0.f, 0.f));
|
||||||
|
CHECK(secondWrongBox.Contains(0.f, 0.f, 0.f));
|
||||||
|
|
||||||
|
secondWrongBox = secondWrongBox.Lerp(NzBoxf::Zero(), secondWrongBox, 0.f); // Zeroed
|
||||||
|
secondWrongBox.ExtendTo(NzBoxf(NzVector3f(0.1f, 0.1f, 0.1f), NzVector3f(0.9f, 0.9f, 0.9f)));
|
||||||
|
secondWrongBox.Translate(NzVector3f(0.05f, 0.05f, 0.05f)); // Box 0.15 to 0.95
|
||||||
|
CHECK(firstWrongBox.Contains(secondWrongBox));
|
||||||
|
|
||||||
|
NzBoxf test(1.f, -500.f, -500.f, 1000.f, 1000.f, 1000.f);
|
||||||
|
CHECK(test.Contains(NzBoxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
|
||||||
|
CHECK(test.Contains(500.f, 0.f, 0.f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue