From 1825d26c72720003a00fd7693d572c0319b98e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 28 Apr 2012 02:13:38 +0200 Subject: [PATCH] Fixed serious error in Intersection::planeLine(). The unit test was so weak that this parenthesis error wasn't spotted until now. Updated the unit test to don't accept the previous code and also floats everywhere instead of ints. --- src/Math/Geometry/Intersection.h | 2 +- src/Math/Geometry/Test/IntersectionTest.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Math/Geometry/Intersection.h b/src/Math/Geometry/Intersection.h index f79eae8dc..b4cee3f72 100644 --- a/src/Math/Geometry/Intersection.h +++ b/src/Math/Geometry/Intersection.h @@ -59,7 +59,7 @@ class Intersection { T f = Vector3::dot(planePosition, planeNormal); /* Compute t */ - return (f-Vector3::dot(planeNormal, a)/Vector3::dot(planeNormal, b-a)); + return (f-Vector3::dot(planeNormal, a))/Vector3::dot(planeNormal, b-a); } }; diff --git a/src/Math/Geometry/Test/IntersectionTest.cpp b/src/Math/Geometry/Test/IntersectionTest.cpp index 51e76ff89..7809fe95c 100644 --- a/src/Math/Geometry/Test/IntersectionTest.cpp +++ b/src/Math/Geometry/Test/IntersectionTest.cpp @@ -29,25 +29,25 @@ namespace Magnum { namespace Math { namespace Geometry { namespace Test { typedef Magnum::Math::Vector3 Vector3; void IntersectionTest::planeLine() { - Vector3 planePosition; + Vector3 planePosition(-1.0f, 1.0f, 0.5f); Vector3 planeNormal(0.0f, 0.0f, 1.0f); /* Inside line segment */ QCOMPARE((Intersection::planeLine(planePosition, planeNormal, - Vector3(0, 0, -1), Vector3(0, 0, 1))), 0.5f); + Vector3(0.0f, 0.0f, -1.0f), Vector3(0.0f, 0.0f, 1.0f))), 0.75f); /* Outside line segment */ QCOMPARE((Intersection::planeLine(planePosition, planeNormal, - Vector3(0, 0, 1), Vector3(0, 0, 2))), -1.0f); + Vector3(0.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 2.0f))), -0.5f); /* Line lies on the plane */ float nan = Intersection::planeLine(planePosition, planeNormal, - Vector3(1, 0, 0), Vector3(0, 1, 0)); + Vector3(1.0f, 0.5f, 0.5f), Vector3(0.0f, 1.0f, 0.5f)); QVERIFY(nan != nan); /* Line is parallell to the plane */ QCOMPARE((Intersection::planeLine(planePosition, planeNormal, - Vector3(1, 0, 1), Vector3(0, 0, 1))), numeric_limits::infinity()); + Vector3(1.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f))), numeric_limits::infinity()); } }}}}