new helper methods
adjusted wall intersection
This commit is contained in:
12
geo/Line2.h
12
geo/Line2.h
@@ -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 {
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user