/// <summary> /// Gets whether or not the other <see cref="FloatRect"/> intersects with this FloatRect. /// </summary> /// <param name="value">The other FloatRect for testing.</param> /// <param name="result"><c>true</c> if other <see cref="FloatRect"/> intersects with this FloatRect; <c>false</c> otherwise. As an output parameter.</param> public void Intersects(ref FloatRect value, out bool result) { result = value.Left < Right && Left < value.Right && value.Top < Bottom && Top < value.Bottom; }
/// <summary> /// Gets whether or not the provided <see cref="FloatRect"/> lies within the bounds of this <see cref="FloatRect"/>. /// </summary> /// <param name="value">The <see cref="FloatRect"/> to check for inclusion in this <see cref="FloatRect"/>.</param> /// <param name="result"><c>true</c> if the provided <see cref="FloatRect"/>'s bounds lie entirely inside this <see cref="FloatRect"/>; <c>false</c> otherwise. As an output parameter.</param> public void Contains(ref FloatRect value, out bool result) { result = ((((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height))); }
/// <summary> /// Gets whether or not the other <see cref="FloatRect"/> intersects with this FloatRect. /// </summary> /// <param name="value">The other FloatRect for testing.</param> /// <returns><c>true</c> if other <see cref="FloatRect"/> intersects with this FloatRect; <c>false</c> otherwise.</returns> public bool Intersects(FloatRect value) { return value.Left < Right && Left < value.Right && value.Top < Bottom && Top < value.Bottom; }
/// <summary> /// Gets whether or not the provided <see cref="FloatRect"/> lies within the bounds of this <see cref="FloatRect"/>. /// </summary> /// <param name="value">The <see cref="FloatRect"/> to check for inclusion in this <see cref="FloatRect"/>.</param> /// <returns><c>true</c> if the provided <see cref="FloatRect"/>'s bounds lie entirely inside this <see cref="FloatRect"/>; <c>false</c> otherwise.</returns> public bool Contains(FloatRect value) { return ((((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height))); }
/// <summary> /// Creates a new <see cref="FloatRect"/> that completely contains two other FloatRects. /// </summary> /// <param name="value1">The first <see cref="FloatRect"/>.</param> /// <param name="value2">The second <see cref="FloatRect"/>.</param> /// <param name="result">The union of the two FloatRects as an output parameter.</param> public static void Union(ref FloatRect value1, ref FloatRect value2, out FloatRect result) { result.X = Math.Min(value1.X, value2.X); result.Y = Math.Min(value1.Y, value2.Y); result.Width = Math.Max(value1.Right, value2.Right) - result.X; result.Height = Math.Max(value1.Bottom, value2.Bottom) - result.Y; }
/// <summary> /// Creates a new <see cref="FloatRect"/> that completely contains two other FloatRects. /// </summary> /// <param name="value1">The first <see cref="FloatRect"/>.</param> /// <param name="value2">The second <see cref="FloatRect"/>.</param> /// <returns>The union of the two FloatRects.</returns> public static FloatRect Union(FloatRect value1, FloatRect value2) { float x = Math.Min(value1.X, value2.X); float y = Math.Min(value1.Y, value2.Y); return new FloatRect(x, y, Math.Max(value1.Right, value2.Right) - x, Math.Max(value1.Bottom, value2.Bottom) - y); }
/// <summary> /// Creates a new <see cref="FloatRect"/> that contains overlapping region of two other FloatRects. /// </summary> /// <param name="value1">The first <see cref="FloatRect"/>.</param> /// <param name="value2">The second <see cref="FloatRect"/>.</param> /// <param name="result">Overlapping region of the two FloatRects as an output parameter.</param> public static void Intersect(ref FloatRect value1, ref FloatRect value2, out FloatRect result) { if (value1.Intersects(value2)) { float right_side = Math.Min(value1.X + value1.Width, value2.X + value2.Width); float left_side = Math.Max(value1.X, value2.X); float top_side = Math.Max(value1.Y, value2.Y); float bottom_side = Math.Min(value1.Y + value1.Height, value2.Y + value2.Height); result = new FloatRect(left_side, top_side, right_side - left_side, bottom_side - top_side); } else { result = new FloatRect(0, 0, 0, 0); } }
/// <summary> /// Creates a new <see cref="FloatRect"/> that contains overlapping region of two other FloatRects. /// </summary> /// <param name="value1">The first <see cref="FloatRect"/>.</param> /// <param name="value2">The second <see cref="FloatRect"/>.</param> /// <returns>Overlapping region of the two FloatRects.</returns> public static FloatRect Intersect(FloatRect value1, FloatRect value2) { FloatRect FloatRect; Intersect(ref value1, ref value2, out FloatRect); return FloatRect; }