A rectangle represented by a Width and a Height
예제 #1
0
 /// <summary>
 /// Can this rectangle hold the subject rectangle
 /// </summary>
 /// <param name="subject">The rectangle to compare to</param>
 /// <returns></returns>
 public bool CanHold(Rectangle subject)
     => Width >= subject.Width && Height >= subject.Height;
예제 #2
0
 /// <summary>
 /// Resizes this rectangle to fit inside a target rectangle
 /// </summary>
 /// <param name="target">The target rectangle</param>
 /// <returns>A new rectangle that fits within the target rectangle</returns>
 public Rectangle EnsureFit(Rectangle target)
     => target.CanHold(this) ? new Rectangle(Width, Height) : Match(target);
예제 #3
0
 /// <summary>
 /// Resizes the rectangle to match the target rectangle on the shortest side
 /// </summary>
 /// <param name="target">The target rectangle</param>
 /// <returns>A new rectangle that matches the shortest side of the target rectangle.</returns>
 public Rectangle Match(Rectangle target)
 {
     var ratio = Ratio(target);
     return Resize(ratio);
 }
예제 #4
0
 /// <summary>
 /// The ratio between this rectangle and a target rectangle
 /// </summary>
 /// <param name="target">The rectangle to compare to</param>
 /// <returns></returns>
 public double Ratio(Rectangle target)
 {
     var heightRatio = Convert.ToDouble(target.Height) / Height;
     var widthRatio = Convert.ToDouble(target.Width) / Width;
     return heightRatio <= widthRatio ? heightRatio : widthRatio;
 }