many changes :P

This commit is contained in:
k-a-z-u
2016-01-21 20:01:20 +01:00
parent a7dc0cabbb
commit 12084fe147
29 changed files with 2900 additions and 144 deletions

View File

@@ -2,43 +2,21 @@
#define GRIDNODEBBOX_H
#include "GridPoint.h"
#include "../geo/Line2D.h"
#include "../geo/BBox2.h"
/**
* describes the 2D (one floor)
* bounding-box for one node on the grid
*/
struct GridNodeBBox {
/** smaller half */
float x1_cm, y1_cm;
/** larger half */
float x2_cm, y2_cm;
struct GridNodeBBox : public BBox2 {
/** ctor */
GridNodeBBox(const GridPoint& center, const int gridSize_cm) {
x1_cm = center.x_cm - gridSize_cm/2; // smaller half
y1_cm = center.y_cm - gridSize_cm/2;
x2_cm = center.x_cm + gridSize_cm/2; // larger half
y2_cm = center.y_cm + gridSize_cm/2;
}
/** equal? */
bool operator == (const GridNodeBBox& o) const {
return (x1_cm == o.x1_cm) && (y1_cm == o.y1_cm) && (x2_cm == o.x2_cm) && (y2_cm == o.y2_cm);
}
/** does the BBox intersect with the given line? */
bool intersects (const Line2D& l) const {
Line2D l1(x1_cm, y1_cm, x2_cm, y1_cm); // upper
Line2D l2(x1_cm, y2_cm, x2_cm, y2_cm); // lower
Line2D l3(x1_cm, y1_cm, x1_cm, y2_cm); // left
Line2D l4(x2_cm, y1_cm, x2_cm, y2_cm); // right
return l.getSegmentIntersection(l1) ||
l.getSegmentIntersection(l2) ||
l.getSegmentIntersection(l3) ||
l.getSegmentIntersection(l4);
p1.x = center.x_cm - gridSize_cm/2; // smaller half
p1.y = center.y_cm - gridSize_cm/2;
p2.x = center.x_cm + gridSize_cm/2; // larger half
p2.y = center.y_cm + gridSize_cm/2;
}
};