From e76178691d050ea63793cdcb63720eb61eae228c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Mar 2014 16:39:09 +0100 Subject: [PATCH] Shapes: added missing test for Shape::collides(). There is one not-yet-sure-about behavior, expecting the failure. --- src/Magnum/Shapes/Test/ShapeTest.cpp | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Magnum/Shapes/Test/ShapeTest.cpp b/src/Magnum/Shapes/Test/ShapeTest.cpp index 5ad60e6a3..9f88909c4 100644 --- a/src/Magnum/Shapes/Test/ShapeTest.cpp +++ b/src/Magnum/Shapes/Test/ShapeTest.cpp @@ -41,6 +41,7 @@ class ShapeTest: public TestSuite::Tester { ShapeTest(); void clean(); + void collides(); void firstCollision(); void shapeGroup(); }; @@ -52,6 +53,7 @@ typedef SceneGraph::Object Object3D; ShapeTest::ShapeTest() { addTests({&ShapeTest::clean, + &ShapeTest::collides, &ShapeTest::firstCollision, &ShapeTest::shapeGroup}); } @@ -96,6 +98,45 @@ void ShapeTest::clean() { CORRADE_VERIFY(b.isDirty()); } +void ShapeTest::collides() { + Scene3D scene; + ShapeGroup3D shapes; + Object3D a(&scene); + Shape aShape(a, {{1.0f, -2.0f, 3.0f}, 1.5f}, &shapes); + + { + /* Collision with point inside the sphere */ + Shape aShape2(a, {{1.0f, -2.0f, 3.0f}}, &shapes); + shapes.setClean(); + CORRADE_VERIFY(aShape.collides(aShape2)); + } { + /* No collision with point inside the sphere, but not in the same group */ + ShapeGroup3D shapes2; + Shape aShape3(a, {{1.0f, -2.0f, 3.0f}}, &shapes2); + shapes2.setClean(); + CORRADE_VERIFY(!aShape.collides(aShape3)); + } { + CORRADE_EXPECT_FAIL("Should cross-scene collision work or not?"); + /* No collision with point inside the sphere, but not in the same scene */ + Scene3D scene2; + Object3D c(&scene2); + Shape cShape(c, {{1.0f, -2.0f, 3.0f}}, &shapes); + shapes.setClean(); + CORRADE_VERIFY(!aShape.collides(cShape)); + } { + /* No collision with point outside of the sphere */ + Object3D b(&scene); + Shape bShape(b, {{3.0f, -2.0f, 3.0f}}, &shapes); + shapes.setClean(); + CORRADE_VERIFY(!aShape.collides(bShape)); + + /* Move point inside the sphere -- collision */ + b.translate(Vector3::xAxis(-1.0f)); + shapes.setClean(); + CORRADE_VERIFY(aShape.collides(bShape)); + } +} + void ShapeTest::firstCollision() { Scene3D scene; ShapeGroup3D shapes;