Beispiel #1
0
        /* Reflect all the figures and groups in the scene.*/
        public void ReflectScene(ReflectOrientation reflectOrientation)
        {
            SceneRectangle sceneRectangle   = CalculateSceneCircumscribingRectangle();
            var            pointSceneCenter = new ScenePoint
            {
                X = (sceneRectangle.Vertex1.X + sceneRectangle.Vertex2.X) / 2.0,
                Y = (sceneRectangle.Vertex1.Y + sceneRectangle.Vertex2.Y) / 2.0
            };

            foreach (var figure in _figures)
            {
                var points = figure.Value.Points;
                GeneralMethodsFigure.ReflectFigure(reflectOrientation, pointSceneCenter, ref points);
                figure.Value.Points = points;
            }


            foreach (var composite in _compositeFigures)
            {
                foreach (var compositeFigures in composite.Value.ChildFigures)
                {
                    var points = compositeFigures.Points;
                    GeneralMethodsFigure.ReflectFigure(reflectOrientation, pointSceneCenter, ref points);
                    compositeFigures.Points = points;
                }
            }
        }
Beispiel #2
0
        /* Calculate the rectangle that wraps figure or group 'name'*/
        public SceneRectangle CalculateCircumscribingRectangle(string name)
        {
            IFigure          figure;
            ICompositeFigure compositeFigure;

            if (_figures.TryGetValue(name, out figure))
            {
                var point1 = new ScenePoint
                {
                    X = figure.CalculateCircumscribingRectangle().Vertex1.X,
                    Y = figure.CalculateCircumscribingRectangle().Vertex1.Y,
                };

                var point2 = new ScenePoint
                {
                    X = figure.CalculateCircumscribingRectangle().Vertex2.X,
                    Y = figure.CalculateCircumscribingRectangle().Vertex2.Y,
                };

                var ñircumscribingRectangle = new SceneRectangle
                {
                    Vertex1 = point1,
                    Vertex2 = point2
                };

                return(ñircumscribingRectangle);
            }
            else if (_compositeFigures.TryGetValue(name, out compositeFigure))
            {
                var point1 = new ScenePoint
                {
                    X = compositeFigure.CalculateCircumscribingRectangle().Vertex1.X,
                    Y = compositeFigure.CalculateCircumscribingRectangle().Vertex1.Y,
                };

                var point2 = new ScenePoint
                {
                    X = compositeFigure.CalculateCircumscribingRectangle().Vertex2.X,
                    Y = compositeFigure.CalculateCircumscribingRectangle().Vertex2.Y,
                };

                var ñircumscribingRectangle = new SceneRectangle
                {
                    Vertex1 = point1,
                    Vertex2 = point2
                };

                return(ñircumscribingRectangle);
            }
            else
            {
                throw new BadName();
            }
        }
Beispiel #3
0
        /* Move figure or group 'name' by 'vector'*/
        public void Move(string name, ScenePoint vector)
        {
            IFigure          figure;
            ICompositeFigure compositeFigure;

            if (_figures.TryGetValue(name, out figure))
            {
                figure.Move(vector);
            }
            else if (_compositeFigures.TryGetValue(name, out compositeFigure))
            {
                compositeFigure.Move(vector);
            }
            else
            {
                throw new BadName();
            }
        }
Beispiel #4
0
        /* Move all the figures and groups in the scene by 'vector'.*/
        public void MoveScene(ScenePoint vector)
        {
            foreach (var figure in _figures)
            {
                var points = figure.Value.Points;
                GeneralMethodsFigure.Move(vector, ref points);
                figure.Value.Points = points;
            }

            foreach (var composite in _compositeFigures)
            {
                foreach (var compositeFigures in composite.Value.ChildFigures)
                {
                    var points = compositeFigures.Points;
                    GeneralMethodsFigure.Move(vector, ref points);
                    compositeFigures.Points = points;
                }
            }
        }
Beispiel #5
0
        private static void DrawScene(Scene scene)
        {
            const string outputFileName = "scene.png";

            if (File.Exists(outputFileName))
            {
                File.Delete(outputFileName);
            }

            var area = scene.CalculateSceneCircumscribingRectangle();

            var origin = new ScenePoint
            {
                X = Math.Min(area.Vertex1.X, area.Vertex2.X),
                Y = Math.Min(area.Vertex1.Y, area.Vertex2.Y),
            };

            var width  = (int)Math.Abs(area.Vertex1.X - area.Vertex2.X) + 1;
            var height = (int)Math.Abs(area.Vertex1.Y - area.Vertex2.Y) + 1;

            using (Stream output = File.Create(outputFileName))
                using (Image image = new Bitmap(width, height))
                    using (Graphics drawing = Graphics.FromImage(image))
                    {
                        using (var bg = new SolidBrush(Color.DarkGray))
                        {
                            drawing.FillRectangle(bg, 0, 0, width, height);
                        }

                        drawing.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // Smoothing
                        drawing.InterpolationMode = InterpolationMode.HighQualityBilinear;            // Specifies high-quality bilinear interpolation.

                        foreach (var figure in scene.ListDrawableFigures())
                        {
                            figure.Draw(origin, drawing);
                        }

                        image.Save(output, ImageFormat.Png);
                    }

            Console.WriteLine("The scene has been saved to " + outputFileName);
        }