80 lines
2.2 KiB
C++
80 lines
2.2 KiB
C++
#ifndef FLOORPLANLINT_H
|
|
#define FLOORPLANLINT_H
|
|
|
|
#include "Floorplan.h"
|
|
#include "../../geo/BBox2.h"
|
|
|
|
namespace Floorplan {
|
|
|
|
class LINT {
|
|
|
|
public:
|
|
|
|
static void check(IndoorMap* map) {
|
|
|
|
for (const Floor* floor : map->floors) {
|
|
|
|
// outline present?
|
|
if (floor->outline.empty()) {throw Exception("floor " + floor->name + " has no outline");}
|
|
|
|
// check outline
|
|
for (FloorOutlinePolygon* poly : floor->outline) {
|
|
checkOutline(floor, poly);
|
|
}
|
|
|
|
// check obstacles
|
|
for (FloorObstacle* obs : floor->obstacles) {
|
|
checkObstacle(floor, obs);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
/** check a floor's outline */
|
|
static void checkOutline(const Floor* floor, const FloorOutlinePolygon* poly) {
|
|
|
|
// number of points valid?
|
|
if (poly->poly.points.size() < 3) {throw Exception("floor '" + floor->name + "' outline '" + poly->name + "' needs at least 3 edges");}
|
|
if (poly->poly.points.size() > 1024) {throw Exception("floor '" + floor->name + "' outline '" + poly->name + "' has too many edges");}
|
|
|
|
// outline size [bbox] valid?
|
|
BBox2 outline;
|
|
for (const Point2 pt : poly->poly.points) { outline.add(pt); }
|
|
const Point2 size = outline.getSize();
|
|
if (size.x < 1.0 || size.y < 1.0) {throw Exception("floor '" + floor->name + "' outline '" + poly->name + "' seems too small");}
|
|
|
|
}
|
|
|
|
/** check walls, doors, ... */
|
|
static void checkObstacle(const Floor* floor, const FloorObstacle* fo) {
|
|
|
|
// line? -> check
|
|
const FloorObstacleLine* line = dynamic_cast<const FloorObstacleLine*>(fo);
|
|
if (line) {
|
|
const float len_m = line->from.getDistance(line->to);
|
|
if (len_m < 0.15) {
|
|
throw Exception("floor '" + floor->name + "' line-obstacle is too short: " + std::to_string(len_m) + " meter from " + line->from.asString() + " to " + line->to.asString());
|
|
}
|
|
}
|
|
|
|
// door? -> check
|
|
const FloorObstacleDoor* door = dynamic_cast<const FloorObstacleDoor*>(fo);
|
|
if (door) {
|
|
const float len_m = door->from.getDistance(door->to);
|
|
if (len_m < 0.40) {
|
|
throw Exception("floor '" + floor->name + "' door is too narrow: " + std::to_string(len_m) + " meter from " + door->from.asString() + " to " + door->to.asString());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
#endif // FLOORPLANLINT_H
|