Exemple #1
0
        public int Execute()
        {
            _logger.LogInformation("ExpandVerticesCommand.Execute");

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

            // Parse input JSON file
            List <Vector> inputVertices = GetVertices(InputPath);

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

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

            // Finally, get the intersection points of the adjacent lines.
            List <Vector> 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);
        }
        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);
        }