#ifndef GRIDNODEBBOX_H #define GRIDNODEBBOX_H #include "GridPoint.h" #include "../geo/Line2D.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; /** 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); } }; #endif // GRIDNODEBBOX_H