new helper methods

adjusted wall intersection
This commit is contained in:
2018-07-22 17:32:44 +02:00
parent 8ea7b7f3b6
commit 083a1c2cf2
5 changed files with 132 additions and 111 deletions

View File

@@ -45,6 +45,18 @@ public:
return p1.getDistance(p2);
}
/** keep the starting point, but make the line longer by the given length */
Line2 longerAtEnd(const float l) {
Point2 dir = p2-p1;
return Line2(p1, p1+dir+dir.normalized()*l);
}
/** keep the ending point, but make the line longer by the given length */
Line2 longerAtStart(const float l) {
Point2 dir = p1-p2;
return Line2(p2, p2+dir+dir.normalized()*l);
}
/** get intersection between these two lines (unlimited length!) */
bool getLineIntersection(const Line2& other, Point2& result) const {

View File

@@ -44,6 +44,7 @@ struct Point2 {
bool operator != (const Point2& o) const {return x!=o.x || y!=o.y;}
bool eq (const Point2& o, const float delta) const { return eq(x,o.x,delta) && eq(y,o.y,delta); }
Point2 perpendicular() const {return Point2(-y, x);}
@@ -66,6 +67,11 @@ struct Point2 {
return "(" + std::to_string(x) + "," + std::to_string(y) + ")";
}
private:
static inline bool eq(const float a, const float b, const float delta) {return std::abs(a-b) <= delta;}
static inline bool ne(const float a, const float b, const float delta) {return std::abs(a-b) > delta;}
};
inline float dot(const Point2 p1, const Point2 p2) {