refactored the new floorplan
new helper methods/operator toe geo classes
This commit is contained in:
@@ -70,6 +70,12 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
/** grow the bbox by the amount given for each dimension */
|
||||
void grow(const Point2& p) {
|
||||
p1 -= p; // decrease minimum
|
||||
p2 += p; // increase maximum
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // BBOX2_H
|
||||
|
||||
10
geo/BBox3.h
10
geo/BBox3.h
@@ -18,8 +18,12 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
/** empty ctor */
|
||||
BBox3() : p1(MAX,MAX,MAX), p2(MIN,MIN,MIN) {;}
|
||||
|
||||
/** ctor with min and max */
|
||||
BBox3(const Point3 min, const Point3 max) : p1(min), p2(max) {;}
|
||||
|
||||
/** adjust the bounding-box by adding this point */
|
||||
void add(const Point3& p) {
|
||||
|
||||
@@ -71,6 +75,12 @@ public:
|
||||
p2 += p; // increase maximum
|
||||
}
|
||||
|
||||
/** set both, min/max z to the same value */
|
||||
void setZ(const float z) {
|
||||
p1.z = z;
|
||||
p2.z = z;
|
||||
}
|
||||
|
||||
/** does the bbox contain the given point? */
|
||||
bool contains(const Point3& p) const {
|
||||
if (p.x < p1.x) {return false;}
|
||||
|
||||
57
geo/Line2.h
57
geo/Line2.h
@@ -14,8 +14,13 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
/** empty ctor */
|
||||
Line2() : p1(), p2() {;}
|
||||
|
||||
/** value ctor */
|
||||
Line2(const Point2 p1, const Point2 p2) : p1(p1), p2(p2) {;}
|
||||
|
||||
/** value ctor */
|
||||
Line2(const float x1, const float y1, const float x2, const float y2) : p1(x1,y1), p2(x2,y2) {;}
|
||||
|
||||
// bool getSegmentIntersection(const Line& other) const {
|
||||
@@ -24,6 +29,30 @@ public:
|
||||
// }
|
||||
|
||||
|
||||
/** get intersection between these two lines (unlimited length!) */
|
||||
bool getLineIntersection(const Line2& other, Point2& result) const {
|
||||
|
||||
double bx = p2.x - p1.x;
|
||||
double by = p2.y - p1.y;
|
||||
|
||||
double dx = other.p2.x - other.p1.x;
|
||||
double dy = other.p2.y - other.p1.y;
|
||||
|
||||
double b_dot_d_perp = bx*dy - by*dx;
|
||||
|
||||
if(b_dot_d_perp == 0) {return false;}
|
||||
|
||||
double cx = other.p1.x - p1.x;
|
||||
double cy = other.p1.y - p1.y;
|
||||
double t = (cx*dy - cy*dx) / b_dot_d_perp;
|
||||
|
||||
result.x = p1.x + t * bx;
|
||||
result.y = p1.y + t * by;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool getSegmentIntersection(const Line2& other) const {
|
||||
|
||||
const float bx = p2.x - p1.x;
|
||||
@@ -49,6 +78,34 @@ public:
|
||||
|
||||
}
|
||||
|
||||
bool getSegmentIntersection(const Line2& other, Point2& result) const {
|
||||
|
||||
const double bx = p2.x - p1.x;
|
||||
const double by = p2.y - p1.y;
|
||||
|
||||
const double dx = other.p2.x - other.p1.x;
|
||||
const double dy = other.p2.y - other.p1.y;
|
||||
|
||||
const double b_dot_d_perp = bx*dy - by*dx;
|
||||
|
||||
if(b_dot_d_perp == 0) {return false;}
|
||||
|
||||
const double cx = other.p1.x - p1.x;
|
||||
const double cy = other.p1.y - p1.y;
|
||||
|
||||
const double t = (cx * dy - cy * dx) / b_dot_d_perp;
|
||||
if(t < 0 || t > 1) {return false;}
|
||||
|
||||
const double u = (cx * by - cy * bx) / b_dot_d_perp;
|
||||
if(u < 0 || u > 1) {return false;}
|
||||
|
||||
result.x = p1.x + t * bx;
|
||||
result.y = p1.y + t * by;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // LINE2D_H
|
||||
|
||||
@@ -38,6 +38,10 @@ struct Point2 {
|
||||
|
||||
bool operator == (const Point2& o) const {return x==o.x && y==o.y;}
|
||||
|
||||
bool operator != (const Point2& o) const {return x!=o.x || y!=o.y;}
|
||||
|
||||
|
||||
Point2 perpendicular() const {return Point2(-y, x);}
|
||||
|
||||
/** get the distance between this point and the other one */
|
||||
float getDistance(const Point2& o) const {
|
||||
|
||||
@@ -46,6 +46,8 @@ struct Point3 {
|
||||
|
||||
bool operator == (const Point3& o) const {return x==o.x && y==o.y && z==o.z;}
|
||||
|
||||
bool operator != (const Point3& o) const {return x!=o.x || y!=o.y || z!=o.z;}
|
||||
|
||||
Point2 xy() const {return Point2(x,y);}
|
||||
|
||||
/** read-only array access */
|
||||
|
||||
Reference in New Issue
Block a user