コード例 #1
0
        public int Execute()
        {
            IEnumerable <Curve> curves = GetCurves(InputPath);

            Svg svg = _svgService.CreateSvg();

            _svgService.DrawPath(svg, curves, PathStyle);
            _svgService.WriteToFile(svg, OutputPath);

            return(0);
        }
コード例 #2
0
        public int Execute()
        {
            IEnumerable <Switch> switches = GetSwitchBearings(InputPath);

            Svg svg = _svgService.CreateSvg();

            _svgService.DrawSwitches(svg, switches, PathStyle);
            _svgService.WriteToFile(svg, OutputPath);

            return(0);
        }
コード例 #3
0
        public int Execute()
        {
            IEnumerable <Segment> segments = GetSegments(InputPath);

            var midpoints = segments.Select(segment => segment.Midpoint());

            Svg svg = _svgService.CreateSvg();

            _svgService.Append(svg, midpoints, HoleStyle);
            _svgService.WriteToFile(svg, OutputPath);

            return(0);
        }
コード例 #4
0
        public int Execute()
        {
            _logger.LogInformation("ExpandVerticesCommand2.Execute");

            if (!double.TryParse(Distance, out double distance))
            {
                Console.WriteLine("Distance must be a valid floating point number.");
                return(-2);
            }

            List <Point3d> inputVertices = GetVertices(InputPath)
                                           .Select(v => new Point3d(v.X, v.Y, 0.0))
                                           .ToList();

            // First, turn the list of vertices into a list of line segments.
            List <Segment3d> inputSegments = GetSegments(inputVertices).ToList();

            // Next, expand the segments into parallel lines that are a given distance away.
            List <Line3d> expandedLines = ExpandSegments(inputSegments, distance)
                                          .ToList();

            // Finally, get the intersection points of the adjacent lines.
            List <Point3d> expandedVertices = GetIntersectionPoints(expandedLines)
                                              .ToList();

            //WriteVerticesToFile(OutputPath, expandedVertices);
            WriteVerticesToConsole(inputVertices, expandedVertices);

            if (!string.IsNullOrEmpty(DebugSvgPath))
            {
                Svg svg = _svgService.CreateSvg();
                //_svgService.Append(svg, inputVertices, InitialVertexSvgStyles);
                //_svgService.Append(svg, inputSegments, InitialSegmentSvgStyles);
                //_svgService.Append(svg, expandedVertices, ExpandedVertexSvgStyles);

                //List<Segment> expandedSegments = VectorOperations.GetSegments(expandedVertices).ToList();
                //_svgService.Append(svg, expandedSegments, ExpandedSegmentSvgStyles);

                _svgService.WriteToFile(svg, DebugSvgPath);
            }

            return(0);
        }
コード例 #5
0
        public int Execute()
        {
            if (!float.TryParse(Distance, out float distance))
            {
                Console.WriteLine("Distance must be a valid floating point number.");
                return(-1);
            }

            var vertices = GetVertices(InputPath);

            List <Curve> curves = VectorOperations
                                  .GenerateCurves(vertices, distance)
                                  .Select(c => c.Round(3))
                                  .ToList();

            WriteCurvesToFile(OutputPath, curves);

            if (!string.IsNullOrEmpty(DebugSvgPath))
            {
                Svg svg = _svgService.CreateSvg();

                List <Vector> curvePoints = FlattenCurvePoints(curves).ToList();
                _svgService.Append(svg, curves, CurveSvgStyles);
                _svgService.Append(svg, curvePoints, VectorSvgStyles);
                _svgService.Append(svg, VectorOperations.GetSegments(curvePoints), SegmentSvgStyles);

                _svgService.WriteToFile(svg, DebugSvgPath);
            }

            if (!string.IsNullOrEmpty(OutputXmlPath))
            {
                List <string> xmlLines = new List <string>();

                for (int i = 0; i < curves.Count; ++i)
                {
                    double startX   = curves[i].Start.X;
                    double startY   = curves[i].Start.Y;
                    double endX     = curves[i].End.X;
                    double endY     = curves[i].End.Y;
                    double controlX = curves[i].Control.X;
                    double controlY = curves[i].Control.Y;

                    if (i == 0)
                    {
                        xmlLines.Add($"<AbsoluteMoveTo> <EndPoint X=\"{startX}\" Y=\"{startY}\" /> </AbsoluteMoveTo>");
                    }
                    else
                    {
                        xmlLines.Add($"<AbsoluteLineTo> <EndPoint X=\"{startX}\" Y=\"{startY}\" /> </AbsoluteLineTo>");
                    }

                    xmlLines.Add($"<AbsoluteQuadraticCurveTo> <EndPoint X=\"{endX}\" Y=\"{endY}\" /> <ControlPoint X=\"{controlX}\" Y=\"{controlY}\" /> </AbsoluteQuadraticCurveTo>");
                }

                xmlLines.Add($"<AbsoluteLineTo> <EndPoint X=\"{curves[0].Start.X}\" Y=\"{curves[0].Start.Y}\" /> </AbsoluteLineTo>");

                string text = string.Join(Environment.NewLine, xmlLines);
                File.WriteAllText(OutputXmlPath, text);
            }

            return(0);
        }
