/// <summary>
        /// Changes rectangle scale by a minimum amount in term of area change to match the scale of the user-specified size scale.
        /// </summary>
        /// <param name="rect">Rectangle.</param>
        /// <param name="widthHeightRatio">Width / height ratio that must be satisfied.</param>
        /// <param name="correctLocation">Moves rectangle to minimize the impact of scaling regarding original location.</param>
        /// <returns>Rectangle that has the same scale as </returns>
        public static RectangleF ScaleTo(this RectangleF rect, float widthHeightRatio, bool correctLocation = true)
        {
            var sizeScale = widthHeightRatio;

            var newWidthCandidate = rect.Height * sizeScale;
            var newHeightCandidate = rect.Width * (1 / sizeScale);

            //if we choose newWidth...
            var newWidthAreaChangeFactor = rect.Area() / (newWidthCandidate * rect.Height);
            newWidthAreaChangeFactor = newWidthAreaChangeFactor - 1; //for how much the area will change (+/- X percent)

            //if we choose newHeight...
            var newHeightAreaChangeFactor = rect.Area() / (newHeightCandidate * rect.Width);
            newHeightAreaChangeFactor = newHeightAreaChangeFactor - 1; //for how much the area will change (+/- X percent)

            if (System.Math.Abs(newWidthAreaChangeFactor) < System.Math.Abs(newHeightAreaChangeFactor))
            {
                var xOffset = 0f;

                if (correctLocation)
                    xOffset = -(newWidthCandidate - rect.Width) / 2;

                return new RectangleF(rect.X + xOffset, rect.Y, newWidthCandidate, rect.Height);
            }
            else
            {
                var yOffset = 0f;

                if (correctLocation)
                    yOffset = -(newHeightCandidate - rect.Height) / 2;

                return new RectangleF(rect.X, rect.Y + yOffset, rect.Width, newHeightCandidate);
            }
        }
Exemplo n.º 2
0
 public static bool IsCurrentArea(this HttpRequestBase request, string area)
 {
     return request.Area() == area.ToLower();
 }
 public static bool IsDegenerated(this Rect rectangle)
 {
     return rectangle.Area() == 0;
 }
Exemplo n.º 4
0
        public static string ToSourceString(this RouteData routeData)
        {
            if (routeData == null)
            {
                return "(null)";
            }

            string source = routeData.Controller() + " -> " + routeData.Action();
            if (!string.IsNullOrEmpty(routeData.Area()))
            {
                source = routeData.Area() + " Area -> " + source;
            }
            return source;
        }