SuperImageEvolver.SoftTranslateMutator.ScaleShape C# (CSharp) Méthode

ScaleShape() public méthode

public ScaleShape ( Random rand, Shape shape, TaskState task ) : void
rand System.Random
shape Shape
task TaskState
Résultat void
        void ScaleShape( Random rand, Shape shape, TaskState task )
        {
            RectangleF rect = shape.GetBoundaries();
            int maxOverlap = task.ProjectOptions.MaxOverlap;

            int maxWidth = (int)( Math.Min( rect.X, task.ImageWidth - rect.Right ) + rect.Width ) + maxOverlap * 2;
            int maxHeight = (int)( Math.Min( rect.Y, task.ImageHeight - rect.Bottom ) + rect.Height ) + maxOverlap * 2;

            int minWidthRatio = (int)Math.Max( 3, rect.Width - maxOverlap );
            int maxWidthRatio = (int)Math.Min( rect.Width + maxOverlap, maxWidth + 1 );
            double newWidthRatio =
                rand.Next( Math.Min( minWidthRatio, maxWidthRatio ), Math.Max( minWidthRatio, maxWidthRatio ) ) /
                rect.Width;

            int minHeightRatio = (int)Math.Max( 3, rect.Height - maxOverlap );
            int maxHeightRatio = (int)Math.Min( rect.Height + maxOverlap, maxHeight + 1 );
            double newHeightRatio =
                rand.Next( Math.Min( minHeightRatio, maxHeightRatio ), Math.Max( minHeightRatio, maxHeightRatio ) ) /
                rect.Height;
            //double newHeightRatio = rand.Next( 3, maxHeight + 1 ) / rect.Height;

            if( PreserveAspectRatio ) {
                newWidthRatio = Math.Min( newWidthRatio, newHeightRatio );
                newHeightRatio = newWidthRatio;
            }

            PointF rectCenter = new PointF {
                X = rect.X + rect.Width / 2f,
                Y = rect.Y + rect.Height / 2f
            };

            for( int i = 0; i < shape.Points.Length; i++ ) {
                shape.Points[i].X = (float)( rectCenter.X + ( shape.Points[i].X - rectCenter.X ) * newWidthRatio );
                shape.Points[i].Y = (float)( rectCenter.Y + ( shape.Points[i].Y - rectCenter.Y ) * newHeightRatio );
            }
        }