示例#1
0
 public void SetPoints(ScenePoint p1, ScenePoint p2, ScenePoint p3, ScenePoint p4)
 {
     _points[0] = p1;
     _points[1] = p2;
     _points[2] = p3;
     _points[3] = p4;
 }
示例#2
0
 public void Draw(ScenePoint origin, Graphics drawing)
 {
     foreach (var figure in _childFigures)
     {
         figure.Draw(origin, drawing);
     }
 }
示例#3
0
 public void Move(ScenePoint vector)
 {
     foreach (var figure in _childFigures)
     {
         figure.Move(vector);
     }
 }
示例#4
0
        public void Draw(ScenePoint origin, Graphics drawing)
        {
            using (var pen = new Pen(Color.Blue))
            {
                drawing.DrawLine(
                    pen,
                    (float)(_p1.X - origin.X),
                    (float)(_p1.Y - origin.Y),
                    (float)(_p2.X - origin.X),
                    (float)(_p2.Y - origin.Y));

                drawing.DrawLine(
                    pen,
                    (float)(_p2.X - origin.X),
                    (float)(_p2.Y - origin.Y),
                    (float)(_p3.X - origin.X),
                    (float)(_p3.Y - origin.Y));

                drawing.DrawLine(
                    pen,
                    (float)(_p3.X - origin.X),
                    (float)(_p3.Y - origin.Y),
                    (float)(_p4.X - origin.X),
                    (float)(_p4.Y - origin.Y));

                drawing.DrawLine(
                    pen,
                    (float)(_p4.X - origin.X),
                    (float)(_p4.Y - origin.Y),
                    (float)(_p1.X - origin.X),
                    (float)(_p1.Y - origin.Y));
            }
        }
 public static void Move(ScenePoint vector, ref ScenePoint[] points)
 {
     for (var i = 0; i < points.Length; i++)
     {
         points[i].X += vector.X;
         points[i].Y += vector.Y;
     }
 }
示例#6
0
 //Ñopy constructor
 public RectangleFigure(ScenePoint p1, ScenePoint p2, ScenePoint p3, ScenePoint p4)
 {
     _p1 = p1;
     _p2 = p2;
     _p3 = p3;
     _p4 = p4;
     SetPoints(_p1, _p2, _p3, _p4);
 }
        public object Clone()
        {
            var center = new ScenePoint {
                X = _center.X, Y = _center.Y
            };
            var clone = new CircleFigure(center, _radius);

            return(clone);
        }
 public void Draw(ScenePoint origin, Graphics drawing)
 {
     using (var pen = new Pen(Color.Green))
     {
         drawing.DrawEllipse(
             pen,
             (int)(_center.X - _radius - origin.X),
             (int)(_center.Y - _radius - origin.Y),
             (int)(_radius * 2),
             (int)(_radius * 2));
     }
 }
示例#9
0
 public RectangleFigure(ScenePoint p1, ScenePoint p2)
 {
     _p1 = p1;
     _p2 = new ScenePoint {
         X = p2.X, Y = p1.Y
     };
     _p3 = p2;
     _p4 = new ScenePoint {
         X = p1.X, Y = p2.Y
     };
     SetPoints(_p1, _p2, _p3, _p4);
 }
        public static void RotateFigure(double angle, ScenePoint centerFigure, ref ScenePoint[] points)
        {
            var rad = (Math.PI / 180) * angle;

            for (var i = 0; i < points.Length; i++)
            {
                var X = points[i].X;
                var Y = points[i].Y;

                points[i].X = centerFigure.X + (X - centerFigure.X) * Math.Cos(rad) - (Y - centerFigure.Y) * Math.Sin(rad);
                points[i].Y = centerFigure.Y + (X - centerFigure.X) * Math.Sin(rad) + (Y - centerFigure.Y) * Math.Cos(rad);
            }
        }
        public void AppendLine(string line)
        {
            var match = RecognizeRegex.Match(line);

            if (match.Success)
            {
                line  = match.ToString();
                _name = Regex.Match(line, name).ToString().Trim();
                line  = line.Remove(0, _name.Length).Trim();

                var coordinate = new double[2, 2];
                var i          = 0;

                foreach (var coordinateMatch in Regex.Matches(line, point))
                {
                    var j = 0;

                    foreach (var valueCoordinate in Regex.Matches(coordinateMatch.ToString(), @"-?\d{1,}"))
                    {
                        if (valueCoordinate.ToString().Length > 1 && valueCoordinate.ToString()[0] == '0')
                        {
                            throw new BadFormatException();
                        }

                        coordinate[i, j] = double.Parse(valueCoordinate.ToString());
                        j++;
                    }

                    i++;
                }

                var p1 = new ScenePoint {
                    X = coordinate[0, 0], Y = coordinate[0, 1]
                };
                var p2 = new ScenePoint {
                    X = coordinate[1, 0], Y = coordinate[1, 1]
                };

                if (Math.Abs(p1.X - p2.X) < Eps || Math.Abs(p1.Y - p2.Y) < Eps)
                {
                    throw new BadRectanglePoint();
                }

                _rectangle = new RectangleFigure(p1, p2);
            }
            else
            {
                throw new BadFormatException();
            }
        }
