예제 #1
0
        public void LwPolylineWithLargeArcTest1()
        {
            var vertices = new List <DxfLwPolylineVertex>()
            {
                new DxfLwPolylineVertex()
                {
                    X = 0.6802950090711775, Y = 1.360590018142377, Bulge = 1.523362963416235
                },
                new DxfLwPolylineVertex()
                {
                    X = 1.176774337206015, Y = 0.2152040759172933
                }
            };
            var poly = new DxfLwPolyline(vertices);
            var path = poly.GetSvgPath();

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

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

            AssertClose(0.6802950090711775, move.LocationX);
            AssertClose(1.360590018142377, move.LocationY);

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

            AssertClose(1.176774337206015, arc.EndPointX);
            AssertClose(0.2152040759172933, arc.EndPointY);
            AssertClose(0.68029500907118867, arc.RadiusX);
            AssertClose(0.68029500907118867, arc.RadiusY);
            Assert.True(arc.IsCounterClockwiseSweep);
            Assert.True(arc.IsLargeArc);
            Assert.Equal(0.0, arc.XAxisRotation);
        }
예제 #2
0
        public void LwPolylineWithLargeArcTest2()
        {
            var vertices = new List <DxfLwPolylineVertex>()
            {
                new DxfLwPolylineVertex()
                {
                    X = 1.176774337206015, Y = 0.2152040759172933, Bulge = -0.1085213126826841
                },
                new DxfLwPolylineVertex()
                {
                    X = 1.501796342836956, Y = 0.2867624159371331
                }
            };
            var poly = new DxfLwPolyline(vertices);
            var path = poly.GetSvgPath();

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

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

            AssertClose(1.176774337206015, move.LocationX);
            AssertClose(0.2152040759172933, move.LocationY);

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

            AssertClose(1.501796342836956, arc.EndPointX);
            AssertClose(0.2867624159371331, arc.EndPointY);
            AssertClose(0.77571287053371341, arc.RadiusX);
            AssertClose(0.77571287053371341, arc.RadiusY);
            Assert.False(arc.IsCounterClockwiseSweep);
            Assert.False(arc.IsLargeArc);
            Assert.Equal(0.0, arc.XAxisRotation);
        }
예제 #3
0
        public static XElement ToXElement(this DxfLwPolyline poly)
        {
            var path = poly.GetSvgPath();

            return(new XElement(DxfToSvgConverter.Xmlns + "path",
                                new XAttribute("d", path.ToString()),
                                new XAttribute("fill-opacity", 0))
                   .AddStroke(poly.Color)
                   .AddStrokeWidth(1.0)
                   .AddVectorEffect());
        }
예제 #4
0
        public void RenderOpenLwPolylineTest()
        {
            //   1,1 D
            //    ------------- 2,1 C
            //                |
            //               /
            // ____________-
            // 0,0      1,0
            //  A        B
            var bulge90Degrees = Math.Sqrt(2.0) - 1.0;
            var vertices       = new List <DxfLwPolylineVertex>()
            {
                new DxfLwPolylineVertex()
                {
                    X = 0.0, Y = 0.0
                },                                              // A
                new DxfLwPolylineVertex()
                {
                    X = 1.0, Y = 0.0, Bulge = bulge90Degrees
                },                                                                      // B
                new DxfLwPolylineVertex()
                {
                    X = 2.0, Y = 1.0
                },                                              // C
                new DxfLwPolylineVertex()
                {
                    X = 1.0, Y = 1.0, Bulge = bulge90Degrees
                }                                                                      // D
            };
            var poly = new DxfLwPolyline(vertices);

            poly.IsClosed = false;
            var path = poly.GetSvgPath();

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

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

            AssertClose(0.0, start.LocationX);
            AssertClose(0.0, start.LocationY);

            var segmentAB = (SvgLineToPath)path.Segments[1];

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

            var segmentBC = (SvgArcToPath)path.Segments[2];

            AssertClose(2.0, segmentBC.EndPointX);
            AssertClose(1.0, segmentBC.EndPointY);
            AssertClose(1.0, segmentBC.RadiusX);
            AssertClose(1.0, segmentBC.RadiusY);
            AssertClose(0.0, segmentBC.XAxisRotation);
            Assert.False(segmentBC.IsLargeArc);
            Assert.True(segmentBC.IsCounterClockwiseSweep);

            var segmentCD = (SvgLineToPath)path.Segments[3];

            AssertClose(1.0, segmentCD.LocationX);
            AssertClose(1.0, segmentCD.LocationY);

            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 = poly.ToXElement();

            AssertXElement(expected, actual);
        }