Пример #1
0
            static Shape <double> CreateDiskShape(ConvolutionFactory factory)
            {
                var eastDirection = factory.CreateDirection(1.0, 0.0);

                var diskArc = factory.CreateArc(
                    center: factory.CreatePoint(0.0, 0.0),
                    directions: factory.CreateDirectionRange(eastDirection, eastDirection, Orientation.CounterClockwise),
                    radius: 1.0,
                    weight: 1);

                return(factory.CreateShape(new[] { diskArc }));
            }
Пример #2
0
        public void When_Direction_Ranges_Are_Included_Then_Intersection_Should_Be_The_Innermost_Range()
        {
            const double radius1 = 2.0;
            const double radius2 = 2.0;

            var convolutionFactory = new ConvolutionFactory();

            var arc1 = convolutionFactory.CreateArc(
                centerX: 1.0,
                centerY: 2.0,
                directionStartX: 1.0,
                directionStartY: 0.0,
                directionEndX: 0.0,
                directionEndY: 1.0,
                orientation: Orientation.CounterClockwise,
                radius: radius1,
                weight: 1);

            var arc2 = convolutionFactory.CreateArc(
                centerX: 2.0,
                centerY: 1.0,
                directionStartX: 1.0,
                directionStartY: 0.5,
                directionEndX: 0.5,
                directionEndY: 1.0,
                orientation: Orientation.CounterClockwise,
                radius: radius2,
                weight: 1);

            var convolution = convolutionFactory.ConvolveTracings(arc1, arc2).ToList();

            convolution.Should().HaveCount(1);

            convolution[0].Convolution.Should().BeOfType(typeof(Arc <double>));

            var convolutionAsArc = (Arc <double>)convolution[0].Convolution;

            convolutionAsArc.Center.Should().BeEquivalentTo(convolutionFactory.CreatePoint(3.0, 3.0));
        }
Пример #3
0
        public void When_Two_Shapes_Are_Convolved_Then_Parent1_Should_Belong_To_Shape1_And_Parent2_Should_Belong_To_Shape2()
        {
            // Arrange
            var shape1 = createShape1();
            var shape2 = createShape2();

            // Act
            var convolution = _factory.ConvolveShapes(shape1, shape2);

            // Assert
            convolution.ConvolvedTracings.ToList()
            .ForEach(convolvedTracing =>
                     shape1.Tracings.Contains(convolvedTracing.Parent1).Should().BeTrue());

            convolution.ConvolvedTracings.ToList()
            .ForEach(convolvedTracing =>
                     shape2.Tracings.Contains(convolvedTracing.Parent2).Should().BeTrue());

            Shape <double> createShape1()
            {
                var weight = new Fraction(1, 2);

                var d1 = _factory.CreateDirection(-1, 2);
                var d2 = _factory.CreateDirection(-1, -2);
                var d3 = _factory.CreateDirection(2, 0);

                var c1 = _factory.CreatePoint(1, 0);
                var c2 = _factory.CreatePoint(0, 2);
                var c3 = _factory.CreatePoint(-1, 0);

                var range1 = _factory.CreateDirectionRange(
                    d3.NormalDirection().Opposite(),
                    d1.NormalDirection().Opposite(),
                    Orientation.CounterClockwise);

                var range2 = _factory.CreateDirectionRange(
                    d1.NormalDirection().Opposite(),
                    d2.NormalDirection().Opposite(),
                    Orientation.CounterClockwise);

                var range3 = _factory.CreateDirectionRange(
                    d2.NormalDirection().Opposite(),
                    d3.NormalDirection().Opposite(),
                    Orientation.CounterClockwise);

                var arc1 = _factory.CreateArc(c1, range1, 1.0, weight);
                var arc2 = _factory.CreateArc(c2, range2, 1.0, weight);
                var arc3 = _factory.CreateArc(c3, range3, 1.0, weight);

                var segment1 = _factory.CreateSegment(arc1.End, arc2.Start, weight);
                var segment2 = _factory.CreateSegment(arc2.End, arc3.Start, weight);
                var segment3 = _factory.CreateSegment(arc3.End, arc1.Start, weight);

                return(_factory.CreateShape(
                           new Tracing <double>[]
                {
                    arc1, segment1, arc2, segment2, arc3, segment3
                }));
            }

            Shape <double> createShape2()
            {
                var weight = new Fraction(1, 2);

                var d1 = _factory.CreateDirection(0, 3);
                var d2 = _factory.CreateDirection(-3, 0);
                var d3 = _factory.CreateDirection(0, -3);
                var d4 = _factory.CreateDirection(3, 0);

                var c1 = _factory.CreatePoint(3, 0);
                var c2 = _factory.CreatePoint(3, 3);
                var c3 = _factory.CreatePoint(0, 3);
                var c4 = _factory.CreatePoint(0, 0);

                var range1 = _factory.CreateDirectionRange(
                    d4.NormalDirection().Opposite(),
                    d1.NormalDirection().Opposite(),
                    Orientation.CounterClockwise);

                var range2 = _factory.CreateDirectionRange(
                    d1.NormalDirection().Opposite(),
                    d2.NormalDirection().Opposite(),
                    Orientation.CounterClockwise);

                var range3 = _factory.CreateDirectionRange(
                    d2.NormalDirection().Opposite(),
                    d3.NormalDirection().Opposite(),
                    Orientation.CounterClockwise);

                var range4 = _factory.CreateDirectionRange(
                    d3.NormalDirection().Opposite(),
                    d4.NormalDirection().Opposite(),
                    Orientation.CounterClockwise);

                var arc1 = _factory.CreateArc(c1, range1, 1.0, weight);
                var arc2 = _factory.CreateArc(c2, range2, 1.0, weight);
                var arc3 = _factory.CreateArc(c3, range3, 1.0, weight);
                var arc4 = _factory.CreateArc(c4, range4, 1.0, weight);

                var segment1 = _factory.CreateSegment(arc1.End, arc2.Start, weight);
                var segment2 = _factory.CreateSegment(arc2.End, arc3.Start, weight);
                var segment3 = _factory.CreateSegment(arc3.End, arc4.Start, weight);
                var segment4 = _factory.CreateSegment(arc4.End, arc1.Start, weight);

                return(_factory.CreateShape(
                           new Tracing <double>[]
                {
                    arc1, segment1, arc2, segment2, arc3, segment3, arc4, segment4
                }));
            }
        }