AerialForWindowsTester.AspectRatioLayoutDecorator.SizeToRatio C# (CSharp) Method

SizeToRatio() public method

public SizeToRatio ( Size size, bool expand ) : Size
size System.Windows.Size
expand bool
return System.Windows.Size
        public Size SizeToRatio(Size size, bool expand)
        {
            double ratio = AspectRatio;

            double height = size.Width/ratio;
            double width = size.Height*ratio;

            if (expand) {
                width = Math.Max(width, size.Width);
                height = Math.Max(height, size.Height);
            } else {
                width = Math.Min(width, size.Width);
                height = Math.Min(height, size.Height);
            }

            return new Size(width, height);
        }