// Copyright (C) 2008-2011 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 static bool checkCollisions() { aabbox3d one(0,0,0,4,4,4); aabbox3d two(2,2,2,4,4,4); if (two.getInterpolated(one, 1) != two) { logTestString("aabbox3d interpolation wrong on 1\n"); return false; } if (two.getInterpolated(one, 0) != one) { logTestString("aabbox3d interpolation wrong on 0\n"); return false; } aabbox3d three(two.getInterpolated(one, 0.5f)); if (two == one) { logTestString("aabbox3d interpolation wrong on 0.5 (right)\n"); return false; } if (two == three) { logTestString("aabbox3d interpolation wrong on 0.5 (left)\n"); return false; } three.reset(aabbox3d(2,2,2,5,5,5)); if (!two.isFullInside(one)) { logTestString("small aabbox3d is not fully inside\n"); return false; } if (three.isFullInside(one)) { logTestString("large aabbox3d is fully inside\n"); return false; } if (!two.intersectsWithBox(one)) { logTestString("small aabbox3d does not intersect\n"); return false; } if (!three.intersectsWithBox(one)) { logTestString("large aabbox3d does not intersect\n"); return false; } core::line3d line(-2,-2,-2,2,2,2); if (!one.intersectsWithLine(line)) { logTestString("aabbox3d does not intersect with line(1)\n"); return false; } line.end.set(2,2,10); if (!one.intersectsWithLine(line)) { logTestString("aabbox3d does not intersect with line(2)\n"); return false; } line.end.set(0,2,10); if (one.intersectsWithLine(line)) { logTestString("aabbox3d does intersect with line(3)\n"); return false; } return true; } template static bool checkPoints() { aabbox3d one(-1,-2,-3,2,2,2); if (!one.isPointInside(core::vector3d(-1,-2,-3))) { logTestString("isPointInside failed with min vertex\n"); return false; } if (!one.isPointInside(core::vector3d(-1,2,-3))) { logTestString("isPointInside failed with other min vertex\n"); return false; } if (!one.isPointInside(core::vector3d(2,-2,2))) { logTestString("isPointInside failed with other max vertex\n"); return false; } if (!one.isPointInside(core::vector3d(2,2,2))) { logTestString("isPointInside failed with max vertex\n"); return false; } if (!one.isPointInside(core::vector3d(0,0,0))) { logTestString("isPointInside failed with origin\n"); return false; } if (!one.isPointInside(core::vector3d((T)1.2,-1,1))) { logTestString("isPointInside failed with random point inside\n"); return false; } if (one.isPointInside(core::vector3d(-2,-2,-3))) { logTestString("isPointInside failed near min vertex\n"); return false; } if (one.isPointInside(core::vector3d(2,3,2))) { logTestString("isPointInside failed near max vertex\n"); return false; } if (one.isPointInside(core::vector3d(3,0,0))) { logTestString("isPointInside failed near origin\n"); return false; } if (one.isPointInside(core::vector3d((T)10.2,-1,1))) { logTestString("isPointInside failed with random point outside\n"); return false; } if (one.isPointTotalInside(core::vector3d(-1,-2,-3))) { logTestString("isPointTotalInside failed with min vertex\n"); return false; } if (one.isPointTotalInside(core::vector3d(-1,2,-3))) { logTestString("isPointTotalInside failed with other min vertex\n"); return false; } if (one.isPointTotalInside(core::vector3d(2,-2,2))) { logTestString("isPointTotalInside failed with other max vertex\n"); return false; } if (one.isPointTotalInside(core::vector3d(2,2,2))) { logTestString("isPointTotalInside failed with max vertex\n"); return false; } if (!one.isPointTotalInside(core::vector3d(0,0,0))) { logTestString("isPointTotalInside failed with origin\n"); return false; } if (!one.isPointTotalInside(core::vector3d((T)1.2,-1,1))) { logTestString("isPointTotalInside failed with random point inside\n"); return false; } if (one.isPointTotalInside(core::vector3d((T)10.2,-1,1))) { logTestString("isPointTotalInside failed with random point outside\n"); return false; } core::plane3d plane(core::vector3d(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 static bool doTests() { aabbox3d empty; aabbox3d one(-1,-1,-1,1,1,1); if (empty != one) { logTestString("default aabbox3d wrong, or comparison failed\n"); return false; } if (empty.getCenter() != core::vector3d(0,0,0)) { logTestString("default aabbox3d has wrong Center\n"); return false; } if (empty.getExtent() != core::vector3d(2,2,2)) { logTestString("default aabbox3d has wrong Extent\n"); return false; } if (empty.isEmpty()) { logTestString("default aabbox3d is empty\n"); return false; } if (empty.getVolume() != 8) { logTestString("default aabbox3d has wrong volume\n"); return false; } if (empty.getArea() != 24) { logTestString("default aabbox3d has wrong area\n"); return false; } aabbox3d two(core::vector3d(-1,-1,-1),core::vector3d(2,2,2)); if (empty == two) { logTestString("empty aabbox3d too large, or comparison failed\n"); return false; } if (two.getCenter() != core::vector3d((T)0.5,(T)0.5,(T)0.5)) { logTestString("extended aabbox3d has wrong Center\n"); return false; } if (two.getExtent() != core::vector3d(3,3,3)) { logTestString("extended aabbox3d has wrong Extent\n"); return false; } if (two.isEmpty()) { logTestString("extended aabbox3d is empty\n"); return false; } if (two.getVolume() != 27) { logTestString("extended aabbox3d has wrong volume\n"); return false; } if (two.getArea() != 54) { logTestString("extended aabbox3d 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(1,1,1)) { logTestString("singular aabbox3d has wrong Center\n"); return false; } if (one.getExtent() != core::vector3d(0,0,0)) { logTestString("singular aabbox3d has Extent\n"); return false; } if (!one.isEmpty()) { logTestString("empty aabbox3d is not empty\n"); return false; } if (one.getVolume() != 0) { logTestString("empty aabbox3d has wrong volume\n"); return false; } if (one.getArea() != 0) { logTestString("empty aabbox3d has wrong area\n"); return false; } one.addInternalPoint(core::vector3d(-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(2,2,2)); if (one != two) { logTestString("addInternalPoint for aabbox3d 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)0.5,0,(T)-0.5)) { logTestString("large aabbox3d has wrong Center\n"); return false; } if (one.getExtent() != core::vector3d(3,4,5)) { logTestString("large aabbox3d has wrong Extent\n"); return false; } if (one.isEmpty()) { logTestString("large aabbox3d is empty\n"); return false; } if (one.getVolume() != 60) { logTestString("large aabbox3d has wrong volume\n"); return false; } if (one.getArea() != 94) { logTestString("large aabbox3d has wrong area\n"); return false; } if (!checkPoints()) return false; return true; } /** Test the functionality of aabbox3d. */ bool testaabbox3d(void) { bool f32Success = doTests(); f32Success &= checkCollisions(); if(f32Success) logTestString("aabbox3d tests passed\n\n"); else logTestString("\n*** aabbox3d tests failed ***\n\n"); bool f64Success = doTests(); f64Success &= checkCollisions(); if(f64Success) logTestString("aabbox3d tests passed\n\n"); else logTestString("\n*** aabbox3d tests failed ***\n\n"); bool s32Success = doTests(); if(s32Success) logTestString("aabbox3d tests passed\n\n"); else logTestString("\n*** aabbox3d tests failed ***\n\n"); return f32Success && f64Success && s32Success; }