/// <summary> /// Is this segment is inside or intersects the given bounding box? /// </summary> /// <param name="r">The bounding box.</param> /// <returns>Returns true if this segment is inside or intersects the given bounding box.</returns> public bool Intersects(Box2d r) { var b = a + ab; if (r.Contains(a) || r.Contains(b)) { return(true); } var t = new Box2d(a, b); if (t.xmin > r.xmax || t.xmax < r.xmin || t.ymin > r.ymax || t.ymax < r.ymin) { return(false); } var p0 = Vector2d.Cross(ab, new Vector2d(r.xmin, r.ymin) - a); var p1 = Vector2d.Cross(ab, new Vector2d(r.xmax, r.ymin) - a); if (p1 * p0 <= 0.0) { return(true); } var p2 = Vector2d.Cross(ab, new Vector2d(r.xmin, r.ymax) - a); if (p2 * p0 <= 0.0) { return(true); } var p3 = Vector2d.Cross(ab, new Vector2d(r.xmax, r.ymax) - a); if (p3 * p0 <= 0.0) { return(true); } return(false); }
/// <summary> /// Is the bounding box intersects the given box? /// </summary> /// <param name="bb">The bounding box.</param> /// <returns>Returns true if this bounding box intersects the given bounding box.</returns> public bool Intersects(Box2d bb) { return(bb.xmax >= xmin && bb.xmin <= xmax && bb.ymax >= ymin && bb.ymin <= ymax); }
/// <summary> /// Is the bounding box contains the giveen bounding box? /// </summary> /// <param name="bb">The bounding box.</param> /// <returns>Returns true if this bounding box contains the given bounding box.</returns> public bool Contains(Box2d bb) { return(bb.xmin >= xmin && bb.xmax <= xmax && bb.ymin >= ymin && bb.ymax <= ymax); }
/// <summary> /// Enlarge the bounding box. /// </summary> /// <param name="bb">The bounding box.</param> /// <returns>Returns the bounding box containing this box and the given box.</returns> public Box2d Enlarge(Box2d bb) { return(new Box2d(Math.Min(xmin, bb.xmin), Math.Max(xmax, bb.xmax), Math.Min(ymin, bb.ymin), Math.Max(ymax, bb.ymax))); }