示例#12
0
        public void Reflect(ReflectOrientation orientation)
        {
            SceneRectangle circumscribingRectangle = CalculateCircumscribingRectangle();
            var            pointSceneCenter        = new ScenePoint
            {
                X = (circumscribingRectangle.Vertex1.X + circumscribingRectangle.Vertex2.X) / 2.0,
                Y = (circumscribingRectangle.Vertex1.Y + circumscribingRectangle.Vertex2.Y) / 2.0
            };

            foreach (var figure in _childFigures)
            {
                var points = figure.Points;
                GeneralMethodsFigure.ReflectFigure(orientation, pointSceneCenter, ref points);
                figure.Points = points;
            }
        }
        public object Clone()
        {
            var points = new ScenePoint[_points.Length];
            var i      = 0;

            foreach (var point in _points)
            {
                points[i] = new ScenePoint {
                    X = point.X, Y = point.Y
                };
                i++;
            }

            var clone = new PolygonFigure(points);

            return(clone);
        }
示例#14
0
        public void AppendLine(string line)
        {
            var match = RecognizeRegex.Match(line);

            if (match.Success)
            {
                line  = match.ToString();
                _name = Regex.Match(line, name).ToString().Trim();
                line  = line.Remove(0, _name.Length).Trim();

                var coordinateMatch = Regex.Match(line, point);
                var coordinate      = new double[2];
                var i = 0;

                foreach (var valueCoordinate in Regex.Matches(coordinateMatch.ToString(), @"-?\d{1,}"))
                {
                    if (valueCoordinate.ToString().Length > 1 && valueCoordinate.ToString()[0] == '0')
                    {
                        throw new BadFormatException();
                    }

                    coordinate[i] = double.Parse(valueCoordinate.ToString());
                    i++;
                }

                line = line.Remove(0, coordinateMatch.ToString().Length);

                var radius = double.Parse(Regex.Match(line, @"-?\d{1,}").ToString());

                if (radius <= 0)
                {
                    throw new BadCircleRadius();
                }

                var p = new ScenePoint {
                    X = coordinate[0], Y = coordinate[1]
                };

                _circle = new CircleFigure(p, radius);
            }
            else
            {
                throw new BadFormatException();
            }
        }
示例#15
0
        /* Return new Rectangle with the same points as the current one. */
        public object Clone()
        {
            var p1 = new ScenePoint {
                X = _p1.X, Y = _p1.Y
            };
            var p2 = new ScenePoint {
                X = _p2.X, Y = _p2.Y
            };
            var p3 = new ScenePoint {
                X = _p3.X, Y = _p3.Y
            };
            var p4 = new ScenePoint {
                X = _p4.X, Y = _p4.Y
            };
            var clone = new RectangleFigure(p1, p2, p3, p4);

            return(clone);
        }
        public static void ReflectFigure(ReflectOrientation orientation, ScenePoint centerFigure, ref ScenePoint[] points)
        {
            if (orientation == ReflectOrientation.Vertical)
            {
                for (var i = 0; i < points.Length; i++)
                {
                    points[i].X += (centerFigure.X - points[i].X) * 2;
                }
            }

            if (orientation == ReflectOrientation.Horizontal)
            {
                for (var i = 0; i < points.Length; i++)
                {
                    points[i].Y += (centerFigure.Y - points[i].Y) * 2;
                }
            }
        }
