#ifdef WITH_TESTS #include "../Tests.h" #include "../../navMesh/NavMeshFactory.h" #include "../../navMesh/walk/NavMeshSub.h" using namespace NM; TEST(NavMeshBenchmark, benchDraw) { Floorplan::IndoorMap map; Floorplan::Floor floor; map.floors.push_back(&floor); floor.atHeight = 0; floor.height = 3; Floorplan::FloorOutlinePolygon outline; floor.outline.push_back(&outline); // circle (many triangles) int i = 0; for (float f = 0; f < M_PI*2; f += 0.1) { const float x = std::cos(f) * 10; const float y = std::sin(f) * 10; outline.poly.points.push_back(Point2(x,y)); ++i; } outline.outdoor = false; outline.method = Floorplan::OutlineMethod::ADD; NavMeshSettings set; NavMesh nm; NavMeshFactory fac(&nm, set); fac.build(&map); ASSERT_NEAR(-10, nm.getBBox().getMin().x, 0.5); ASSERT_NEAR(-10, nm.getBBox().getMin().y, 0.5); ASSERT_NEAR( 0, nm.getBBox().getMin().z, 0.5); ASSERT_NEAR(+10, nm.getBBox().getMax().x, 0.5); ASSERT_NEAR(+10, nm.getBBox().getMax().y, 0.5); ASSERT_NEAR( 0, nm.getBBox().getMax().z, 0.5); ASSERT_EQ(45, nm.getNumTriangles()); NavMeshRandom rnd = nm.getRandom(); for (int i = 0; i < 5000*1000; ++i) { NavMeshLocation loc = rnd.draw(); } } TEST(NavMeshBenchmark, benchSubRegion) { Floorplan::IndoorMap map; Floorplan::Floor floor; map.floors.push_back(&floor); floor.atHeight = 0; floor.height = 3; Floorplan::FloorOutlinePolygon outline; floor.outline.push_back(&outline); // circle (many triangles) int i = 0; for (float f = 0; f < M_PI*2; f += 0.1) { const float x = std::cos(f) * 10; const float y = std::sin(f) * 10; outline.poly.points.push_back(Point2(x,y)); ++i; } outline.outdoor = false; outline.method = Floorplan::OutlineMethod::ADD; NavMeshSettings set; NavMesh nm; NavMeshFactory fac(&nm, set); fac.build(&map); ASSERT_NEAR(-10, nm.getBBox().getMin().x, 0.5); ASSERT_NEAR(-10, nm.getBBox().getMin().y, 0.5); ASSERT_NEAR( 0, nm.getBBox().getMin().z, 0.5); ASSERT_NEAR(+10, nm.getBBox().getMax().x, 0.5); ASSERT_NEAR(+10, nm.getBBox().getMax().y, 0.5); ASSERT_NEAR( 0, nm.getBBox().getMax().z, 0.5); ASSERT_EQ(45, nm.getNumTriangles()); std::minstd_rand gen(1337); std::uniform_real_distribution dist(0, M_PI*2); for (int i = 0; i < 50000; ++i) { const float f = dist(gen); const float x = std::cos(f) * 9; const float y = std::sin(f) * 9; NavMeshLocation loc = nm.getLocation(Point3(x,y,0)); NavMeshSub(loc, 5); } } #endif