static public bool lineseg_intersect_rectangle(LineSegf lineseg, Rectanglef rect) { if (point_in_rectangle(lineseg.vertex0, rect)) { return(true); } if (point_in_rectangle(lineseg.vertex1, rect)) { return(true); } if (lineseg_intersect_lineseg(lineseg, rect.side(0))) { return(true); } if (lineseg_intersect_lineseg(lineseg, rect.side(1))) { return(true); } if (lineseg_intersect_lineseg(lineseg, rect.side(2))) { return(true); } if (lineseg_intersect_lineseg(lineseg, rect.side(3))) { return(true); } return(false); }
static public bool rectangle_intersect_rectangle(Rectanglef rect1, Rectanglef rect2) { if (rectangle_in_rectangle(rect1, rect2)) { return(true); } if (rectangle_in_rectangle(rect2, rect1)) { return(true); } for (int i = 0; i < 4; i++) { if (lineseg_intersect_rectangle(rect1.side(i), rect2)) { return(true); } if (lineseg_intersect_rectangle(rect2.side(i), rect1)) { return(true); } } return(true); }