Working on unit tests for class world

This commit is contained in:
2021-08-03 11:25:12 -04:00
parent 91d7e1c15d
commit 202c5a24ba
13 changed files with 240 additions and 103 deletions

View File

@@ -12,7 +12,7 @@
#define CELL_SCALE 10.0
// Round a float and return as integer. Clamp result to the specified range.
static int round_and_clamp(double x, int lo, int hi) {
static int round_and_clamp(float x, int lo, int hi) {
x = round(x);
if (x < lo) return lo;
if (x > hi) return hi;
@@ -37,7 +37,7 @@ struct CellRange {
// beyond the maximum cell range. In that case, it clamps to the edge
// of the cell range.
//
static CellRange rect_cell_range(double x1, double y1, double x2, double y2) {
static CellRange rect_cell_range(float x1, float y1, float x2, float y2) {
CellRange result;
result.xlo = round_and_clamp(x1 / CELL_SCALE, -CELL_LIMIT, CELL_LIMIT);
result.ylo = round_and_clamp(y1 / CELL_SCALE, -CELL_LIMIT, CELL_LIMIT);
@@ -53,9 +53,9 @@ static int64_t cell_id(int64_t cellx, int64_t celly) {
}
// Get the cell ID of the specified point
static int64_t point_cell_id(double x, double y) {
double cellx = round_and_clamp(x / CELL_SCALE, -CELL_LIMIT, CELL_LIMIT);
double celly = round_and_clamp(y / CELL_SCALE, -CELL_LIMIT, CELL_LIMIT);
static int64_t point_cell_id(float x, float y) {
float cellx = round_and_clamp(x / CELL_SCALE, -CELL_LIMIT, CELL_LIMIT);
float celly = round_and_clamp(y / CELL_SCALE, -CELL_LIMIT, CELL_LIMIT);
return cell_id(int64_t(cellx), int64_t(celly));
}
@@ -85,7 +85,7 @@ void PlaneMap::insert(const std::string &plane, int64_t cellid, PlaneItem *clien
l.push_back(client);
}
void PlaneItem::set_pos(const std::string &plane, double x, double y, double z) {
void PlaneItem::set_pos(const std::string &plane, float x, float y, float z) {
int64_t old_cell = point_cell_id(x_, y_);
int64_t new_cell = point_cell_id(x, y);
@@ -160,7 +160,7 @@ int PlaneMap::total_cells() const {
return total;
}
PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, double x, double y, double radius, int64_t prepend) const {
PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, float x, float y, float radius, int64_t prepend) const {
PlaneMap::IdVector result;
if (prepend != 0) {
result.push_back(prepend);
@@ -169,7 +169,7 @@ PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, double x, dou
if (piter != planes_.end()) {
const Plane &p = piter->second;
CellRange range = rect_cell_range(x - radius, y - radius, x + radius, y + radius);
double radsq = radius*radius;
float radsq = radius*radius;
for (int cy = range.ylo; cy <= range.yhi; cy++) {
for (int cx = range.xlo; cx <= range.xhi; cx++) {
auto liter = p.find(cell_id(cx, cy));
@@ -189,8 +189,8 @@ PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, double x, dou
}
LuaDefine(unittests_planemap, "c") {
double SC = CELL_SCALE;
double E = CELL_SCALE * 0.4;
float SC = CELL_SCALE;
float E = CELL_SCALE * 0.4;
int LO = -CELL_LIMIT;
int HI = CELL_LIMIT;
PlaneMap pm;