示例#17
0
        private static bool IsSegmentsIntersect(ScenePoint a, ScenePoint b, ScenePoint c, ScenePoint d)
        {
            if (Math.Abs(b.X - c.X) < Eps && Math.Abs(b.Y - c.Y) < Eps)
            {
                var k1 = (b.X - a.X) / (b.Y - a.Y);
                var k2 = (d.X - c.X) / (d.Y - c.Y);

                if (k1 != k2)
                {
                    return(false);
                }
            }

            return(Intersect(a.X, b.X, c.X, d.X) &&
                   Intersect(a.Y, b.Y, c.Y, d.Y) &&
                   OrientedAreaTriangle(a, b, c) * OrientedAreaTriangle(a, b, d) <= Eps &&
                   OrientedAreaTriangle(c, d, a) * OrientedAreaTriangle(c, d, b) <= Eps);
        }
        public void Draw(ScenePoint origin, Graphics drawing)
        {
            using (var pen = new Pen(Color.DarkOrchid))
            {
                for (var i = 0; i < _points.Length; i++)
                {
                    ScenePoint firstPoint  = _points[i];
                    ScenePoint secondPoint = i >= _points.Length - 1 ? _points.First() : _points[i + 1];

                    drawing.DrawLine(
                        pen,
                        (float)(firstPoint.X - origin.X),
                        (float)(firstPoint.Y - origin.Y),
                        (float)(secondPoint.X - origin.X),
                        (float)(secondPoint.Y - origin.Y));
                }
            }
        }
示例#19
0
        private bool EqualScenePoints(ScenePoint scenePoint1, ScenePoint scenePoint2)
        {
            double Eps = 1e-10;

            return((Math.Abs(scenePoint1.X - scenePoint2.X) < Eps && Math.Abs(scenePoint1.Y - scenePoint2.Y) < Eps) ? true : false);
        }
 public void Move(ScenePoint vector)
 {
     GeneralMethodsFigure.Move(vector, ref _points);
     _center = _points[0];
 }
 public CircleFigure(ScenePoint center, double radius)
 {
     _center    = center;
     _radius    = radius;
     _points[0] = _center;
 }
示例#22
0
 public MoveCommand(string name, ScenePoint vector)
 {
     _name   = name;
     _vector = vector;
 }
示例#23
0
 /* Move all the points of current rectangle. */
 public void Move(ScenePoint vector)
 {
     GeneralMethodsFigure.Move(vector, ref _points);
     SetP(_points);
 }
示例#24
0
        public void AppendLine(string line)
        {
            var matchStart      = RecognizeRegexStart.Match(line);
            var matchCoordinate = RecognizeRegexCoordinate.Match(line);
            var matchEnd        = RecognizeRegexEnd.Match(line);

            if (matchStart.Success)
            {
                line  = line.Remove(matchStart.Index, matchStart.Length);
                _name = line.Trim();
            }
            else if (matchCoordinate.Success)
            {
                var coordinate = new double[2];
                var i          = 0;

                foreach (var valueCoordinate in Regex.Matches(matchCoordinate.ToString(), @"-?\d{1,}"))
                {
                    if (valueCoordinate.ToString().Length > 1 && valueCoordinate.ToString()[0] == '0')
                    {
                        throw new BadFormatException();
                    }

                    coordinate[i] = double.Parse(valueCoordinate.ToString());
                    i++;
                }

                var coord = new ScenePoint {
                    X = coordinate[0], Y = coordinate[1]
                };

                //Check for a match with a point in the polygon
                for (var j = 0; j < _coordinatePolygon.Count; j++)
                {
                    if (Math.Abs(_coordinatePolygon[j].X - coord.X) < Eps && Math.Abs(_coordinatePolygon[j].Y - coord.Y) < Eps)
                    {
                        throw new BadPolygonPoint();
                    }
                }

                //Self-healing check
                if (_coordinatePolygon.Count >= 2)
                {
                    for (var j = 0; j < _coordinatePolygon.Count - 1; j++)
                    {
                        if (IsSegmentsIntersect(_coordinatePolygon[j], _coordinatePolygon[j + 1],
                                                _coordinatePolygon[_coordinatePolygon.Count - 1], coord))
                        {
                            throw new BadPolygonPoint();
                        }
                    }
                }

                _coordinatePolygon.Add(coord);
            }
            else if (matchEnd.Success)
            {
                if (_coordinatePolygon.Count < 3)
                {
                    throw new BadPolygonPointNumber();
                }

                var coordinates = new ScenePoint[_coordinatePolygon.Count];

                for (var i = 0; i < coordinates.Length; i++)
                {
                    coordinates[i] = _coordinatePolygon[i];
                }

                _endPoligon = true;
                _polygon    = new PolygonFigure(coordinates);
            }
            else
            {
                throw new BadFormatException();
            }
        }
示例#25
0
 private static double OrientedAreaTriangle(ScenePoint a, ScenePoint b, ScenePoint c)
 {
     return(((b.X - a.X) * (c.Y - a.Y)) - ((b.Y - a.Y) * (c.X - a.X)));
 }