started adding floorplan LINT
new helper methods
This commit is contained in:
79
floorplan/v2/FloorplanLINT.h
Normal file
79
floorplan/v2/FloorplanLINT.h
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#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
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Floorplan.h"
|
#include "Floorplan.h"
|
||||||
|
#include "FloorplanLINT.h"
|
||||||
|
|
||||||
#include "../../misc/Debug.h"
|
#include "../../misc/Debug.h"
|
||||||
#include "../../Assertions.h"
|
#include "../../Assertions.h"
|
||||||
@@ -40,6 +41,7 @@ namespace Floorplan {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
IndoorMap* map = parse(doc);
|
IndoorMap* map = parse(doc);
|
||||||
|
Floorplan::LINT::check(map);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +59,7 @@ namespace Floorplan {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
IndoorMap* map = parse(doc);
|
IndoorMap* map = parse(doc);
|
||||||
|
Floorplan::LINT::check(map);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,9 +434,6 @@ namespace Floorplan {
|
|||||||
poly.points.push_back(p2);
|
poly.points.push_back(p2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (poly.points.size() < 4 || poly.points.size() > 1024) {
|
|
||||||
throw Exception("detected invalid outline-polygon during XML parsing");
|
|
||||||
}
|
|
||||||
return poly;
|
return poly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** returns true if the bbox is not yet configured */
|
/** returns true if the bbox is not yet configured */
|
||||||
const bool isInvalid() const {
|
bool isInvalid() const {
|
||||||
return p1.x == MAX || p1.y == MAX || p2.x == MIN || p2.y == MIN;
|
return p1.x == MAX || p1.y == MAX || p2.x == MIN || p2.y == MIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +47,9 @@ public:
|
|||||||
/** get the bbox's maximum */
|
/** get the bbox's maximum */
|
||||||
const Point2& getMax() const {return p2;}
|
const Point2& getMax() const {return p2;}
|
||||||
|
|
||||||
|
/** get the bbox's size [max-min] */
|
||||||
|
const Point2 getSize() const {return p2-p1;}
|
||||||
|
|
||||||
/** get the bbox's center point */
|
/** get the bbox's center point */
|
||||||
Point2 getCenter() const { return (p1+p2) / 2; }
|
Point2 getCenter() const { return (p1+p2) / 2; }
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ struct Point2 {
|
|||||||
return std::sqrt(dx*dx + dy*dy);
|
return std::sqrt(dx*dx + dy*dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string asString() const {
|
||||||
|
return "(" + std::to_string(x) + "," + std::to_string(y) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void swap(Point2& p1, Point2& p2) {
|
inline void swap(Point2& p1, Point2& p2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user