worked on floorplan (v2)
worked on grid-generation (v2) new helper methods for geometry new test cases
This commit is contained in:
66
geo/Line2.h
66
geo/Line2.h
@@ -55,6 +55,35 @@ public:
|
||||
|
||||
bool getSegmentIntersection(const Line2& other) const {
|
||||
|
||||
const double delta = 0.0000001;
|
||||
|
||||
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 (std::abs(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+delta || t > 1-delta) {return false;}
|
||||
|
||||
const double u = (cx * by - cy * bx) / b_dot_d_perp;
|
||||
if(u < 0+delta || u > 1-delta) {return false;}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool getSegmentIntersection(const Line2& other, Point2& result) const {
|
||||
|
||||
const float delta = 0.000001;
|
||||
|
||||
const float bx = p2.x - p1.x;
|
||||
const float by = p2.y - p1.y;
|
||||
|
||||
@@ -63,49 +92,24 @@ public:
|
||||
|
||||
const float b_dot_d_perp = bx*dy - by*dx;
|
||||
|
||||
if (b_dot_d_perp == 0) {return false;}
|
||||
if(b_dot_d_perp == 0) {return false;}
|
||||
|
||||
const float cx = other.p1.x - p1.x;
|
||||
const float cy = other.p1.y - p1.y;
|
||||
|
||||
const float t = (cx * dy - cy * dx) / b_dot_d_perp;
|
||||
if(t < 0 || t > 1) {return false;}
|
||||
if(t < 0+delta || t > 1-delta) {return false;}
|
||||
|
||||
const float u = (cx * by - cy * bx) / b_dot_d_perp;
|
||||
if(u < 0 || u > 1) {return false;}
|
||||
if(u < 0+delta || u > 1-delta) {return false;}
|
||||
|
||||
result.x = p1.x + t * bx;
|
||||
result.y = p1.y + t * by;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user