/// <summary> /// Gets a specific point in this rectangle. /// </summary> /// <param name="index">Index of Point in rectangle.</param> /// <returns>Copy of the point.</returns> public FIntPoint this[int index] { get { switch (index) { case 0: return(Min); case 1: return(Max); default: throw new IndexOutOfRangeException("Invalid FIntRect index (" + index + ")"); } } set { switch (index) { case 0: Min = value; break; case 1: Max = value; break; default: throw new IndexOutOfRangeException("Invalid FIntRect index (" + index + ")"); } } }
/// <summary> /// Adds to this rectangle to include a given point. /// </summary> /// <param name="point">The point to increase the rectangle to.</param> public void Include(FIntPoint point) { Min.X = FMath.Min(Min.X, point.X); Min.Y = FMath.Min(Min.Y, point.Y); Max.X = FMath.Max(Max.X, point.X); Max.Y = FMath.Max(Max.Y, point.Y); }
/// <summary> /// Gets the Center and Extents of this rectangle. /// </summary> /// <param name="center">Will contain the center point.</param> /// <param name="extent">Will contain the extent.</param> public void GetCenterAndExtents(out FIntPoint center, out FIntPoint extent) { extent.X = (Max.X - Min.X) / 2; extent.Y = (Max.Y - Min.Y) / 2; center.X = Min.X + extent.X; center.Y = Min.Y + extent.Y; }
/// <summary> /// Divides a rectangle and rounds up to the nearest integer. /// </summary> /// <param name="lhs">The Rectangle to divide.</param> /// <param name="div">What to divide by.</param> /// <returns>New divided rectangle.</returns> public static FIntRect DivideAndRoundUp(FIntRect lhs, FIntPoint div) { return(new FIntRect(lhs.Min / div, FIntPoint.DivideAndRoundUp(lhs.Max, div))); }
/// <summary> /// Gets a new rectangle from the inner of this one. /// </summary> /// <param name="shrink">How much to remove from each point of this rectangle.</param> /// <returns>New inner Rectangle.</returns> public FIntRect Inner(FIntPoint shrink) { return(new FIntRect(Min + shrink, Max - shrink)); }
/// <summary> /// Test whether this rectangle contains a point. /// </summary> /// <param name="point">The point to test against.</param> /// <returns>true if the rectangle contains the specified point,, false otherwise..</returns> public bool Contains(FIntPoint point) { return(point.X >= Min.X && point.X < Max.X && point.Y >= Min.Y && point.Y < Max.Y); }
/// <summary> /// Subtracts a point from the given rectangle. /// </summary> /// <param name="rect">The rectangle.</param> /// <param name="point">The point to subtract from both points in the rectangle.</param> /// <param name="result">The result of the rectangle after subtraction.</param> public static void Subtract(ref FIntRect rect, ref FIntPoint point, out FIntRect result) { result.Min = rect.Min - point; result.Max = rect.Max - point; }
public FIntRect(FIntPoint min, FIntPoint max) { Min = min; Max = max; }
/// <summary> /// Subtracts a point from the given rectangle. /// </summary> /// <param name="rect">The rectangle.</param> /// <param name="point">The point to subtract from both points in the rectangle.</param> /// <returns>The result of the rectangle after subtraction.</returns> public static FIntRect Subtract(FIntRect rect, FIntPoint point) { Subtract(ref rect, ref point, out rect); return(rect); }
/// <summary> /// Adds a point to the given rectangle. /// </summary> /// <param name="rect">The rectangle.</param> /// <param name="point">The point to add onto both points in the rectangle.</param> /// <param name="result">The result of the rectangle after addition.</param> public static void Add(ref FIntRect rect, ref FIntPoint point, out FIntRect result) { result.Min = rect.Min + point; result.Max = rect.Max + point; }
/// <summary> /// Adds a point to the given rectangle. /// </summary> /// <param name="rect">The rectangle.</param> /// <param name="point">The point to add onto both points in the rectangle.</param> /// <returns>The result of the rectangle after addition.</returns> public static FIntRect Add(FIntRect rect, FIntPoint point) { Add(ref rect, ref point, out rect); return(rect); }
/// <summary> /// Performs a linear interpolation between two values, Alpha ranges from 0-1 /// </summary> public static FIntPoint LerpStable(FIntPoint a, FIntPoint b, float alpha) { return(new FIntPoint( (int)FMath.LerpStable(a.X, b.X, alpha), (int)FMath.LerpStable(a.Y, b.Y, alpha))); }
/// <summary> /// Constructs a vector from an FIntPoint. /// </summary> /// <param name="pos">Integer point used to set this vector.</param> public FVector2D(FIntPoint pos) { X = pos.X; Y = pos.Y; }