Пример #1
0
        public void CreateAngleXLineCommand()
        {
            PromptPointOptions ppo = new PromptPointOptions("\nPick Point");
            PromptPointResult  ppr = GLOBAL.CurrentEditor.GetPoint(ppo);

            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }

            PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter Grade (%)");
            PromptDoubleResult  pdr = GLOBAL.CurrentEditor.GetDouble(pdo);

            if (pdr.Status != PromptStatus.OK)
            {
                return;
            }
            // calculate second point
            Point3d secondPoint = Helper.Point3dHelper.Offset(ppr.Value, 100, pdr.Value, 0);
            Xline   xline       = new Xline()
            {
                BasePoint = ppr.Value, UnitDir = new Vector3d(secondPoint.X - ppr.Value.X, secondPoint.Y - ppr.Value.Y, secondPoint.Z - ppr.Value.Z)
            };
            CompositeFigure cg = new CompositeFigure();

            cg.Children.Add(xline);
            cg.Append(GLOBAL.CurrentDocument);
        }
Пример #2
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)),
            });
        }
Пример #3
0
        /* Create a group figure*/
        public void CreateCompositeFigure(string nameGroup, IEnumerable <string> childFigures)
        {
            var figuresList = new List <IFigure>();

            if (_compositeFigures.ContainsKey(nameGroup))
            {
                throw new NameDoesAlreadyExist();
            }

            foreach (var nameFigure in childFigures)
            {
                if (_figures.ContainsKey(nameFigure) && !_compositeFigures.ContainsKey(nameFigure))
                {
                    figuresList.Add(_figures[nameFigure]);
                    _figures.Remove(nameFigure); //Delete after grouping
                }
                else
                {
                    throw new NameDoesAlreadyExist();
                }
            }

            var copositeFigure = new CompositeFigure(figuresList);

            _compositeFigures.Add(nameGroup, copositeFigure);
        }
Пример #4
0
        public void EmptyCompositeTest()
        {
            // Arrange
            var compositeFigure = new CompositeFigure(Array.Empty <FigureBase>());

            var areaCalculator      = new Mock <IAreaCalculator>(MockBehavior.Strict);
            var compositeCalculator = new CompositeAreaCalculator(areaCalculator.Object);

            // Act
            var calculatedArea = compositeCalculator.TryCalculateArea(compositeFigure);

            // Assert
            Assert.AreEqual(0, calculatedArea, 0);
        }
Пример #5
0
        public void IntegrationTest()
        {
            // Arrange
            var circle         = new Circle(1);
            var customFigure   = new TestFigure();
            var innerComposite = new CompositeFigure(new FigureBase[] { circle, customFigure });

            var emptyComposite = new CompositeFigure(Array.Empty <FigureBase>());
            var triangle       = new ThreeLinesTriangle(2.5, 3, 4);

            var composite = new CompositeFigure(new FigureBase[] { innerComposite, emptyComposite, triangle });
            var circle2   = new Circle(2);

            var customCalculatorNotUsed = new Mock <ITryAreaCalculator>(MockBehavior.Default);

            customCalculatorNotUsed.Setup(it => it.TryCalculateArea(customFigure))
            .Throws(new AssertionException("Should not be called"));

            var customCalculator = new Mock <ITryAreaCalculatorWithPriority>(MockBehavior.Default);

            customCalculator.Setup(it => it.TryCalculateArea(customFigure)).Returns(15.2);
            customCalculator.Setup(it => it.GetPriority(customFigure)).Returns(100);

            var areaCalculator = new AreaCalculator();

            areaCalculator.Calculators.Add(new CompositeAreaCalculator(areaCalculator));
            areaCalculator.Calculators.Add(new TriangleAreaCalculator());
            areaCalculator.Calculators.Add(new RightAngleTriangleCalculator());
            areaCalculator.Calculators.Add(new CircleAreaCalculator());
            areaCalculator.Calculators.Add(customCalculatorNotUsed.Object);
            areaCalculator.Calculators.Add(customCalculator.Object);

            // Act
            var compositeArea = areaCalculator.CalculateArea(composite);
            var triangleArea  = areaCalculator.CalculateArea(triangle);
            var circle2Area   = areaCalculator.CalculateArea(circle2);

            // Assert
            const double ExpectedTriangleArea  = 3.7453095666446585;
            var          expectedCompositeArea = Math.PI + 15.2 + ExpectedTriangleArea;

            Assert.AreEqual(expectedCompositeArea, compositeArea, DoubleEquality.Epsilon);
            Assert.AreEqual(ExpectedTriangleArea, triangleArea, DoubleEquality.Epsilon);
            Assert.AreEqual(4 * Math.PI, circle2Area, DoubleEquality.Epsilon);
        }
