From 7142566932b457d3a70f6ee39c9b3812e30b699f Mon Sep 17 00:00:00 2001 From: namreeb Date: Mon, 18 Sep 2023 16:48:51 -1000 Subject: [PATCH] More robust fix for floating point imprecision. This should fix issue #63 --- utility/MathHelper.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utility/MathHelper.cpp b/utility/MathHelper.cpp index 4c1efbe..a53527b 100644 --- a/utility/MathHelper.cpp +++ b/utility/MathHelper.cpp @@ -86,7 +86,10 @@ float Convert::ToRadians(float degrees) void Convert::WorldToAdt(const Vector3& vertex, int& adtX, int& adtY) { - auto constexpr mid = 32.0 * MeshSettings::AdtSize; + // FIXME: We can't use MeshSettings::AdtSize here because of floating point + // imprecision. Should consider changing MeshSettings:: values to double. + auto constexpr mid = 32.0 * (533.0 + (1.0 / 3.0)); + adtX = static_cast((mid - vertex.Y) / MeshSettings::AdtSize); adtY = static_cast((mid - vertex.X) / MeshSettings::AdtSize); }