示例#1
0
        // Add a chain-like figure using TransformedFigure and CompositeFigure.
        private void CreateChain()
        {
            var ellipse = new EllipseFigure
            {
                IsFilled = false,
                RadiusX  = 1f,
                RadiusY  = 1f,
            };

            var compositeFigure = new CompositeFigure();

            for (int i = 0; i < 9; i++)
            {
                var transformedEllipse = new TransformedFigure(ellipse)
                {
                    Scale = new Vector3F(0.4f, 0.2f, 1),
                    Pose  = new Pose(new Vector3F(-2 + i * 0.5f, 0, 0), Matrix33F.CreateRotationX(ConstantsF.PiOver2 * (i % 2)))
                };
                compositeFigure.Children.Add(transformedEllipse);
            }

            _scene.Children.Add(new FigureNode(compositeFigure)
            {
                Name            = "Chain",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(0.1f),
                StrokeAlpha     = 1,
                PoseLocal       = new Pose(new Vector3F(0, 3, 0)),
            });
        }
示例#2
0
        public void CheckHit(Point dot, List <Point> Points, int Width, List <Point> Expected)
        {
            EllipseFigure ellipse = new EllipseFigure(Color.Black, Width);
            List <Point>  Actual  = ellipse.CheckHit(dot);

            Assert.AreEqual(Expected, Actual);
        }
示例#3
0
        private void ScaleEllipse(EllipseFigure ef, Point pos)
        {
            if (_nowScaling == null)
            {
                _originalW = ef.Radius1.CachedValue.AsDouble;
                _originalH = ef.Radius2.CachedValue.AsDouble;
                var snappedTo = StepManager.SnapTo(pos, ef.GetMagnets(), ef.Center);
                if ((snappedTo == ef.Left) && (Math.Abs(_originalW) > Utils.Tolerance))
                {
                    _nowScaling = new ScaleEllipseStep(ef, ScaleEllipseStep.Side.Right,
                                                       1 - (pos.X - _downPos.X) / _originalW);
                }
                else if ((snappedTo == ef.Right) && (Math.Abs(_originalW) > Utils.Tolerance))
                {
                    _nowScaling = new ScaleEllipseStep(ef, ScaleEllipseStep.Side.Left,
                                                       1 + (pos.X - _downPos.X) / _originalW);
                }
                else if ((snappedTo == ef.Top) && (Math.Abs(_originalH) > Utils.Tolerance))
                {
                    _nowScaling = new ScaleEllipseStep(ef, ScaleEllipseStep.Side.Bottom,
                                                       1 - (pos.Y - _downPos.Y) / _originalH);
                }
                else if ((snappedTo == ef.Bottom) && (Math.Abs(_originalH) > Utils.Tolerance))
                {
                    _nowScaling = new ScaleEllipseStep(ef, ScaleEllipseStep.Side.Top,
                                                       1 + (pos.Y - _downPos.Y) / _originalH);
                }
                if (_nowScaling == null)
                {
                    return;
                }
                StepManager.InsertNext(_nowScaling);
            }
            else
            {
                var srs = (ScaleEllipseStep)_nowScaling;

                if (srs.ScaleAround == ScaleEllipseStep.Side.Right)
                {
                    srs.Scale(1 - (pos.X - _downPos.X) / _originalW);
                }
                else if (srs.ScaleAround == ScaleEllipseStep.Side.Left)
                {
                    srs.Scale(1 + (pos.X - _downPos.X) / _originalW);
                }
                else if (srs.ScaleAround == ScaleEllipseStep.Side.Top)
                {
                    srs.Scale(1 + (pos.Y - _downPos.Y) / _originalH);
                }
                else if (srs.ScaleAround == ScaleEllipseStep.Side.Bottom)
                {
                    srs.Scale(1 - (pos.Y - _downPos.Y) / _originalH);
                }
            }
        }
示例#4
0
        public void GetPointsTest(Point p1, Point p2, List <Point> expected)
        {
            Canvas canvas = Canvas.CreateCanvas();

            canvas.prevPoint = p1;
            canvas.curPoint  = p2;

            EllipseFigure ellipseFigure = new EllipseFigure();
            List <Point>  actual        = ellipseFigure.Calculate();

            Assert.AreEqual(expected, actual);
        }