Пример #6
0
        public void DuplicateFigureTest()
        {
            // Arrange
            var figure          = new TestFigure();
            var compositeFigure = new CompositeFigure(new FigureBase[] { figure, figure });

            var areaCalculator = new Mock <IAreaCalculator>(MockBehavior.Strict);

            areaCalculator.Setup(it => it.CalculateArea(figure)).Returns(10.5);

            var compositeCalculator = new CompositeAreaCalculator(areaCalculator.Object);

            // Act
            var calculatedArea = compositeCalculator.TryCalculateArea(compositeFigure);

            // Assert
            Assert.AreEqual(21, calculatedArea, DoubleEquality.Epsilon);
        }
Пример #7
0
        public void NestedCompositeTest()
        {
            // Arrange
            var figure          = new TestFigure();
            var innerComposite  = new CompositeFigure(Array.Empty <FigureBase>());
            var compositeFigure = new CompositeFigure(new FigureBase[] { innerComposite, figure });

            var areaCalculator = new Mock <IAreaCalculator>(MockBehavior.Strict);

            areaCalculator.Setup(it => it.CalculateArea(figure)).Returns(1.5);
            areaCalculator.Setup(it => it.CalculateArea(innerComposite)).Returns(2.1);

            var compositeCalculator = new CompositeAreaCalculator(areaCalculator.Object);

            // Act
            var calculatedArea = compositeCalculator.TryCalculateArea(compositeFigure);

            // Assert
            Assert.AreEqual(3.6, calculatedArea, DoubleEquality.Epsilon);
        }
Пример #8
0
        public void SimpleCompositeTest()
        {
            // Arrange
            var figure1         = new TestFigure();
            var figure2         = new TestFigure();
            var figure3         = new TestFigure();
            var compositeFigure = new CompositeFigure(new FigureBase[] { figure1, figure2, figure3 });

            var areaCalculator = new Mock <IAreaCalculator>(MockBehavior.Strict);

            areaCalculator.Setup(it => it.CalculateArea(figure1)).Returns(100);
            areaCalculator.Setup(it => it.CalculateArea(figure2)).Returns(20);
            areaCalculator.Setup(it => it.CalculateArea(figure3)).Returns(5.3);

            var compositeCalculator = new CompositeAreaCalculator(areaCalculator.Object);

            // Act
            var calculatedArea = compositeCalculator.TryCalculateArea(compositeFigure);

            // Assert
            Assert.AreEqual(125.3, calculatedArea, DoubleEquality.Epsilon);
        }
