World model is now operational

This commit is contained in:
2021-01-16 01:24:33 -05:00
parent d7d633bd96
commit 313e78067a
11 changed files with 313 additions and 188 deletions

View File

@@ -74,8 +74,10 @@
#define PLANEMAP_HPP
#include <cstdint>
#include <cstddef>
#include <vector>
#include <map>
#include "util.hpp"
class PlaneMap;
@@ -85,20 +87,38 @@ class PlaneItem {
private:
PlaneMap *pmap_;
std::string plane_;
double x_, y_, z_;
util::XYZ xyz_;
public:
PlaneItem();
~PlaneItem();
const std::string &plane() const { return plane_; }
const double x() const { return x_; }
const double y() const { return y_; }
const double z() const { return z_; }
const util::XYZ &xyz() const { return xyz_; }
const float x() const { return xyz_.x; }
const float y() const { return xyz_.y; }
const float z() const { return xyz_.z; }
void untrack();
void set_pos(const std::string &plane, double x, double y, double z);
void set_xyz(double x, double y, double z) { set_pos(plane_, x, y, z); }
void set_pos(const std::string &plane, const util::XYZ &xyz);
void set_pos(const std::string &plane, float x, float y, float z) { set_pos(plane, util::XYZ(x,y,z)); }
void set_xyz(const util::XYZ &xyz) { set_pos(plane_, xyz); }
void set_xyz(float x, float y, float z) { set_pos(plane_, util::XYZ(x, y, z)); }
// Assume that some other object has methods 'get_plane' and 'get_xyz'.
// Get the plane and XYZ from that object and store it in this PlaneItem.
template<class T>
void set_pos_from(const T &obj) {
set_pos(obj.get_plane(), obj.get_xyz());
}
// Assume that the PlaneItem is a field in an object of class T.
// Static cast the PlaneItem pointer to a type T pointer.
template<class T>
T *static_field_cast() {
const std::size_t offset = offsetof(T, plane_item_);
return reinterpret_cast<T*>(reinterpret_cast<char*>(this) - offset);
}
};
class PlaneMap {
@@ -114,7 +134,7 @@ public:
PlaneMap();
~PlaneMap();
void track(PlaneItem *item);
EltVec scan_radius(const std::string &plane, double x, double y, double radius) const;
EltVec scan_radius(const std::string &plane, float x, float y, float radius) const;
private:
// unit testing stuff.