示例#5
0
        //private Workspace _workspace;

        public DataInitialization(int Width, int Height)
        {
            var unityContainerInit = new UnityContainer();

            _action = unityContainerInit.Resolve <Actions>();

            _selectClass = unityContainerInit.Resolve <Selection>();

            _pointSelection = unityContainerInit.Resolve <PointSelection>();

            _rectangleSelection = unityContainerInit.Resolve <RectangleSelection>();

            _drawClass = unityContainerInit.Resolve <DrawOnCanvas>(new OrderedParametersOverride(new object[] { Width, Height, _action }));

            _editDate = unityContainerInit.Resolve <EditData>(new OrderedParametersOverride(new object[] { _drawClass, _action }));

            _rectangl        = unityContainerInit.Resolve <RectangleFigure>();
            _ellipse         = unityContainerInit.Resolve <EllipseFigure>();
            _line            = unityContainerInit.Resolve <Line>();
            _poliLine        = unityContainerInit.Resolve <PolylineFigure>();
            _polygon         = unityContainerInit.Resolve <PolygonFigure>();
            _rectangleSelect = unityContainerInit.Resolve <RectangleSelect>();

            _listFigures.Add(_rectangl);
            _listFigures.Add(_ellipse);
            _listFigures.Add(_line);
            _listFigures.Add(_poliLine);
            _listFigures.Add(_polygon);

            _drawListFigures.Add(_rectangl);
            _drawListFigures.Add(_ellipse);
            _drawListFigures.Add(_line);
            _drawListFigures.Add(_poliLine);
            _drawListFigures.Add(_polygon);
            _drawListFigures.Add(_rectangleSelect);

            _selectionList.Add(_pointSelection);
            _selectionList.Add(_rectangleSelection);

            _modesList.Add(unityContainerInit.Resolve <DrawMode>(new OrderedParametersOverride(new object[] { _listFigures, _selectClass, _drawClass })));
            _modesList.Add(unityContainerInit.Resolve <SelectRegionMode>(new OrderedParametersOverride(new object[] { _listFigures, _selectClass, _drawClass, _editDate, _selectionList })));
            _modesList.Add(unityContainerInit.Resolve <SelectPointoMode>(new OrderedParametersOverride(new object[] { _listFigures, _selectClass, _drawClass, _editDate, _selectionList })));

            _workspace = new Workspace(_selectClass, _drawClass, _editDate, _listFigures, _modesList, _drawListFigures);
        }
        public override void CopyStaticFigure()
        {
            if ((Iterations == -1) || Figure.IsGuide)
            {
                return;
            }

            var rf = new EllipseFigure
            {
                X           = new ScalarExpression("a", "a", EllipseFigure.X.CachedValue.Str),
                Y           = new ScalarExpression("a", "a", EllipseFigure.Y.CachedValue.Str),
                Radius1     = new ScalarExpression("a", "a", EllipseFigure.Radius1.CachedValue.Str),
                Radius2     = new ScalarExpression("a", "a", EllipseFigure.Radius2.CachedValue.Str),
                FigureColor = EllipseFigure.FigureColor.Copy()
            };

            Figure.StaticLoopFigures.Add(rf);
            StepManager.Figures.Add(rf);
        }
 private ResizeEllipseStep(EllipseFigure figure, Side resizeAround)
 {
     Figure        = figure;
     EllipseFigure = figure;
     ResizeAround  = resizeAround;
 }
 public ResizeEllipseStep(EllipseFigure figure, Side resizeAround, double delta)
     : this(figure, resizeAround, delta.Str())
 {
 }
