public static XElement ToXElement(this DxfEllipse ellipse)
        {
            XElement baseShape;

            if (IsCloseTo(ellipse.StartParameter, 0.0) && IsCloseTo(ellipse.EndParameter, Math.PI * 2.0))
            {
                baseShape = new XElement(DxfToSvgConverter.Xmlns + "ellipse",
                                         new XAttribute("cx", ellipse.Center.X.ToDisplayString()),
                                         new XAttribute("cy", ellipse.Center.Y.ToDisplayString()),
                                         new XAttribute("rx", ellipse.MajorAxis.Length.ToDisplayString()),
                                         new XAttribute("ry", ellipse.MinorAxis().Length.ToDisplayString()));
            }
            else
            {
                var path = ellipse.GetSvgPath();
                baseShape = new XElement(DxfToSvgConverter.Xmlns + "path",
                                         new XAttribute("d", path.ToString()));
            }

            baseShape.Add(new XAttribute("fill-opacity", 0));
            return(baseShape
                   .AddStroke(ellipse.Color)
                   .AddStrokeWidth(1.0)
                   .AddVectorEffect());
        }
Example #2
0
        public void RenderEllipseTest()
        {
            var ellipse = new DxfEllipse(new DxfPoint(1.0, 2.0, 3.0), new DxfVector(1.0, 0.0, 0.0), 0.5)
            {
                StartParameter = 0.0,
                EndParameter   = Math.PI / 2.0 // 90 degrees
            };
            var path = ellipse.GetSvgPath();

            Assert.Equal(2, path.Segments.Count);

            var move = (SvgMoveToPath)path.Segments[0];

            AssertClose(2.0, move.LocationX);
            AssertClose(2.0, move.LocationY);

            var arcSegment = (SvgArcToPath)path.Segments[1];

            AssertClose(1.0, arcSegment.EndPointX);
            AssertClose(2.5, arcSegment.EndPointY);
            Assert.Equal(1.0, arcSegment.RadiusX);
            Assert.Equal(0.5, arcSegment.RadiusY);
            Assert.Equal(0.0, arcSegment.XAxisRotation);
            Assert.False(arcSegment.IsLargeArc);
            Assert.True(arcSegment.IsCounterClockwiseSweep);

            var expected = new XElement("path",
                                        new XAttribute("d", path.ToString()),
                                        new XAttribute("fill-opacity", "0"),
                                        new XAttribute("stroke-width", "1.0px"),
                                        new XAttribute("vector-effect", "non-scaling-stroke"));
            var actual = ellipse.ToXElement();

            AssertXElement(expected, actual);
        }
Example #3
0
        public void EllipsePathOf180DegreesTest()
        {
            var ellipse = new DxfEllipse(new DxfPoint(0.0, 0.0, 0.0), new DxfVector(1.0, 0.0, 0.0), 0.5)
            {
                StartParameter = 0.0,
                EndParameter   = Math.PI
            };
            var path = ellipse.GetSvgPath();

            Assert.Equal(3, path.Segments.Count);

            var move = (SvgMoveToPath)path.Segments[0];

            AssertClose(1.0, move.LocationX);
            AssertClose(0.0, move.LocationY);

            // 180 degree ellipses are difficult to render; split it into two 90s
            var first = (SvgArcToPath)path.Segments[1];

            AssertClose(0.0, first.EndPointX);
            AssertClose(0.5, first.EndPointY);
            Assert.Equal(1.0, first.RadiusX);
            Assert.Equal(0.5, first.RadiusY);
            Assert.Equal(0.0, first.XAxisRotation);
            Assert.False(first.IsLargeArc);
            Assert.True(first.IsCounterClockwiseSweep);
            var second = (SvgArcToPath)path.Segments[2];

            AssertClose(-1.0, second.EndPointX);
            AssertClose(0.0, second.EndPointY);
            Assert.Equal(1.0, second.RadiusX);
            Assert.Equal(0.5, second.RadiusY);
            Assert.Equal(0.0, second.XAxisRotation);
            Assert.False(second.IsLargeArc);
            Assert.True(second.IsCounterClockwiseSweep);
        }