public static double GetScalingFactor(this Artivity.DataModel.Rectangle r, RectangleF target) { double w = target.Width / r.Width; double h = target.Height / r.Height; return(w >= h ? h : w); }
public static RectangleF ToRectangle(this Artivity.DataModel.Rectangle r) { RectangleF rectangle = new RectangleF(); rectangle.Location = r.Position.ToPoint(); rectangle.Width = Convert.ToSingle(r.Width); rectangle.Height = Convert.ToSingle(r.Height); return(rectangle); }
public static RectangleF Fit(this Artivity.DataModel.Rectangle r, RectangleF target) { double s = r.GetScalingFactor(target); RectangleF result = new RectangleF(); result.Width = Convert.ToSingle(Math.Round(r.Width * s, 0)); result.Height = Convert.ToSingle(Math.Round(r.Height * s, 0)); return(result); }