示例#9
0
 private void MoveEllipse(EllipseFigure ef, Point pos)
 {
     if (_nowMoving == null)
     {
         _nowMoving = new MoveEllipseStep(ef, pos.X - _downPos.X, pos.Y - _downPos.Y);
         StepManager.InsertNext(_nowMoving);
     }
     else
     {
         var    snapped = StepManager.Snap(pos, _nowMoving.Figure);
         Magnet snappedBy;
         if ((snapped != null) &&
             ((snappedBy = StepManager.SnapTo(pos, _nowMoving.Figure.GetMagnets())) != null))
         {
             if (snappedBy.EqualExprStrings(ef.Left))
             {
                 ((MoveEllipseStep)_nowMoving).Move(
                     "((" + snapped.X.ExprString + ") + (" + ef.Name + ".radius1)) - (" +
                     _nowMoving.Figure.Name +
                     ".x)",
                     "(" + snapped.Y.ExprString + ") - (" + _nowMoving.Figure.Name + ".y)",
                     snappedBy.Def, snapped.Def);
             }
             else if (snappedBy.EqualExprStrings(ef.Right))
             {
                 ((MoveEllipseStep)_nowMoving).Move(
                     "((" + snapped.X.ExprString + ") - (" + ef.Name + ".radius1)) - (" +
                     _nowMoving.Figure.Name +
                     ".x)",
                     "(" + snapped.Y.ExprString + ") - (" + _nowMoving.Figure.Name + ".y)",
                     snappedBy.Def, snapped.Def);
             }
             else if (snappedBy.EqualExprStrings(ef.Top))
             {
                 ((MoveEllipseStep)_nowMoving).Move(
                     "(" + snapped.X.ExprString + ") - (" + _nowMoving.Figure.Name + ".x)",
                     "((" + snapped.Y.ExprString + ") + (" + ef.Name + ".radius2)) - (" +
                     _nowMoving.Figure.Name +
                     ".y)", snappedBy.Def, snapped.Def);
             }
             else if (snappedBy.EqualExprStrings(ef.Bottom))
             {
                 ((MoveEllipseStep)_nowMoving).Move(
                     "(" + snapped.X.ExprString + ") - (" + _nowMoving.Figure.Name + ".x)",
                     "((" + snapped.Y.ExprString + ") - (" + ef.Name + ".radius2)) - (" +
                     _nowMoving.Figure.Name +
                     ".y)", snappedBy.Def, snapped.Def);
             }
             else if (snappedBy.EqualExprStrings(ef.Center))
             {
                 ((MoveEllipseStep)_nowMoving).Move(
                     "(" + snapped.X.ExprString + ") - (" + _nowMoving.Figure.Name + ".x)",
                     "(" + snapped.Y.ExprString + ") - (" + _nowMoving.Figure.Name + ".y)", snappedBy.Def,
                     snapped.Def);
             }
         }
         else
         {
             ((MoveEllipseStep)_nowMoving).Move(pos.X - _downPos.X, pos.Y - _downPos.Y);
         }
     }
 }
示例#10
0
 public ScaleEllipseStep(EllipseFigure figure, Side scaleAround, double factor)
     : this(figure, scaleAround, factor.Str())
 {
 }
示例#11
0
 public ScaleEllipseStep(EllipseFigure figure, Side scaleAround, string factor) : this(figure, scaleAround)
 {
     Scale(factor);
 }
示例#12
0
 private ScaleEllipseStep(EllipseFigure figure, Side scaleAround)
 {
     Figure        = figure;
     EllipseFigure = figure;
     ScaleAround   = scaleAround;
 }
示例#13
0
        // Add some ellipses.
        private void CreateEllipses()
        {
            Figure figure = new EllipseFigure
            {
                IsFilled = false,
                RadiusX  = 0.5f,
                RadiusY  = 0.25f,
            };
            FigureNode figureNode = new FigureNode(figure)
            {
                Name            = "Ellipse #1",
                StrokeThickness = 1,
                StrokeColor     = new Vector3F(0.7f, 0.3f, 0.5f),
                StrokeAlpha     = 1,
                PoseLocal       = new Pose(new Vector3F(-2, 2, 0))
            };

            _scene.Children.Add(figureNode);

            figure = new EllipseFigure
            {
                IsFilled = false,
                RadiusX  = 0.25f,
                RadiusY  = 0.4f,
            };
            figureNode = new FigureNode(figure)
            {
                Name              = "Ellipse #2",
                StrokeThickness   = 3,
                StrokeColor       = new Vector3F(0.2f, 0.3f, 0.3f),
                StrokeAlpha       = 0.5f,
                StrokeDashPattern = new Vector4F(10, 2, 3, 2),
                DashInWorldSpace  = false,
                PoseLocal         = new Pose(new Vector3F(-1, 2, 0))
            };
            _scene.Children.Add(figureNode);

            figure = new EllipseFigure
            {
                IsFilled = true,
                RadiusX  = 0.3f,
                RadiusY  = 0.35f,
            };
            figureNode = new FigureNode(figure)
            {
                Name              = "Ellipse #3",
                StrokeThickness   = 2,
                StrokeColor       = new Vector3F(0.3f, 0, 0.2f),
                StrokeAlpha       = 1,
                StrokeDashPattern = new Vector4F(10, 2, 3, 2) / 100,
                DashInWorldSpace  = true,
                FillColor         = new Vector3F(0.7f, 0, 0.5f),
                FillAlpha         = 0.5f,
                PoseLocal         = new Pose(new Vector3F(-0, 2, 0))
            };
            _scene.Children.Add(figureNode);

            figure = new EllipseFigure
            {
                IsFilled = true,
                RadiusX  = 0.5f,
                RadiusY  = 0.1f,
            };
            figureNode = new FigureNode(figure)
            {
                Name              = "Ellipse #4",
                StrokeThickness   = 2,
                StrokeColor       = new Vector3F(0, 0, 0),
                StrokeAlpha       = 1,
                StrokeDashPattern = new Vector4F(1, 1, 1, 1) / 100,
                DashInWorldSpace  = true,
                FillColor         = new Vector3F(0.3f, 0.3f, 0.3f),
                FillAlpha         = 0.5f,
                PoseLocal         = new Pose(new Vector3F(1, 2, 0))
            };
            _scene.Children.Add(figureNode);

            figure = new EllipseFigure
            {
                IsFilled = true,
                RadiusX  = 0.2f,
                RadiusY  = 0.25f,
            };
            figureNode = new FigureNode(figure)
            {
                Name            = "Ellipse #5",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(0.3f),
                StrokeAlpha     = 1,
                FillColor       = new Vector3F(0.3f),
                FillAlpha       = 1,
                PoseLocal       = new Pose(new Vector3F(2, 2, 0))
            };
            _scene.Children.Add(figureNode);
        }
