Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/tests/test_HierPathfinder.h
Show First 20 Lines • Show All 382 Lines • ▼ Show 20 Lines | else \ | ||||
check_closest_passable(5 * 5 + 3, 7 * 5 + 2, 2); | check_closest_passable(5 * 5 + 3, 7 * 5 + 2, 2); | ||||
#undef check_closest_passable | #undef check_closest_passable | ||||
PathGoal goal; | PathGoal goal; | ||||
goal.type = PathGoal::POINT; | goal.type = PathGoal::POINT; | ||||
// from the left of the C, goal is unreachable, expect closest navcell to goal | // from the left of the C, goal is unreachable, expect closest navcell to goal | ||||
oi = 5 * 5 + 3; oj = 3 * 5 + 3; | oi = 5 * 5 + 3; oj = 3 * 5 + 3; | ||||
pi = 5 * 5 + 3; pj = 7 * 5 + 2; goal.x = fixed::FromInt(pi); goal.z = fixed::FromInt(pj); | pi = 5 * 5 + 3; pj = 6 * 5 + 2; goal.x = fixed::FromInt(pi); goal.z = fixed::FromInt(pj); | ||||
hierPath.MakeGoalReachable(oi, oj, goal, PASS_1); | hierPath.MakeGoalReachable(oi, oj, goal, PASS_1); | ||||
hierPath.FindNearestPassableNavcell(pi, pj, PASS_1); | hierPath.FindNearestPassableNavcell(pi, pj, PASS_1); | ||||
TS_ASSERT(pi == goal.x.ToInt_RoundToNegInfinity() && pj == goal.z.ToInt_RoundToNegInfinity()); | TS_ASSERT_EQUALS(pi, goal.x.ToInt_RoundToNegInfinity()); | ||||
TS_ASSERT_EQUALS(pj, goal.z.ToInt_RoundToNegInfinity()); | |||||
// random reachable point. | // random reachable point. | ||||
oi = 5 * 5 + 3; oj = 3 * 5 + 3; | oi = 5 * 5 + 3; oj = 3 * 5 + 3; | ||||
pi = 26 * 5 + 3; pj = 5 * 5 + 2; goal.x = fixed::FromInt(pi) + fixed::FromInt(1)/3; goal.z = fixed::FromInt(pj) + fixed::FromInt(1)/3; | pi = 26 * 5 + 3; pj = 5 * 5 + 2; goal.x = fixed::FromInt(pi) + fixed::FromInt(1)/3; goal.z = fixed::FromInt(pj) + fixed::FromInt(1)/3; | ||||
hierPath.MakeGoalReachable(oi, oj, goal, PASS_1); | hierPath.MakeGoalReachable(oi, oj, goal, PASS_1); | ||||
TS_ASSERT(pi == goal.x.ToInt_RoundToNegInfinity() && pj == goal.z.ToInt_RoundToNegInfinity()); | TS_ASSERT(pi == goal.x.ToInt_RoundToNegInfinity() && pj == goal.z.ToInt_RoundToNegInfinity()); | ||||
// top-left corner | // top-left corner | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | #undef check_closest_passable | ||||
// Huge Circle goal, expect point closest to us. | // Huge Circle goal, expect point closest to us. | ||||
goal.type = PathGoal::CIRCLE; | goal.type = PathGoal::CIRCLE; | ||||
goal.hw = fixed::FromInt(20); | goal.hw = fixed::FromInt(20); | ||||
oi = 5 * 5 + 3; oj = 3 * 5 + 3; | oi = 5 * 5 + 3; oj = 3 * 5 + 3; | ||||
pi = 36 * 5 + 3; pj = 7 * 5 + 2; goal.x = fixed::FromInt(pi); goal.z = fixed::FromInt(pj); | pi = 36 * 5 + 3; pj = 7 * 5 + 2; goal.x = fixed::FromInt(pi); goal.z = fixed::FromInt(pj); | ||||
hierPath.MakeGoalReachable(oi, oj, goal, PASS_1); | hierPath.MakeGoalReachable(oi, oj, goal, PASS_1); | ||||
// bit of leeway for cell placement | // bit of leeway for cell placement | ||||
TS_ASSERT(std::fabs(euclidian(goal.x.ToInt_RoundToNegInfinity(), goal.z.ToInt_RoundToNegInfinity(), pi, pj)-20) < 1.5f); | TS_ASSERT(std::fabs(euclidian(goal.x.ToInt_RoundToNegInfinity(), goal.z.ToInt_RoundToNegInfinity(), pi, pj)-20) < 1.5f); | ||||
TS_ASSERT(std::fabs(euclidian(goal.x.ToInt_RoundToNegInfinity(), goal.z.ToInt_RoundToNegInfinity(), oi, oj) - euclidian(pi, pj, oi, oj)) < 22.0f); | TS_ASSERT(std::fabs(euclidian(goal.x.ToInt_RoundToNegInfinity(), goal.z.ToInt_RoundToNegInfinity(), oi, oj) - euclidian(pi, pj, oi, oj)) < 22.0f); | ||||
} | } | ||||
void test_regions_flood_fill() | void test_regions_flood_fill() | ||||
{ | { | ||||
// Partial test of region inner flood filling. | // Partial test of region inner flood filling. | ||||
Show All 34 Lines |
Wildfire Games · Phabricator