Browse Source

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.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
1825d26c72
  1. 2
      src/Math/Geometry/Intersection.h
  2. 10
      src/Math/Geometry/Test/IntersectionTest.cpp

2
src/Math/Geometry/Intersection.h

@ -59,7 +59,7 @@ class Intersection {
T f = Vector3<T>::dot(planePosition, planeNormal); T f = Vector3<T>::dot(planePosition, planeNormal);
/* Compute t */ /* Compute t */
return (f-Vector3<T>::dot(planeNormal, a)/Vector3<T>::dot(planeNormal, b-a)); return (f-Vector3<T>::dot(planeNormal, a))/Vector3<T>::dot(planeNormal, b-a);
} }
}; };

10
src/Math/Geometry/Test/IntersectionTest.cpp

@ -29,25 +29,25 @@ namespace Magnum { namespace Math { namespace Geometry { namespace Test {
typedef Magnum::Math::Vector3<float> Vector3; typedef Magnum::Math::Vector3<float> Vector3;
void IntersectionTest::planeLine() { void IntersectionTest::planeLine() {
Vector3 planePosition; Vector3 planePosition(-1.0f, 1.0f, 0.5f);
Vector3 planeNormal(0.0f, 0.0f, 1.0f); Vector3 planeNormal(0.0f, 0.0f, 1.0f);
/* Inside line segment */ /* Inside line segment */
QCOMPARE((Intersection::planeLine(planePosition, planeNormal, 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 */ /* Outside line segment */
QCOMPARE((Intersection::planeLine(planePosition, planeNormal, 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 */ /* Line lies on the plane */
float nan = Intersection::planeLine(planePosition, planeNormal, 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); QVERIFY(nan != nan);
/* Line is parallell to the plane */ /* Line is parallell to the plane */
QCOMPARE((Intersection::planeLine(planePosition, planeNormal, QCOMPARE((Intersection::planeLine(planePosition, planeNormal,
Vector3(1, 0, 1), Vector3(0, 0, 1))), numeric_limits<float>::infinity()); Vector3(1.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f))), numeric_limits<float>::infinity());
} }
}}}} }}}}

Loading…
Cancel
Save