123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- // Copyright (C) 2008-2012 Colin MacDonald
- // No rights reserved: this software is in the public domain.
- #include "testUtils.h"
- using namespace irr;
- using namespace core;
- // These tests are also only called for f32 and f64, due to conversion problems
- // in the respective methods.
- template<class T>
- static bool checkCollisions()
- {
- aabbox3d<T> one(0,0,0,4,4,4);
- aabbox3d<T> two(2,2,2,4,4,4);
- if (two.getInterpolated(one, 1) != two)
- {
- logTestString("aabbox3d<T> interpolation wrong on 1\n");
- return false;
- }
- if (two.getInterpolated(one, 0) != one)
- {
- logTestString("aabbox3d<T> interpolation wrong on 0\n");
- return false;
- }
- aabbox3d<T> three(two.getInterpolated(one, 0.5f));
- if (two == one)
- {
- logTestString("aabbox3d<T> interpolation wrong on 0.5 (right)\n");
- return false;
- }
- if (two == three)
- {
- logTestString("aabbox3d<T> interpolation wrong on 0.5 (left)\n");
- return false;
- }
- three.reset(aabbox3d<T>(2,2,2,5,5,5));
- if (!two.isFullInside(one))
- {
- logTestString("small aabbox3d<T> is not fully inside\n");
- return false;
- }
- if (three.isFullInside(one))
- {
- logTestString("large aabbox3d<T> is fully inside\n");
- return false;
- }
- if (!two.intersectsWithBox(one))
- {
- logTestString("small aabbox3d<T> does not intersect\n");
- return false;
- }
- if (!three.intersectsWithBox(one))
- {
- logTestString("large aabbox3d<T> does not intersect\n");
- return false;
- }
- core::line3d<T> line(-2,-2,-2,2,2,2);
- if (!one.intersectsWithLine(line))
- {
- logTestString("aabbox3d<T> does not intersect with line(1)\n");
- return false;
- }
- line.end.set(2,2,10);
- if (!one.intersectsWithLine(line))
- {
- logTestString("aabbox3d<T> does not intersect with line(2)\n");
- return false;
- }
- line.end.set(0,2,10);
- if (one.intersectsWithLine(line))
- {
- logTestString("aabbox3d<T> does intersect with line(3)\n");
- return false;
- }
- return true;
- }
- template<class T>
- static bool checkPoints()
- {
- aabbox3d<T> one(-1,-2,-3,2,2,2);
- if (!one.isPointInside(core::vector3d<T>(-1,-2,-3)))
- {
- logTestString("isPointInside failed with min vertex\n");
- return false;
- }
- if (!one.isPointInside(core::vector3d<T>(-1,2,-3)))
- {
- logTestString("isPointInside failed with other min vertex\n");
- return false;
- }
- if (!one.isPointInside(core::vector3d<T>(2,-2,2)))
- {
- logTestString("isPointInside failed with other max vertex\n");
- return false;
- }
- if (!one.isPointInside(core::vector3d<T>(2,2,2)))
- {
- logTestString("isPointInside failed with max vertex\n");
- return false;
- }
- if (!one.isPointInside(core::vector3d<T>(0,0,0)))
- {
- logTestString("isPointInside failed with origin\n");
- return false;
- }
- if (!one.isPointInside(core::vector3d<T>((T)1.2,-1,1)))
- {
- logTestString("isPointInside failed with random point inside\n");
- return false;
- }
- if (one.isPointInside(core::vector3d<T>(-2,-2,-3)))
- {
- logTestString("isPointInside failed near min vertex\n");
- return false;
- }
- if (one.isPointInside(core::vector3d<T>(2,3,2)))
- {
- logTestString("isPointInside failed near max vertex\n");
- return false;
- }
- if (one.isPointInside(core::vector3d<T>(3,0,0)))
- {
- logTestString("isPointInside failed near origin\n");
- return false;
- }
- if (one.isPointInside(core::vector3d<T>((T)10.2,-1,1)))
- {
- logTestString("isPointInside failed with random point outside\n");
- return false;
- }
- if (one.isPointTotalInside(core::vector3d<T>(-1,-2,-3)))
- {
- logTestString("isPointTotalInside failed with min vertex\n");
- return false;
- }
- if (one.isPointTotalInside(core::vector3d<T>(-1,2,-3)))
- {
- logTestString("isPointTotalInside failed with other min vertex\n");
- return false;
- }
- if (one.isPointTotalInside(core::vector3d<T>(2,-2,2)))
- {
- logTestString("isPointTotalInside failed with other max vertex\n");
- return false;
- }
- if (one.isPointTotalInside(core::vector3d<T>(2,2,2)))
- {
- logTestString("isPointTotalInside failed with max vertex\n");
- return false;
- }
- if (!one.isPointTotalInside(core::vector3d<T>(0,0,0)))
- {
- logTestString("isPointTotalInside failed with origin\n");
- return false;
- }
- if (!one.isPointTotalInside(core::vector3d<T>((T)1.2,-1,1)))
- {
- logTestString("isPointTotalInside failed with random point inside\n");
- return false;
- }
- if (one.isPointTotalInside(core::vector3d<T>((T)10.2,-1,1)))
- {
- logTestString("isPointTotalInside failed with random point outside\n");
- return false;
- }
- core::plane3d<T> plane(core::vector3d<T>(0,0,-1), -10);
- if (one.classifyPlaneRelation(plane) != core::ISREL3D_BACK)
- {
- logTestString("box not behind\n");
- return false;
- }
- plane.D=0;
- if (one.classifyPlaneRelation(plane) != core::ISREL3D_CLIPPED)
- {
- logTestString("box not clipped\n");
- return false;
- }
- plane.D=10;
- if (one.classifyPlaneRelation(plane) != core::ISREL3D_FRONT)
- {
- logTestString("box not in front\n");
- return false;
- }
- return true;
- }
- template <class T>
- static bool doTests()
- {
- aabbox3d<T> empty;
- aabbox3d<T> one(-1,-1,-1,1,1,1);
- if (empty != one)
- {
- logTestString("default aabbox3d<T> wrong, or comparison failed\n");
- return false;
- }
- if (empty.getCenter() != core::vector3d<T>(0,0,0))
- {
- logTestString("default aabbox3d<T> has wrong Center\n");
- return false;
- }
- if (empty.getExtent() != core::vector3d<T>(2,2,2))
- {
- logTestString("default aabbox3d<T> has wrong Extent\n");
- return false;
- }
- if (empty.isEmpty())
- {
- logTestString("default aabbox3d<T> is empty\n");
- return false;
- }
- if (empty.getVolume() != 8)
- {
- logTestString("default aabbox3d<T> has wrong volume\n");
- return false;
- }
- if (empty.getArea() != 24)
- {
- logTestString("default aabbox3d<T> has wrong area\n");
- return false;
- }
- aabbox3d<T> two(core::vector3d<T>(-1,-1,-1),core::vector3d<T>(2,2,2));
- if (empty == two)
- {
- logTestString("empty aabbox3d<T> too large, or comparison failed\n");
- return false;
- }
- if (two.getCenter() != core::vector3d<T>((T)0.5,(T)0.5,(T)0.5))
- {
- logTestString("extended aabbox3d<T> has wrong Center\n");
- return false;
- }
- if (two.getExtent() != core::vector3d<T>(3,3,3))
- {
- logTestString("extended aabbox3d<T> has wrong Extent\n");
- return false;
- }
- if (two.isEmpty())
- {
- logTestString("extended aabbox3d<T> is empty\n");
- return false;
- }
- if (two.getVolume() != 27)
- {
- logTestString("extended aabbox3d<T> has wrong volume\n");
- return false;
- }
- if (two.getArea() != 54)
- {
- logTestString("extended aabbox3d<T> has wrong area\n");
- return false;
- }
- one.reset(1,1,1);
- if (one==empty)
- {
- logTestString("reset failed, or comparison failed\n");
- return false;
- }
- if (one.getCenter() != core::vector3d<T>(1,1,1))
- {
- logTestString("singular aabbox3d<T> has wrong Center\n");
- return false;
- }
- if (one.getExtent() != core::vector3d<T>(0,0,0))
- {
- logTestString("singular aabbox3d<T> has Extent\n");
- return false;
- }
- if (!one.isEmpty())
- {
- logTestString("empty aabbox3d<T> is not empty\n");
- return false;
- }
- if (one.getVolume() != 0)
- {
- logTestString("empty aabbox3d<T> has wrong volume\n");
- return false;
- }
- if (one.getArea() != 0)
- {
- logTestString("empty aabbox3d<T> has wrong area\n");
- return false;
- }
- one.addInternalPoint(core::vector3d<T>(-1,-1,-1));
- if (one!=empty)
- {
- logTestString("addInternalPoint failed, creating default bbox\n");
- return false;
- }
- one.reset(1,1,1);
- one.reset(empty);
- if (one!=empty)
- {
- logTestString("reset with bbox failed, creating default bbox\n");
- return false;
- }
- one.addInternalPoint(core::vector3d<T>(2,2,2));
- if (one != two)
- {
- logTestString("addInternalPoint for aabbox3d<T> failed.\n");
- return false;
- }
- one.addInternalBox(empty);
- if (one != two)
- {
- logTestString("addInternalBox with smaller box failed.\n");
- return false;
- }
- one.addInternalBox(two);
- if (one != two)
- {
- logTestString("addInternalBox with same box failed.\n");
- return false;
- }
- one.addInternalPoint(-1,-2,-3);
- two.addInternalPoint(-1,-2,-3);
- empty.addInternalBox(one);
- if (empty != two)
- {
- logTestString("addInternalBox with larger box failed\n");
- return false;
- }
- if (one.getCenter() != core::vector3d<T>((T)0.5,0,(T)-0.5))
- {
- logTestString("large aabbox3d<T> has wrong Center\n");
- return false;
- }
- if (one.getExtent() != core::vector3d<T>(3,4,5))
- {
- logTestString("large aabbox3d<T> has wrong Extent\n");
- return false;
- }
- if (one.isEmpty())
- {
- logTestString("large aabbox3d<T> is empty\n");
- return false;
- }
- if (one.getVolume() != 60)
- {
- logTestString("large aabbox3d<T> has wrong volume\n");
- return false;
- }
- if (one.getArea() != 94)
- {
- logTestString("large aabbox3d<T> has wrong area\n");
- return false;
- }
- if (!checkPoints<T>())
- return false;
- return true;
- }
- /** Test the functionality of aabbox3d<T>. */
- bool testaabbox3d(void)
- {
- bool f32Success = doTests<f32>();
- f32Success &= checkCollisions<f32>();
- if(f32Success)
- logTestString("aabbox3d<f32> tests passed\n\n");
- else
- logTestString("\n*** aabbox3d<f32> tests failed ***\n\n");
- bool f64Success = doTests<f64>();
- f64Success &= checkCollisions<f64>();
- if(f64Success)
- logTestString("aabbox3d<f64> tests passed\n\n");
- else
- logTestString("\n*** aabbox3d<f64> tests failed ***\n\n");
- bool s32Success = doTests<s32>();
- if(s32Success)
- logTestString("aabbox3d<s32> tests passed\n\n");
- else
- logTestString("\n*** aabbox3d<s32> tests failed ***\n\n");
- return f32Success && f64Success && s32Success;
- }
|