Refractor and cleanup binding logic
This commit is contained in:
+6
-10
@@ -6,6 +6,8 @@
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
struct Color {
|
||||
uint8_t r, g, b = 0, a = 255;
|
||||
};
|
||||
@@ -77,18 +79,13 @@ struct Line {
|
||||
Line(Vec2<float> start, Vec2<float> end) : start(start), end(end) {}
|
||||
|
||||
bool intersects(const Line &other) const {
|
||||
float denom = (other.end.y - other.start.y) * (end.x - start.x) -
|
||||
(other.end.x - other.start.x) * (end.y - start.y);
|
||||
float denom = (other.end.y - other.start.y) * (end.x - start.x) - (other.end.x - other.start.x) * (end.y - start.y);
|
||||
|
||||
if (std::abs(denom) < 1e-6f) // Lines are parallel (or very close to it)
|
||||
return false;
|
||||
|
||||
float ua = ((other.end.x - other.start.x) * (start.y - other.start.y) -
|
||||
(other.end.y - other.start.y) * (start.x - other.start.x)) /
|
||||
denom;
|
||||
float ub = ((end.x - start.x) * (start.y - other.start.y) -
|
||||
(end.y - start.y) * (start.x - other.start.x)) /
|
||||
denom;
|
||||
float ua = ((other.end.x - other.start.x) * (start.y - other.start.y) - (other.end.y - other.start.y) * (start.x - other.start.x)) / denom;
|
||||
float ub = ((end.x - start.x) * (start.y - other.start.y) - (end.y - start.y) * (start.x - other.start.x)) / denom;
|
||||
|
||||
return ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1;
|
||||
}
|
||||
@@ -113,8 +110,7 @@ struct Rect {
|
||||
}
|
||||
|
||||
bool contains(const Vec2<float> &point) const {
|
||||
return point.x >= diagonal.start.x && point.x <= diagonal.end.x &&
|
||||
point.y >= diagonal.start.y && point.y <= diagonal.end.y;
|
||||
return point.x >= diagonal.start.x && point.x <= diagonal.end.x && point.y >= diagonal.start.y && point.y <= diagonal.end.y;
|
||||
}
|
||||
|
||||
bool intersects(const Rect &other) const {
|
||||
|
||||
Reference in New Issue
Block a user