Fix 'dtRandomPointInConvexPoly()' returning a garbage value if s == 1.0f. (#271)
This commit is contained in:
parent
ef3ea40f7a
commit
46654531e4
@ -342,8 +342,8 @@ void dtRandomPointInConvexPoly(const float* pts, const int npts, float* areas,
|
||||
// Find sub triangle weighted by area.
|
||||
const float thr = s*areasum;
|
||||
float acc = 0.0f;
|
||||
float u = 0.0f;
|
||||
int tri = 0;
|
||||
float u = 1.0f;
|
||||
int tri = npts - 1;
|
||||
for (int i = 2; i < npts; i++) {
|
||||
const float dacc = areas[i];
|
||||
if (thr >= acc && thr < (acc+dacc))
|
||||
|
@ -45,7 +45,7 @@
|
||||
// Uncomment this to dump all the requests in stdout.
|
||||
#define DUMP_REQS
|
||||
|
||||
// Returns a random number [0..1)
|
||||
// Returns a random number [0..1]
|
||||
static float frand()
|
||||
{
|
||||
// return ((float)(rand() & 0xffff)/(float)0xffff);
|
||||
|
@ -202,6 +202,8 @@ project "Tests"
|
||||
"../Tests/*.cpp",
|
||||
"../Tests/Recast/*.h",
|
||||
"../Tests/Recast/*.cpp",
|
||||
"../Tests/Detour/*.h",
|
||||
"../Tests/Detour/*.cpp",
|
||||
}
|
||||
|
||||
-- project dependencies
|
||||
|
33
Tests/Detour/Tests_Detour.cpp
Normal file
33
Tests/Detour/Tests_Detour.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "DetourCommon.h"
|
||||
|
||||
TEST_CASE("dtRandomPointInConvexPoly")
|
||||
{
|
||||
SECTION("Properly works when the argument 's' is 1.0f")
|
||||
{
|
||||
const float pts[] = {
|
||||
0, 0, 0,
|
||||
0, 0, 1,
|
||||
1, 0, 0,
|
||||
};
|
||||
const int npts = 3;
|
||||
float areas[6];
|
||||
float out[3];
|
||||
|
||||
dtRandomPointInConvexPoly(pts, npts, areas, 0.0f, 1.0f, out);
|
||||
REQUIRE(out[0] == 0);
|
||||
REQUIRE(out[1] == 0);
|
||||
REQUIRE(out[2] == 1);
|
||||
|
||||
dtRandomPointInConvexPoly(pts, npts, areas, 0.5f, 1.0f, out);
|
||||
REQUIRE(out[0] == 1.0f / 2);
|
||||
REQUIRE(out[1] == 0);
|
||||
REQUIRE(out[2] == 1.0f / 2);
|
||||
|
||||
dtRandomPointInConvexPoly(pts, npts, areas, 1.0f, 1.0f, out);
|
||||
REQUIRE(out[0] == 1);
|
||||
REQUIRE(out[1] == 0);
|
||||
REQUIRE(out[2] == 0);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user