|
|
@@ -109,7 +109,29 @@ namespace math {
|
|
|
contains(lhs, rhs.center);
|
|
|
}
|
|
|
|
|
|
- bool intersects(dim2::quad const & lhs, dim2::quad const & rhs);
|
|
|
+ bool check_edges(dim2::line const & seg, dim2::triangle const & tri) {
|
|
|
+ return orient(seg, tri.a) == clockwise && orient(seg, tri.b) == clockwise &&
|
|
|
+ orient(seg, tri.c) == clockwise;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool intersects(dim2::triangle const & lhs, dim2::triangle const & rhs) {
|
|
|
+ if (check_edges({lhs.a, lhs.b}, rhs)) return false;
|
|
|
+ if (check_edges({lhs.b, lhs.c}, rhs)) return false;
|
|
|
+ if (check_edges({lhs.c, lhs.a}, rhs)) return false;
|
|
|
+ if (check_edges({rhs.a, rhs.b}, lhs)) return false;
|
|
|
+ if (check_edges({rhs.b, rhs.c}, lhs)) return false;
|
|
|
+ if (check_edges({rhs.c, rhs.a}, lhs)) return false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool intersects(dim2::quad const & lhs, dim2::quad const & rhs) {
|
|
|
+ dim2::triangle l1{lhs.ll, lhs.lr, lhs.ul};
|
|
|
+ dim2::triangle l2{lhs.ul, lhs.ur, lhs.ll};
|
|
|
+ dim2::triangle r1{rhs.ll, rhs.lr, rhs.ul};
|
|
|
+ dim2::triangle r2{rhs.ul, rhs.ur, rhs.ll};
|
|
|
+ return intersects(l1, r1) || intersects(l2, r2) || intersects(l1, r2) ||
|
|
|
+ intersects(l2, r1);
|
|
|
+ }
|
|
|
|
|
|
bool intersects(dim2::circle const & lhs, dim2::circle const & rhs) {
|
|
|
vec2 const delta = rhs.center - lhs.center;
|