Minor fixes

This commit is contained in:
SirLynix 2023-07-30 19:46:01 +02:00
parent a7eba496fb
commit e2808192aa
12 changed files with 22 additions and 28 deletions

View File

@ -102,6 +102,7 @@ jobs:
# Run unit tests
- name: Run unit tests
if: matrix.mode != 'releasedbg
run: xmake run UnitTests
# Setup installation configuration

View File

@ -234,9 +234,6 @@ int main(int argc, char* argv[])
for (std::size_t i = 0; i < planeModel.GetSubMeshCount(); ++i)
planeModel.SetMaterial(i, planeMat);
Nz::PredefinedInstanceData instanceUboOffsets = Nz::PredefinedInstanceData::GetOffsets();
Nz::PredefinedViewerData viewerUboOffsets = Nz::PredefinedViewerData::GetOffsets();
Nz::Vector2ui windowSize = window.GetSize();
Nz::ViewerInstance viewerInstance;

View File

@ -16,7 +16,7 @@ namespace Nz
struct ModuleConfigHasOverride<T, std::void_t<decltype(std::declval<T>().Override(std::declval<const CommandLineParameters&>()))>> : std::true_type {};
template<typename T>
auto OverrideModuleConfig(T&& module, const CommandLineParameters& params)
decltype(auto) OverrideModuleConfig(T&& module, const CommandLineParameters& params)
{
if constexpr (!std::is_const_v<T> && ModuleConfigHasOverride<T>::value)
module.Override(params);
@ -28,7 +28,7 @@ namespace Nz
struct Pick
{
template<typename First, typename... Args>
static auto Get(First&& first, Args&&... args)
static decltype(auto) Get(First&& first, Args&&... args)
{
if constexpr (std::is_same_v<T, std::decay_t<First>>)
return std::forward<First>(first);
@ -40,7 +40,7 @@ namespace Nz
}
template<typename First, typename... Args>
static auto Get(const CommandLineParameters& parameters, First&& first, Args&&... args)
static decltype(auto) Get(const CommandLineParameters& parameters, First&& first, Args&&... args)
{
if constexpr (std::is_same_v<T, std::decay_t<First>>)
return OverrideModuleConfig<First>(first, parameters);
@ -51,7 +51,7 @@ namespace Nz
}
}
static auto Get()
static T Get()
{
return T{};
}

View File

@ -31,9 +31,9 @@ namespace Nz
constexpr bool ApproxEqual(const Sphere& sphere, T maxDifference = std::numeric_limits<T>::epsilon()) const;
constexpr bool Contains(T X, T Y, T Z) const;
constexpr bool Contains(const Box<T>& box) const;
constexpr bool Contains(const Vector3<T>& point) const;
constexpr bool Contains(T X, T Y, T Z, T epsilon = std::numeric_limits<T>::epsilon()) const;
constexpr bool Contains(const Box<T>& box, T epsilon = std::numeric_limits<T>::epsilon()) const;
constexpr bool Contains(const Vector3<T>& point, T epsilon = std::numeric_limits<T>::epsilon()) const;
T Distance(T X, T Y, T Z) const;
T Distance(const Vector3<T>& point) const;

View File

@ -95,9 +95,9 @@ namespace Nz
* \see Contains
*/
template<typename T>
constexpr bool Sphere<T>::Contains(T X, T Y, T Z) const
constexpr bool Sphere<T>::Contains(T X, T Y, T Z, T epsilon) const
{
return Contains(Vector3<T>(X, Y, Z));
return Contains(Vector3<T>(X, Y, Z), epsilon);
}
/*!
@ -109,9 +109,9 @@ namespace Nz
* \see Contains
*/
template<typename T>
constexpr bool Sphere<T>::Contains(const Box<T>& box) const
constexpr bool Sphere<T>::Contains(const Box<T>& box, T epsilon) const
{
if (Contains(box.GetMinimum()) && Contains(box.GetMaximum()))
if (Contains(box.GetMinimum(), epsilon) && Contains(box.GetMaximum(), epsilon))
return true;
return false;
@ -124,9 +124,9 @@ namespace Nz
* \param point Position of the point
*/
template<typename T>
constexpr bool Sphere<T>::Contains(const Vector3<T>& point) const
constexpr bool Sphere<T>::Contains(const Vector3<T>& point, T epsilon) const
{
return GetPosition().SquaredDistance(point) <= radius * radius;
return (GetPosition().SquaredDistance(point) - radius * radius) <= epsilon;
}
/*!

View File

@ -258,11 +258,7 @@ int main()
Nz::SparsePtr<Nz::Vector2f> particleVelPtr(particleBasePtr + particleVelOffset, particleSize);
for (std::size_t i = 0; i < particleCount; ++i)
{
auto&& [pos, color] = logoParticles[i];
particleVelPtr[i] = Nz::Vector2f(velDis(rand), velDis(rand));
}
particleBuffer->Unmap();
});

View File

@ -208,7 +208,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
THEN("We should retrieve it")
{
CHECK(identity.GetScale() == scale);
CHECK(identity.GetScale().ApproxEqual(scale));
CHECK(identity.GetSquaredScale() == squaredScale);
}

View File

@ -68,7 +68,7 @@ SCENARIO("Plane", "[MATH][PLANE]")
THEN("It must be equal to XZ distance 1")
{
REQUIRE(xy == Nz::Planef(Nz::Vector3f::UnitY(), -1.f));
REQUIRE(xy.ApproxEqual(Nz::Planef(Nz::Vector3f::UnitY(), -1.f)));
}
}
@ -77,7 +77,7 @@ SCENARIO("Plane", "[MATH][PLANE]")
Nz::Planef xy(Nz::Vector3f(0.f, 1.f, 0.f), Nz::Vector3f(1.f, 1.f, 1.f), Nz::Vector3f(-1.f, 1.f, 0.f));
THEN("It must be equal to XZ distance 1")
{
REQUIRE(xy == Nz::Planef(-Nz::Vector3f::UnitY(), 1.f));
REQUIRE(xy.ApproxEqual(Nz::Planef(-Nz::Vector3f::UnitY(), 1.f)));
}
}
}

View File

@ -14,7 +14,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
THEN("They are the same and the proprieties of quaternions are respected")
{
REQUIRE(firstQuaternion.ApproxEqual(secondQuaternion));
REQUIRE(firstQuaternion.ComputeW() == secondQuaternion.Normalize());
REQUIRE(firstQuaternion.ComputeW().ApproxEqual(secondQuaternion.Normalize()));
REQUIRE(firstQuaternion.Conjugate() == secondQuaternion.Inverse());
REQUIRE(firstQuaternion.DotProduct(secondQuaternion) == Catch::Approx(1.f));
}
@ -200,7 +200,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
Nz::Vector3f origin(1.f, 0.f, 1.f);
Nz::Vector3f extremity(-1.f, 0.f, 1.f);
Nz::Quaternionf rotation = Nz::Quaternionf::RotationBetween(origin, extremity);
REQUIRE((rotation * origin).ApproxEqual(extremity));
REQUIRE((rotation * origin).ApproxEqual(extremity, 0.0001f));
}
}
}

View File

@ -75,7 +75,7 @@ SCENARIO("Ray", "[MATH][RAY]")
Nz::BoundingVolumef infiniteVolume(Nz::Extent::Infinite);
CHECK(ray.Intersect(infiniteVolume, &tmpClosest, &tmpFurthest));
CHECK(tmpClosest == Catch::Approx(0.f));
CHECK(tmpFurthest == std::numeric_limits<float>::infinity());
CHECK(std::isinf(tmpFurthest));
}
THEN("For the triangle collision's")

View File

@ -56,7 +56,7 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
THEN("For normal cases should be normal")
{
Nz::Vector2f normalized = firstUnit.GetNormal(&ratio);
REQUIRE(normalized == (Nz::Vector2f::Unit() / std::sqrt(2.f)));
REQUIRE(normalized.ApproxEqual(Nz::Vector2f::Unit() / std::sqrt(2.f)));
REQUIRE(ratio == Catch::Approx(std::sqrt(2.f)));
}

View File

@ -28,7 +28,7 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
REQUIRE(firstUnit.AbsDotProduct(tmp) == Catch::Approx(2.f));
REQUIRE(firstUnit.DotProduct(tmp) == Catch::Approx(0.f));
REQUIRE(firstUnit.AngleBetween(tmp).ApproxEqual(Nz::DegreeAnglef(90.f)));
REQUIRE(firstUnit.AngleBetween(-firstUnit).ApproxEqual(Nz::DegreeAnglef(180.f)));
REQUIRE(firstUnit.AngleBetween(-firstUnit).ApproxEqual(Nz::DegreeAnglef(180.f), 0.001f));
}
}