// Tests if two edges defined by their endpoints (a,b) and (c,d) intersect. Returns true and the // point of intersection if they do and false otherwise. static bool edgeEdgeTest(const FloatPoint& a, const FloatPoint& b, const FloatPoint& c, const FloatPoint& d, FloatPoint& r) { FloatSize u = b - a; FloatSize v = d - c; FloatSize w = a - c; float denom = perpProduct(u, v); // If denom == 0 then the edges are parallel. While they could be overlapping // we don't bother to check here as the we'll find their intersections from the // corner to quad tests. if (!denom) return false; float s = perpProduct(v, w) / denom; if (s < 0 || s > 1) return false; float t = perpProduct(u, w) / denom; if (t < 0 || t > 1) return false; u.scale(s); r = a + u; return true; }
// Tests if two edges defined by their endpoints (a,b) and (c,d) intersect. Returns true and the // point of intersection if they do and false otherwise. static bool edgeEdgeTest(const FloatPoint& a, const FloatPoint& b, const FloatPoint& c, const FloatPoint& d, FloatPoint& r) { FloatSize u = b - a; FloatSize v = d - c; FloatSize w = a - c; float denom = perpProduct(u, v); // If denom == 0 then the edges are parallel. if (!denom) { // If the edges are not colinear then there's no intersection. if (perpProduct(u, w) || perpProduct(v, w)) return false; if (pointInColinearEdge(a, c, d)) { r = a; return true; } if (pointInColinearEdge(b, c, d)) { r = b; return true; } if (pointInColinearEdge(c, a, b)) { r = c; return true; } if (pointInColinearEdge(d, a, b)) { r = d; return true; } return false; } float s = perpProduct(v, w) / denom; if (s < 0 || s > 1) return false; float t = perpProduct(u, w) / denom; if (t < 0 || t > 1) return false; u.scale(s); r = a + u; return true; }