Browse Source

Debug operator for shape type.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
f7d002d06d
  1. 39
      src/Physics/AbstractShape.cpp
  2. 8
      src/Physics/AbstractShape.h
  3. 41
      src/Physics/Test/AbstractShapeTest.cpp
  4. 25
      src/Physics/Test/AbstractShapeTest.h
  5. 1
      src/Physics/Test/CMakeLists.txt
  6. 4
      src/Physics/Test/CapsuleTest.h
  7. 4
      src/Physics/Test/PlaneTest.h
  8. 46
      src/Physics/Test/ShapeTestBase.h
  9. 4
      src/Physics/Test/SphereTest.h

39
src/Physics/AbstractShape.cpp

@ -15,6 +15,8 @@
#include "AbstractShape.h" #include "AbstractShape.h"
#include <Utility/Debug.h>
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> bool AbstractShape<dimensions>::collides(const AbstractShape* other) const { template<std::uint8_t dimensions> bool AbstractShape<dimensions>::collides(const AbstractShape* other) const {
@ -28,4 +30,41 @@ template<std::uint8_t dimensions> bool AbstractShape<dimensions>::collides(const
template class AbstractShape<2>; template class AbstractShape<2>;
template class AbstractShape<3>; template class AbstractShape<3>;
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug operator<<(Debug debug, AbstractShape2D::Type value) {
switch(value) {
#define _val(value) case AbstractShape2D::Type::value: return debug << "AbstractShape2D::Type::" #value;
_val(Point)
_val(Line)
_val(LineSegment)
_val(Sphere)
_val(Capsule)
_val(AxisAlignedBox)
_val(Box)
_val(ShapeGroup)
#undef _val
}
return debug << "AbstractShape2D::Type::(unknown)";
}
Debug operator<<(Debug debug, AbstractShape3D::Type value) {
switch(value) {
#define _val(value) case AbstractShape3D::Type::value: return debug << "AbstractShape3D::Type::" #value;
_val(Point)
_val(Line)
_val(LineSegment)
_val(Sphere)
_val(Capsule)
_val(AxisAlignedBox)
_val(Box)
_val(ShapeGroup)
_val(Plane)
#undef _val
}
return debug << "AbstractShape2D::Type::(unknown)";
}
#endif
}} }}

8
src/Physics/AbstractShape.h

@ -124,6 +124,14 @@ typedef AbstractShape<2> AbstractShape2D;
/** @brief Abstract three-dimensional shape */ /** @brief Abstract three-dimensional shape */
typedef AbstractShape<3> AbstractShape3D; typedef AbstractShape<3> AbstractShape3D;
/** @debugoperator{Magnum::Physics::AbstractShape} */
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug PHYSICS_EXPORT operator<<(Debug debug, AbstractShape2D::Type value);
Debug PHYSICS_EXPORT operator<<(Debug debug, AbstractShape3D::Type value);
#else
template<std::uint8_t dimensions> Debug operator<<(Debug debug, typename AbstractShape<dimensions>::Type value);
#endif
}} }}
#endif #endif

41
src/Physics/Test/AbstractShapeTest.cpp

@ -0,0 +1,41 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include "AbstractShapeTest.h"
#include <sstream>
#include <Utility/Debug.h>
#include "Physics/AbstractShape.h"
CORRADE_TEST_MAIN(Magnum::Physics::Test::AbstractShapeTest)
namespace Magnum { namespace Physics { namespace Test {
AbstractShapeTest::AbstractShapeTest() {
addTests(&AbstractShapeTest::debug);
}
void AbstractShapeTest::debug() {
std::ostringstream o;
Debug(&o) << AbstractShape2D::Type::ShapeGroup;
CORRADE_COMPARE(o.str(), "AbstractShape2D::Type::ShapeGroup\n");
o.str("");
Debug(&o) << AbstractShape3D::Type::Plane;
CORRADE_COMPARE(o.str(), "AbstractShape3D::Type::Plane\n");
}
}}}

