GetBoundaries() public méthode

public GetBoundaries ( ) : RectangleF
Résultat System.Drawing.RectangleF
Exemple #1
0
        public DNA Initialize(Random rand, TaskState task)
        {
            var dna = new DNA {
                Shapes = new Shape[task.Shapes]
            };

            for (int s = 0; s < task.Shapes; s++)
            {
                var shape = new Shape {
                    Color  = Color.FromArgb(StartingAlpha, Color.R, Color.G, Color.B),
                    Points = new PointF[task.Vertices]
                };
                int maxRadius = (int)Math.Round(Math.Min(task.ImageWidth, task.ImageHeight) * MaxRadiusRatio);
                int radius    = rand.Next(MinRadius, maxRadius);
                var center    = new Point(rand.Next(radius - MaxOverlap, task.ImageWidth - radius + MaxOverlap),
                                          rand.Next(radius - MaxOverlap, task.ImageHeight - radius + MaxOverlap));
                for (int v = 0; v < task.Vertices; v++)
                {
                    double t = v * Math.PI * 2 * Revolutions / task.Vertices + Angle * Math.PI * 2 + Math.PI / task.Vertices;
                    shape.Points[v].X = (float)(center.X + Math.Cos(t) * radius);
                    shape.Points[v].Y = (float)(center.Y + Math.Sin(t) * radius);
                }
                if (shape.GetBoundaries().Width < 1 || shape.GetBoundaries().Height < 1)
                {
                    continue;
                }
                dna.Shapes[s] = shape;
            }
            return(dna);
        }
        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;

            double newWidthRatio  = rand.Next(3, maxWidth + 1) / rect.Width;
            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);
            }
        }
        static void MoveShape(Random rand, Shape shape, TaskState task)
        {
            RectangleF rect       = shape.GetBoundaries();
            int        maxOverlap = task.ProjectOptions.MaxOverlap;
            PointF     delta      = new PointF {
                X = rand.NextFloat(-rect.X - maxOverlap, task.ImageWidth - rect.Right + maxOverlap),
                Y = rand.NextFloat(-rect.Y - maxOverlap, task.ImageHeight - rect.Bottom + maxOverlap)
            };

            for (int i = 0; i < shape.Points.Length; i++)
            {
                shape.Points[i].X += delta.X;
                shape.Points[i].Y += delta.Y;
            }
        }
Exemple #4
0
        void RotateShape(Random rand, Shape shape)
        {
            RectangleF rect       = shape.GetBoundaries();
            PointF     rectCenter = new PointF {
                X = rect.X + rect.Width / 2,
                Y = rect.Y + rect.Height / 2
            };

            double rotation = rand.NextDouble() * Math.PI * 2 * (MaxPosDelta / 180);

            for (int i = 0; i < shape.Points.Length; i++)
            {
                float alignedX = shape.Points[i].X - rectCenter.X;
                float alignedY = shape.Points[i].Y - rectCenter.Y;
                shape.Points[i].X =
                    (float)(rectCenter.X + alignedX * Math.Cos(rotation) - alignedY * Math.Sin(rotation));
                shape.Points[i].Y =
                    (float)(rectCenter.Y + alignedX * Math.Sin(rotation) + alignedY * Math.Cos(rotation));
            }
        }
        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;

            double newWidthRatio = rand.Next( 3, maxWidth + 1 ) / rect.Width;
            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 );
            }
        }
        static void RotateShape( Random rand, Shape shape )
        {
            RectangleF rect = shape.GetBoundaries();
            PointF rectCenter = new PointF {
                X = rect.X + rect.Width / 2,
                Y = rect.Y + rect.Height / 2
            };

            double rotation = rand.NextDouble() * Math.PI * 2;

            for( int i = 0; i < shape.Points.Length; i++ ) {
                float alignedX = shape.Points[i].X - rectCenter.X;
                float alignedY = shape.Points[i].Y - rectCenter.Y;
                shape.Points[i].X =
                    (float)( rectCenter.X + alignedX * Math.Cos( rotation ) - alignedY * Math.Sin( rotation ) );
                shape.Points[i].Y =
                    (float)( rectCenter.Y + alignedX * Math.Sin( rotation ) + alignedY * Math.Cos( rotation ) );
            }
        }
 static void MoveShape( Random rand, Shape shape, TaskState task )
 {
     RectangleF rect = shape.GetBoundaries();
     int maxOverlap = task.ProjectOptions.MaxOverlap;
     PointF delta = new PointF {
         X = rand.NextFloat( -rect.X - maxOverlap, task.ImageWidth - rect.Right + maxOverlap ),
         Y = rand.NextFloat( -rect.Y - maxOverlap, task.ImageHeight - rect.Bottom + maxOverlap )
     };
     for( int i = 0; i < shape.Points.Length; i++ ) {
         shape.Points[i].X += delta.X;
         shape.Points[i].Y += delta.Y;
     }
 }
 public DNA Initialize(Random rand, TaskState task)
 {
     var dna = new DNA {
         Shapes = new Shape[task.Shapes]
     };
     for (int s = 0; s < task.Shapes; s++) {
         var shape = new Shape {
             Color = Color.FromArgb(StartingAlpha, Color.R, Color.G, Color.B),
             Points = new PointF[task.Vertices]
         };
         int maxRadius = (int)Math.Round(Math.Min(task.ImageWidth, task.ImageHeight)*MaxRadiusRatio);
         int radius = rand.Next(MinRadius, maxRadius);
         var center = new Point(rand.Next(radius - MaxOverlap, task.ImageWidth - radius + MaxOverlap),
                                rand.Next(radius - MaxOverlap, task.ImageHeight - radius + MaxOverlap));
         for (int v = 0; v < task.Vertices; v++) {
             double t = v*Math.PI*2*Revolutions/task.Vertices + Angle*Math.PI*2 + Math.PI/task.Vertices;
             shape.Points[v].X = (float)(center.X + Math.Cos(t)*radius);
             shape.Points[v].Y = (float)(center.Y + Math.Sin(t)*radius);
         }
         if (shape.GetBoundaries().Width < 1 || shape.GetBoundaries().Height < 1) {
             continue;
         }
         dna.Shapes[s] = shape;
     }
     return dna;
 }