Esempio n. 1
0
        /// <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 NativeRectFloat Resize(this NativeRectFloat rect, float?width = null, float?height = null)
 {
     return(rect.Resize(new NativeSizeFloat(width ?? rect.Width, height ?? rect.Height)));
 }