25
src/Physics/Test/AbstractShapeTest.h

@ -17,29 +17,14 @@
#include <TestSuite/Tester.h> #include <TestSuite/Tester.h>
#include "Math/Matrix4.h"
#include "Magnum.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class AbstractShapeTest { class AbstractShapeTest: public Corrade::TestSuite::Tester<AbstractShapeTest> {
protected: public:
template<class T> void randomTransformation(T& shape) { AbstractShapeTest();
shape.applyTransformation(Matrix4::translation({7.0f, 8.0f, -9.0f}));
}
};
#define VERIFY_COLLIDES(a, b) \ void debug();
CORRADE_VERIFY(a % b); \ };
CORRADE_VERIFY(b % a); \
CORRADE_VERIFY(a.collides(&b)); \
CORRADE_VERIFY(b.collides(&a));
#define VERIFY_NOT_COLLIDES(a, b) \
CORRADE_VERIFY(!(a % b)); \
CORRADE_VERIFY(!(b % a)); \
CORRADE_VERIFY(!(a.collides(&b))); \
CORRADE_VERIFY(!(b.collides(&a)));
}}} }}}

1
src/Physics/Test/CMakeLists.txt

@ -1,3 +1,4 @@
corrade_add_test2(PhysicsAbstractShapeTest AbstractShapeTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test2(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test2(PhysicsBoxTest BoxTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsBoxTest BoxTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test2(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics)

4
src/Physics/Test/CapsuleTest.h

@ -15,11 +15,11 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "AbstractShapeTest.h" #include "ShapeTestBase.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class CapsuleTest: public Corrade::TestSuite::Tester<CapsuleTest>, AbstractShapeTest { class CapsuleTest: public Corrade::TestSuite::Tester<CapsuleTest>, ShapeTestBase {
public: public:
CapsuleTest(); CapsuleTest();

4
src/Physics/Test/PlaneTest.h

@ -15,11 +15,11 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "AbstractShapeTest.h" #include "ShapeTestBase.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class PlaneTest: public Corrade::TestSuite::Tester<PlaneTest>, AbstractShapeTest { class PlaneTest: public Corrade::TestSuite::Tester<PlaneTest>, ShapeTestBase {
public: public:
PlaneTest(); PlaneTest();

46
src/Physics/Test/ShapeTestBase.h

@ -0,0 +1,46 @@
#ifndef Magnum_Physics_Test_ShapeTestBase_h
#define Magnum_Physics_Test_ShapeTestBase_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include <TestSuite/Tester.h>
#include "Math/Matrix4.h"
#include "Magnum.h"
namespace Magnum { namespace Physics { namespace Test {
class ShapeTestBase {
protected:
template<class T> void randomTransformation(T& shape) {
shape.applyTransformation(Matrix4::translation({7.0f, 8.0f, -9.0f}));
}
};
#define VERIFY_COLLIDES(a, b) \
CORRADE_VERIFY(a % b); \
CORRADE_VERIFY(b % a); \
CORRADE_VERIFY(a.collides(&b)); \
CORRADE_VERIFY(b.collides(&a));
#define VERIFY_NOT_COLLIDES(a, b) \
CORRADE_VERIFY(!(a % b)); \
CORRADE_VERIFY(!(b % a)); \
CORRADE_VERIFY(!(a.collides(&b))); \
CORRADE_VERIFY(!(b.collides(&a)));
}}}
#endif

4
src/Physics/Test/SphereTest.h

@ -15,11 +15,11 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "AbstractShapeTest.h" #include "ShapeTestBase.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class SphereTest: public Corrade::TestSuite::Tester<SphereTest>, AbstractShapeTest { class SphereTest: public Corrade::TestSuite::Tester<SphereTest>, ShapeTestBase {
public: public:
SphereTest(); SphereTest();

Loading…
Cancel
Save