コード例 #6
0
        public int Execute()
        {
            _logger.LogInformation("ExpandVerticesCommand2.Execute");

            if (!double.TryParse(Distance, out double distance))
            {
                Console.WriteLine("Distance must be a valid floating point number.");
                return(-2);
            }

            // Parse JSON input file
            List <Point3d> inputVertices = GetVertices(InputPath)
                                           .Select(v => new Point3d(v.X, v.Y, 0.0))
                                           .ToList();

            _logger.LogInformation("Parsed input vertices:");
            foreach (Point3d v in inputVertices)
            {
                _logger.LogInformation($" - ({v.X}, {v.Y})");
            }

            // First, turn the list of vertices into a list of line segments.
            List <Segment3d> inputSegments = GetSegments(inputVertices).ToList();

            _logger.LogInformation("Converted vertices to segments:");
            foreach (Segment3d s in inputSegments)
            {
                _logger.LogInformation($" - [({s.P1.X}, {s.P1.Y}), ({s.P2.X}, {s.P2.Y})]");
            }

            // Next, expand the segments into parallel lines that are a given distance away.
            List <Line3d> expandedLines = ExpandSegments(inputSegments, distance)
                                          .ToList();

            _logger.LogInformation("Expanded segments into lines:");
            foreach (Line3d l in expandedLines)
            {
                _logger.LogInformation($" - Direction: {l.Direction}, Point: {l.Point}");
            }

            // Finally, get the intersection points of the adjacent lines.
            List <Point3d> expandedVertices = GetIntersectionPoints(expandedLines)
                                              .ToList();

            WriteVerticesToFile(OutputPath, expandedVertices);
            WriteVerticesToConsole(inputVertices, expandedVertices);

            if (!string.IsNullOrEmpty(DebugSvgPath))
            {
                Svg svg = _svgService.CreateSvg();
                _svgService.Append(
                    svg,
                    inputVertices.Select(p => new Vector(p.X, p.Y)),
                    InitialVertexSvgStyles);
                _svgService.Append(
                    svg,
                    inputSegments.Select(s => new Segment(
                                             new Vector(s.P1.X, s.P1.Y),
                                             new Vector(s.P2.X, s.P2.Y)
                                             )),
                    InitialSegmentSvgStyles);
                _svgService.Append(
                    svg,
                    expandedVertices.Select(p => new Vector(p.X, p.Y)),
                    ExpandedVertexSvgStyles);

                _svgService.Append(
                    svg,
                    GetSegments(expandedVertices).Select(s => new Segment(
                                                             new Vector(s.P1.X, s.P1.Y),
                                                             new Vector(s.P2.X, s.P2.Y)
                                                             ))
                    .ToList(),
                    ExpandedSegmentSvgStyles);

                _svgService.WriteToFile(svg, DebugSvgPath);
            }

            return(0);
        }