This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/tests/navMesh/TestNavMeshBenchmark.cpp
frank 55061ef0da minor changes to floorplan
fixed some compile issues
worked on nav-meshes
added some tests
2018-01-16 12:41:05 +01:00

102 lines
2.6 KiB
C++

#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::NavMeshTriangle> nm;
NavMeshFactory<NM::NavMeshTriangle> 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<NM::NavMeshTriangle> rnd = nm.getRandom();
for (int i = 0; i < 5000*1000; ++i) {
NavMeshLocation<NM::NavMeshTriangle> 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::NavMeshTriangle> nm;
NavMeshFactory<NM::NavMeshTriangle> 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<float> 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<NM::NavMeshTriangle> loc = nm.getLocation(Point3(x,y,0));
NavMeshSub<NM::NavMeshTriangle>(loc, 5);
}
}
#endif