示例#14
0
 private void ResizeEllipse(EllipseFigure ef, Point pos)
 {
     if (_nowResizing == null)
     {
         var snappedTo = StepManager.SnapTo(pos, ef.GetMagnets(), ef.Center);
         if (snappedTo == ef.Left)
         {
             _nowResizing = new ResizeEllipseStep(ef, ResizeEllipseStep.Side.Right, pos.X - _downPos.X);
         }
         else if (snappedTo == ef.Right)
         {
             _nowResizing = new ResizeEllipseStep(ef, ResizeEllipseStep.Side.Left, pos.X - _downPos.X);
         }
         else if (snappedTo == ef.Top)
         {
             _nowResizing = new ResizeEllipseStep(ef, ResizeEllipseStep.Side.Bottom, pos.Y - _downPos.Y);
         }
         else if (snappedTo == ef.Bottom)
         {
             _nowResizing = new ResizeEllipseStep(ef, ResizeEllipseStep.Side.Top, pos.Y - _downPos.Y);
         }
         if (_nowResizing == null)
         {
             return;
         }
         StepManager.InsertNext(_nowResizing);
     }
     else
     {
         var res     = (ResizeEllipseStep)_nowResizing;
         var snapped = StepManager.Snap(pos, _nowResizing.Figure);
         if (snapped != null)
         {
             if (res.ResizeAround == ResizeEllipseStep.Side.Right)
             {
                 res.Resize("(" + res.Figure.Name + ".x - " + res.Figure.Name + ".radius1 ) - (" +
                            snapped.X.ExprString + ")", snapped.Def);
             }
             else if (res.ResizeAround == ResizeEllipseStep.Side.Left)
             {
                 res.Resize("(" + snapped.X.ExprString + ") - (" + res.Figure.Name + ".x + (" +
                            res.Figure.Name + ".radius1))", snapped.Def);
             }
             else if (res.ResizeAround == ResizeEllipseStep.Side.Top)
             {
                 res.Resize("(" + res.Figure.Name + ".y + " + res.Figure.Name + ".radius2 ) - (" +
                            snapped.Y.ExprString + ")", snapped.Def);
             }
             else if (res.ResizeAround == ResizeEllipseStep.Side.Bottom)
             {
                 res.Resize("(" + snapped.Y.ExprString + ") - (" + res.Figure.Name + ".y - (" +
                            res.Figure.Name + ".radius2))", snapped.Def);
             }
         }
         else
         {
             if (res.ResizeAround == ResizeEllipseStep.Side.Right)
             {
                 res.Resize(_downPos.X - pos.X);
             }
             else if (res.ResizeAround == ResizeEllipseStep.Side.Left)
             {
                 res.Resize(pos.X - _downPos.X);
             }
             else if (res.ResizeAround == ResizeEllipseStep.Side.Top)
             {
                 res.Resize(_downPos.Y - pos.Y);
             }
             else if (res.ResizeAround == ResizeEllipseStep.Side.Bottom)
             {
                 res.Resize(pos.Y - _downPos.Y);
             }
         }
     }
 }
 public ResizeEllipseStep(EllipseFigure figure, Side resizeAround, string delta, string where = null)
     : this(figure, resizeAround)
 {
     Resize(delta, where);
 }
示例#16
0
 private DrawEllipseStep()
 {
     Figure        = new EllipseFigure("circle" + _count++);
     EllipseFigure = (EllipseFigure)Figure;
 }
示例#17
0
 public MoveEllipseStep(EllipseFigure figure, double x, double y) : this(figure, x.Str(), y.Str())
 {
 }
示例#18
0
 public MoveEllipseStep(EllipseFigure figure, string x, string y) : this(figure)
 {
     Move(x, y);
 }
示例#19
0
 private MoveEllipseStep(EllipseFigure figure)
 {
     Figure        = figure;
     EllipseFigure = figure;
 }