/// <summary> /// Grow bounds to include specified bounds. /// </summary> /// <param name="bounds">Bounds</param> public void Encapsulate(Bounds2i bounds) { if (Min.x > bounds.Min.x) { Min.x = bounds.Min.x; } if (Min.y > bounds.Min.y) { Min.y = bounds.Min.y; } if (Max.x < bounds.Max.x) { Max.x = bounds.Max.x; } if (Max.y < bounds.Max.y) { Max.y = bounds.Max.y; } }
/// <summary> /// Are specified bounds instersects. Optimized version. /// </summary> /// <param name="lhs">First bounds</param> /// <param name="rhs">Second bounds</param> public static bool Intersects(ref Bounds2i lhs, ref Bounds2i rhs) { return(lhs.Min.x <= rhs.Max.x && lhs.Max.x >= rhs.Min.x && lhs.Min.y <= rhs.Max.y && lhs.Max.y >= rhs.Min.y); }
/// <summary> /// Is specified bounds intersects with current one. /// </summary> /// <param name="bounds">Bounds</param> public bool Intersects(Bounds2i bounds) { return(Min.x <= bounds.Max.x && Max.x >= bounds.Min.x && Min.y <= bounds.Max.y && Max.y >= bounds.Min.y); }