No problems
No problems found in Rect, Sphere, Vector2, Vector3 and Vector4 Former-commit-id: 6688608a2beaa9cf5328daf7e5108b6cfebd843d
This commit is contained in:
parent
cb8ab90300
commit
89e0f631d6
|
|
@ -64,7 +64,7 @@ template<typename T>
|
|||
bool NzRect<T>::Contains(const NzRect<T>& rect) const
|
||||
{
|
||||
return Contains(rect.x, rect.y) &&
|
||||
Contains(rect.x + rect.width, rect.y + rect.height);
|
||||
Contains(rect.x + rect.width, rect.y + rect.height);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
@ -410,7 +410,7 @@ template<typename T>
|
|||
bool NzRect<T>::operator==(const NzRect& rect) const
|
||||
{
|
||||
return NzNumberEquals(x, rect.x) && NzNumberEquals(y, rect.y) &&
|
||||
NzNumberEquals(width, rect.width) && NzNumberEquals(height, rect.height);
|
||||
NzNumberEquals(width, rect.width) && NzNumberEquals(height, rect.height);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
|||
|
|
@ -51,13 +51,13 @@ bool NzSphere<T>::Contains(T X, T Y, T Z) const
|
|||
template<typename T>
|
||||
bool NzSphere<T>::Contains(const NzBox<T>& box) const
|
||||
{
|
||||
if (box.GetMinimum().SquaredDistance(GetPosition()) <= radius * radius)
|
||||
{
|
||||
if (box.GetMaximum().SquaredDistance(GetPosition()) <= radius * radius)
|
||||
return true;
|
||||
}
|
||||
if (box.GetMinimum().SquaredDistance(GetPosition()) <= radius * radius)
|
||||
{
|
||||
if (box.GetMaximum().SquaredDistance(GetPosition()) <= radius * radius)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
template<typename T>
|
||||
bool NzSphere<T>::Contains(const NzVector3<T>& point) const
|
||||
|
|
@ -156,7 +156,7 @@ bool NzSphere<T>::Intersect(const NzBox<T>& box) const
|
|||
squaredDistance += diff*diff;
|
||||
}
|
||||
|
||||
return squaredDistance <= radius * radius;
|
||||
return squaredDistance <= radius * radius;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
SCENARIO("Rect", "[MATH][RECT]")
|
||||
{
|
||||
GIVEN("Two same rectangles center and unit lengths")
|
||||
{
|
||||
NzRectf firstCenterAndUnit(0.f, 0.f, 1.f, 1.f);
|
||||
NzRectf secondCenterAndUnit(NzRecti(NzVector2i::Unit(), NzVector2i::Zero()));
|
||||
|
||||
WHEN("We ask if they are the same")
|
||||
{
|
||||
THEN("They should be")
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit == secondCenterAndUnit);
|
||||
REQUIRE(firstCenterAndUnit.GetCenter() == secondCenterAndUnit.GetCenter());
|
||||
REQUIRE(firstCenterAndUnit.GetCorner(nzRectCorner_LeftBottom) == secondCenterAndUnit.GetCorner(nzRectCorner_LeftBottom));
|
||||
CHECK(firstCenterAndUnit.IsValid());
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We move one from (0.5, 0.5)")
|
||||
{
|
||||
firstCenterAndUnit.Translate(NzVector2f(0.5f, 0.5f));
|
||||
|
||||
THEN("The collision should be (0.5, 0.5) -> (0.5, 0.5)")
|
||||
{
|
||||
NzRectf tmp;
|
||||
CHECK(firstCenterAndUnit.Intersect(secondCenterAndUnit, &tmp));
|
||||
REQUIRE(tmp == NzRectf(0.5f, 0.5f, 0.5f, 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We make an empty")
|
||||
{
|
||||
THEN("It's not valid")
|
||||
{
|
||||
CHECK(!(firstCenterAndUnit * 0.f).IsValid());
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We ask for infos")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit.GetLengths() == NzVector2f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMaximum() == NzVector2f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMinimum() == NzVector2f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetNegativeVertex(NzVector2f::Unit()) == NzVector2f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPosition() == NzVector2f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPositiveVertex(NzVector2f::Unit()) == NzVector2f::Unit());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
#include <Nazara/Math/Sphere.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
SCENARIO("Sphere", "[MATH][SPHERE]")
|
||||
{
|
||||
GIVEN("Two same sphere center and unit")
|
||||
{
|
||||
NzSpheref firstCenterAndUnit(0.f, 0.f, 0.f, 1.f);
|
||||
NzSpheref secondCenterAndUnit(NzSphere<int>(NzVector3i::Zero(), 1));
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
THEN("They are the same")
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit == secondCenterAndUnit);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We ask if they intersect or contain")
|
||||
{
|
||||
THEN("These results are expected for Contains")
|
||||
{
|
||||
CHECK(firstCenterAndUnit.Contains(0.5f, 0.5f, 0.5f));
|
||||
CHECK(firstCenterAndUnit.Contains(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 0.5f)));
|
||||
CHECK(!firstCenterAndUnit.Contains(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 5.f)));
|
||||
}
|
||||
|
||||
THEN("There are for Intersect")
|
||||
{
|
||||
CHECK(firstCenterAndUnit.Intersect(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 0.5f)));
|
||||
CHECK(firstCenterAndUnit.Intersect(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 5.f)));
|
||||
CHECK(!firstCenterAndUnit.Intersect(NzBoxf(NzVector3f::Unit() * 5.f, NzVector3f::Unit())));
|
||||
|
||||
CHECK(firstCenterAndUnit.Intersect(NzSpheref(NzVector3f::Zero(), 0.5f)));
|
||||
CHECK(firstCenterAndUnit.Intersect(NzSpheref(NzVector3f::Zero(), 5.f)));
|
||||
CHECK(!firstCenterAndUnit.Intersect(NzSpheref(NzVector3f::Unit() * 5.f, 1.f)));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We ask for distance")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit.Distance(NzVector3f::UnitX()) == Approx(1.f));
|
||||
REQUIRE(firstCenterAndUnit.SquaredDistance(NzVector3f::UnitX()) == Approx(1.f));
|
||||
|
||||
NzSpheref tmp(NzVector3f::UnitX(), 1.f);
|
||||
REQUIRE(tmp.Distance(NzVector3f::UnitX() * 4.f) == Approx(3.f));
|
||||
REQUIRE(tmp.SquaredDistance(NzVector3f::UnitX() * 4.f) == Approx(9.f));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We get sphere from box unit and center")
|
||||
{
|
||||
NzBoxf centerUnitBox(NzVector3f::Unit() * -0.5f, NzVector3f::Unit() * 0.5f);
|
||||
|
||||
THEN("This is equal to sphere center and radius 0.75")
|
||||
{
|
||||
REQUIRE(centerUnitBox.GetSquaredBoundingSphere() == NzSpheref(NzVector3f::Zero(), 0.75f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
SCENARIO("Vector2", "[MATH][VECTOR2]")
|
||||
{
|
||||
GIVEN("Two same vectors (1, 1)")
|
||||
{
|
||||
NzVector2f firstUnit(1.f);
|
||||
NzVector2f secondUnit(NzVector2i(NzVector4i(1, 1, 3, 5)));
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
THEN("They are the same")
|
||||
{
|
||||
REQUIRE(firstUnit == secondUnit);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We test the dot product")
|
||||
{
|
||||
NzVector2f tmp(-1.f, 1.f);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstUnit.AbsDotProduct(tmp) == Approx(2.f));
|
||||
REQUIRE(firstUnit.DotProduct(tmp) == Approx(0.f));
|
||||
REQUIRE(firstUnit.AngleBetween(tmp) == Approx(90.f));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We ask for distance from (-2, -3)")
|
||||
{
|
||||
NzVector2f tmp(-2.f, -3.f);
|
||||
NzVector2f tmp2(-1.f, -1.f);
|
||||
|
||||
THEN("These are expected")
|
||||
{
|
||||
REQUIRE(firstUnit.Distance(tmp2) == Approx(2.f * std::sqrt(2.f)));
|
||||
REQUIRE(firstUnit.Distance(tmp) == Approx(5.f));
|
||||
REQUIRE(firstUnit.SquaredDistance(tmp) == Approx(25.f));
|
||||
|
||||
REQUIRE(firstUnit.GetSquaredLength() == Approx(2.f));
|
||||
REQUIRE(firstUnit.GetLength() == Approx(std::sqrt(2.f)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
SCENARIO("Vector3", "[MATH][VECTOR3]")
|
||||
{
|
||||
GIVEN("Two same unit vector")
|
||||
{
|
||||
NzVector3f firstUnit(1.f, 1.f, 1.f);
|
||||
NzVector3f secondUnit(NzVector3i(NzVector4i(1, 1, 1, 5)));
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
THEN("They are the same")
|
||||
{
|
||||
REQUIRE(firstUnit == secondUnit);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We test the dot product")
|
||||
{
|
||||
NzVector3f tmp(-1.f, 0.f, 1.f);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstUnit.AbsDotProduct(tmp) == Approx(2.f));
|
||||
REQUIRE(firstUnit.DotProduct(tmp) == Approx(0.f));
|
||||
REQUIRE(firstUnit.AngleBetween(tmp) == Approx(90.f));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We test the cross product")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(NzVector3f::CrossProduct(NzVector3f::UnitX(), NzVector3f::UnitY()) == NzVector3f::UnitZ());
|
||||
REQUIRE(NzVector3f::CrossProduct(NzVector3f(1.f, 2.f, 3.f), NzVector3f(3.f, 2.f, 1.f)) == NzVector3f(-4.f, 8.f, -4.f));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We ask for distance")
|
||||
{
|
||||
NzVector3f tmp(-1.f, -5.f, -8.f);
|
||||
|
||||
THEN("These are expected")
|
||||
{
|
||||
REQUIRE(firstUnit.Distance(tmp) == Approx(11.f));
|
||||
REQUIRE(firstUnit.SquaredDistance(tmp) == Approx(121.f));
|
||||
|
||||
REQUIRE(firstUnit.GetSquaredLength() == Approx(3.f));
|
||||
REQUIRE(firstUnit.GetLength() == Approx(std::sqrt(3.f)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
SCENARIO("Vector4", "[MATH][VECTOR4]")
|
||||
{
|
||||
GIVEN("Two same unit vector")
|
||||
{
|
||||
NzVector4f firstUnit(1.f, 1.f, 1.f);
|
||||
NzVector4f secondUnit(NzVector4i(1, 1, 1, 1));
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
THEN("They are the same")
|
||||
{
|
||||
REQUIRE(firstUnit == secondUnit);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We test the dot product")
|
||||
{
|
||||
NzVector4f tmp(-1.f, 0.f, 1.f, 0.f);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstUnit.AbsDotProduct(tmp) == Approx(2.f));
|
||||
REQUIRE(firstUnit.DotProduct(tmp) == Approx(0.f));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We normalize")
|
||||
{
|
||||
NzVector4f tmp(1.f, 1.f, 1.f, 3.f);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstUnit.Normalize() == NzVector4f(1.f, NzVector3f::Unit()));
|
||||
REQUIRE(tmp.Normalize() == NzVector4f(NzVector3f::Unit() * (1.f / 3.f), 1.f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue