worked on floorplan (v2)
worked on grid-generation (v2) new helper methods for geometry new test cases
This commit is contained in:
29
geo/BBox2.h
29
geo/BBox2.h
@@ -42,6 +42,10 @@ public:
|
||||
/** get the bbox's maximum */
|
||||
const Point2& getMax() const {return p2;}
|
||||
|
||||
/** get the bbox's center point */
|
||||
Point2 getCenter() const { return (p1+p2) / 2; }
|
||||
|
||||
|
||||
/** equal? */
|
||||
bool operator == (const BBox2& o) const {
|
||||
return (p1.x == o.p1.x) &&
|
||||
@@ -52,16 +56,27 @@ public:
|
||||
|
||||
/** does the BBox intersect with the given line? */
|
||||
bool intersects (const Line2& l) const {
|
||||
Line2 l1(p1.x, p1.y, p2.x, p1.y); // upper
|
||||
Line2 l2(p1.x, p2.y, p2.x, p2.y); // lower
|
||||
Line2 l3(p1.x, p1.y, p1.x, p2.y); // left
|
||||
Line2 l4(p2.x, p1.y, p2.x, p2.y); // right
|
||||
const Line2 l1(p1.x, p1.y, p2.x, p1.y); // upper
|
||||
const Line2 l2(p1.x, p2.y, p2.x, p2.y); // lower
|
||||
const Line2 l3(p1.x, p1.y, p1.x, p2.y); // left
|
||||
const Line2 l4(p2.x, p1.y, p2.x, p2.y); // right
|
||||
return l.getSegmentIntersection(l1) ||
|
||||
l.getSegmentIntersection(l2) ||
|
||||
l.getSegmentIntersection(l3) ||
|
||||
l.getSegmentIntersection(l4);
|
||||
}
|
||||
|
||||
std::vector<Line2> lines() const {
|
||||
return std::vector<Line2>(
|
||||
{
|
||||
Line2(p1.x, p1.y, p2.x, p1.y),
|
||||
Line2(p1.x, p2.y, p2.x, p2.y),
|
||||
Line2(p1.x, p1.y, p1.x, p2.y),
|
||||
Line2(p2.x, p1.y, p2.x, p2.y)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool contains(const Point2& p) const {
|
||||
if (p.x < p1.x) {return false;}
|
||||
if (p.x > p2.x) {return false;}
|
||||
@@ -76,6 +91,12 @@ public:
|
||||
p2 += p; // increase maximum
|
||||
}
|
||||
|
||||
/** grow the bbox by the amount given for each dimension */
|
||||
void grow(const float val) {
|
||||
p1 -= Point2(val, val); // decrease minimum
|
||||
p2 += Point2(val, val); // increase maximum
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // BBOX2_H
|
||||
|
||||
Reference in New Issue
Block a user