Пример #9
0
        private void CreateGate()
        {
            // not gate
            var trianglePath = new Path2F
            {
                new PathKey2F
                {
                    Parameter     = 0,
                    Interpolation = SplineInterpolation.Linear,
                    Point         = new Vector2F(1, 0),
                },
                new PathKey2F
                {
                    Parameter     = 1,
                    Interpolation = SplineInterpolation.Linear,
                    Point         = new Vector2F(-0.25f, 0.5f),
                },
                new PathKey2F
                {
                    Parameter     = 2,
                    Interpolation = SplineInterpolation.Linear,
                    Point         = new Vector2F(-0.25f, -0.5f),
                },
                new PathKey2F
                {
                    Parameter     = 3,
                    Interpolation = SplineInterpolation.Linear,
                    Point         = new Vector2F(1, 0),
                }
            };

            var triangle = new PathFigure2F();

            triangle.Segments.Add(trianglePath);
            var outPinFigure = new PathFigure2F
            {
                Segments =
                {
                    new LineSegment2F()
                    {
                        Point1 = new Vector2F(1, 0), Point2 = new Vector2F(1.2f, 0)
                    }
                }
            };

            // Add figure to the scene.
            var notGateNode = new FigureNode(triangle)
            {
                Name            = "Not Gate",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(1, 0.2f, 0.2f),
                FillColor       = new Vector3F(1, 0.5f, 0.5f),
                FillAlpha       = 0.5f,
                PoseLocal       = new Pose(new Vector3F(0, 0, 0)),
                ScaleLocal      = new Vector3F(1),
                Children        = new SceneNodeCollection(3),
            };

            var pinFigure = new PathFigure2F
            {
                Segments =
                {
                    new LineSegment2F {
                        Point1 = new Vector2F(0, 0), Point2 = new Vector2F(0.2f, 0)
                    }
                }
            };
            var pinsFigure = new CompositeFigure();

            var output = new TransformedFigure(pinFigure)
            {
                Pose = new Pose(new Vector3F(1.0f, 0, 0))
            };

            pinsFigure.Children.Add(output);

            var ina = new TransformedFigure(pinFigure)
            {
                Pose = new Pose(new Vector3F(-0.25f - 0.2f, -0.25f, 0))
            };

            pinsFigure.Children.Add(ina);

            var inb = new TransformedFigure(pinFigure)
            {
                Pose = new Pose(new Vector3F(-0.25f - 0.2f, 0.25f, 0))
            };

            pinsFigure.Children.Add(inb);

            notGateNode.Children.Add(new FigureNode(pinsFigure)
            {
                Name            = "Pins",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(0, 0, 0),
                PoseLocal       = new Pose(new Vector3F(0, 0, 0)),
                ScaleLocal      = new Vector3F(1f),
            });


            Scene.Children.Add(notGateNode);
        }
Пример #10
0
        // Add a flower shape.
        private void CreateFlower()
        {
            // Define single flower petal.
            var petalPath = new Path2F
            {
                new PathKey2F
                {
                    Parameter     = 0,
                    Interpolation = SplineInterpolation.Bezier,
                    Point         = new Vector2F(0, 0),
                    TangentIn     = new Vector2F(0, 0),
                    TangentOut    = new Vector2F(-0.2f, 0.2f)
                },
                new PathKey2F
                {
                    Parameter     = 1,
                    Interpolation = SplineInterpolation.Bezier,
                    Point         = new Vector2F(0, 1),
                    TangentIn     = new Vector2F(-0.3f, 1.1f),
                    TangentOut    = new Vector2F(0.3f, 1.1f)
                },
                new PathKey2F
                {
                    Parameter     = 2,
                    Interpolation = SplineInterpolation.Bezier,
                    Point         = new Vector2F(0, 0),
                    TangentIn     = new Vector2F(0.2f, 0.2f),
                    TangentOut    = new Vector2F(0, 0)
                }
            };

            var petal = new PathFigure2F();

            petal.Segments.Add(petalPath);

            // Duplicate and rotate flower petal several times.
            const int numberOfPetals = 9;
            var       flower         = new CompositeFigure();

            flower.Children.Add(petal);
            for (int i = 1; i < numberOfPetals; i++)
            {
                var transformedPetal = new TransformedFigure(petal)
                {
                    Pose = new Pose(Matrix33F.CreateRotationZ(i * ConstantsF.TwoPi / numberOfPetals))
                };
                flower.Children.Add(transformedPetal);
            }

            var flowerNode = new FigureNode(flower)
            {
                Name            = "Flower",
                StrokeThickness = 2,
                StrokeColor     = new Vector3F(1, 0.2f, 0.2f),
                FillColor       = new Vector3F(1, 0.5f, 0.5f),
                FillAlpha       = 1,
                PoseLocal       = new Pose(new Vector3F(3, 1, 0)),
                ScaleLocal      = new Vector3F(0.5f)
            };

            _scene.Children.Add(flowerNode);
        }
 public BorderDecoratorCommand(CompositeFigure figures, IFigure f)
 {
     this.f = f;
     this.cf = figures;
 }
Пример #12
0
 public BorderDecoratorCommand(CompositeFigure figures, IFigure f)
 {
     this.f  = f;
     this.cf = figures;
 }