public static void Scale(Rectangle boundsBeforeResize, Positions gripperPosition, int cursorX, int cursorY, ref RectangleF boundsAfterResize, IDoubleProcessor angleRoundBehavior) { ScaleOptions opts = GetScaleOptions(); bool rationalScale = (opts & ScaleOptions.Rational) == ScaleOptions.Rational; bool centeredScale = (opts & ScaleOptions.Centered) == ScaleOptions.Centered; if (rationalScale) { double angle = GeometryHelper.Angle2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY); if (angleRoundBehavior != null) { angle = angleRoundBehavior.Process(angle); } int dist = GeometryHelper.Distance2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY); boundsAfterResize.Width = (int)Math.Round(dist * Math.Cos(angle / 180 * Math.PI)); boundsAfterResize.Height = (int)Math.Round(dist * Math.Sin(angle / 180 * Math.PI)); } if (centeredScale) { float wdiff = boundsAfterResize.Width - boundsBeforeResize.Width; float hdiff = boundsAfterResize.Height - boundsBeforeResize.Height; boundsAfterResize.Width += wdiff; boundsAfterResize.Height += hdiff; boundsAfterResize.X -= wdiff; boundsAfterResize.Y -= hdiff; } }
/// <summary> /// /// </summary> /// <param name="boundsBeforeResize"></param> /// <param name="gripperPosition"></param> /// <param name="cursorX"></param> /// <param name="cursorY"></param> /// <param name="boundsAfterResize"></param> /// <param name="angleRoundBehavior"></param> public static void Scale(Rectangle boundsBeforeResize, Positions gripperPosition, int cursorX, int cursorY, ref NativeRectFloat boundsAfterResize, IDoubleProcessor angleRoundBehavior) { var opts = GetScaleOptions(); var rationalScale = (opts & ScaleOptions.Rational) == ScaleOptions.Rational; var centeredScale = (opts & ScaleOptions.Centered) == ScaleOptions.Centered; if (rationalScale) { var angle = GeometryHelper.Angle2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY); if (angleRoundBehavior != null) { angle = angleRoundBehavior.Process(angle); } var dist = GeometryHelper.Distance2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY); boundsAfterResize = boundsAfterResize.Resize((float)Math.Round(dist * Math.Cos(angle / 180 * Math.PI)), (float)Math.Round(dist * Math.Sin(angle / 180 * Math.PI))); } if (centeredScale) { var wdiff = boundsAfterResize.Width - boundsBeforeResize.Width; var hdiff = boundsAfterResize.Height - boundsBeforeResize.Height; boundsAfterResize = boundsAfterResize.Offset(-wdiff, -hdiff).Resize(boundsAfterResize.Width + wdiff, boundsAfterResize.Height + hdiff); } }
public static void Scale(Rectangle boundsBeforeResize, int gripperPosition, int cursorX, int cursorY, ref RectangleF boundsAfterResize, IDoubleProcessor angleRoundBehavior) { ScaleHelper.ScaleOptions opts = ScaleHelper.GetScaleOptions(); bool rationalScale = (opts & ScaleHelper.ScaleOptions.Rational) == ScaleHelper.ScaleOptions.Rational; bool centeredScale = (opts & ScaleHelper.ScaleOptions.Centered) == ScaleHelper.ScaleOptions.Centered; if(rationalScale) { double angle = GeometryHelper.Angle2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY); if(angleRoundBehavior != null) { angle = angleRoundBehavior.Process(angle); } int dist = GeometryHelper.Distance2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY); boundsAfterResize.Width = (int)Math.Round(dist * Math.Cos(angle / 180 * Math.PI)); boundsAfterResize.Height = (int)Math.Round(dist * Math.Sin(angle / 180 * Math.PI)); } if(centeredScale) { float wdiff = boundsAfterResize.Width - boundsBeforeResize.Width; float hdiff = boundsAfterResize.Height - boundsBeforeResize.Height; boundsAfterResize.Width += wdiff; boundsAfterResize.Height += hdiff; boundsAfterResize.X -= wdiff; boundsAfterResize.Y -= hdiff; } }