|
@@ -1,5 +1,7 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+
|
|
|
+using System.Globalization;
|
|
|
using System.Windows;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
@@ -10,6 +12,32 @@ namespace SketchAssistantWPF
|
|
|
{
|
|
|
public class FileImporter
|
|
|
{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ double scale;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ int i;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ readonly char[] whitespaces = new char[] { ' ', ',' };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ readonly int samplingRateEllipse = 12;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ readonly int samplingRateBezier = 101;
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -27,7 +55,6 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
private Tuple<int, int, List<InternalLine>> ParseISADInput(String[] allLines)
|
|
|
{
|
|
|
-
|
|
|
if (allLines.Length == 0)
|
|
|
{
|
|
|
throw new FileImporterException("file is empty", "", -1);
|
|
@@ -40,10 +67,9 @@ namespace SketchAssistantWPF
|
|
|
{
|
|
|
throw new FileImporterException("unterminated drawing definition", ".isad files have to end with the 'enddrawing' token", allLines.Length);
|
|
|
}
|
|
|
-
|
|
|
Tuple<int, int> dimensions = ParseISADHeader(allLines);
|
|
|
List<InternalLine> picture = ParseISADBody(allLines, dimensions.Item1, dimensions.Item2);
|
|
|
-
|
|
|
+
|
|
|
return new Tuple<int, int, List<InternalLine>>(dimensions.Item1, dimensions.Item2, picture);
|
|
|
}
|
|
|
|
|
@@ -75,12 +101,9 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
private List<InternalLine> ParseISADBody(String[] allLines, int width, int height)
|
|
|
{
|
|
|
-
|
|
|
String lineStartString = "line";
|
|
|
String lineEndString = "endline";
|
|
|
-
|
|
|
List<InternalLine> drawing = new List<InternalLine>();
|
|
|
-
|
|
|
|
|
|
int i = 2;
|
|
|
|
|
@@ -140,5 +163,1525 @@ namespace SketchAssistantWPF
|
|
|
return ParseISADInput(allLines);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Tuple<int, int, List<InternalLine>> ParseSVGInputFile(String fileName, int windowWidth, int windowHeight)
|
|
|
+ {
|
|
|
+ return ParseSVGInput(System.IO.File.ReadAllLines(fileName), windowWidth, windowHeight);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<int, int, List<InternalLine>> ParseSVGInput(String[] allLines, double windowWidth, double windowHeight)
|
|
|
+ {
|
|
|
+ i = 0;
|
|
|
+ if (allLines.Length == 0)
|
|
|
+ {
|
|
|
+ throw new FileImporterException("file is empty", "", -1);
|
|
|
+ }
|
|
|
+ var sizedef = ParseSVGHeader(allLines);
|
|
|
+ i++;
|
|
|
+ int width;
|
|
|
+ int height;
|
|
|
+ if (windowWidth != 0 && windowHeight != 0)
|
|
|
+ {
|
|
|
+ if (windowWidth / windowHeight > sizedef.Item1 / sizedef.Item2)
|
|
|
+ {
|
|
|
+ scale = windowHeight / sizedef.Item2;
|
|
|
+ height = (int)Math.Round(windowHeight);
|
|
|
+ width = (int)Math.Round(scale * sizedef.Item1);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ scale = windowWidth / sizedef.Item1;
|
|
|
+ width = (int)Math.Round(windowWidth);
|
|
|
+ height = (int)Math.Round(scale * sizedef.Item2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ scale = 1;
|
|
|
+ width = sizedef.Item1;
|
|
|
+ height = sizedef.Item2;
|
|
|
+ }
|
|
|
+ for (int j = 0; j < allLines.Length; j++)
|
|
|
+ {
|
|
|
+ allLines[j] = allLines[j].Trim(whitespaces);
|
|
|
+ }
|
|
|
+ List<InternalLine> picture = ParseSVGBody(allLines);
|
|
|
+ return new Tuple<int, int, List<InternalLine>>(width, height, picture);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<int, int> ParseSVGHeader(String[] allLines)
|
|
|
+ {
|
|
|
+ while (!allLines[i].StartsWith("<svg"))
|
|
|
+ {
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ String[] currentLine = allLines[i].Split(' ');
|
|
|
+ int width = -1;
|
|
|
+ int height = -1;
|
|
|
+ for (int j = 0; j < currentLine.Length; j++)
|
|
|
+ {
|
|
|
+ if (currentLine[j].StartsWith("width"))
|
|
|
+ {
|
|
|
+ width = Convert.ToInt32(ParseSingleSVGAttribute(currentLine[j]));
|
|
|
+ }
|
|
|
+ else if (currentLine[j].StartsWith("height"))
|
|
|
+ {
|
|
|
+ height = Convert.ToInt32(ParseSingleSVGAttribute(currentLine[j]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (width == -1)
|
|
|
+ {
|
|
|
+ throw new FileImporterException("missing width definition in SVG header", "the header should contain the \"width=...\" attribute", i + 1);
|
|
|
+ }
|
|
|
+ if (height == -1)
|
|
|
+ {
|
|
|
+ throw new FileImporterException("missing height definition in SVG header", "the header should contain the \"height=...\" attribute", i + 1);
|
|
|
+ }
|
|
|
+ return new Tuple<int, int>(width, height);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<InternalLine> ParseSVGBody(String[] allLines)
|
|
|
+ {
|
|
|
+ List<InternalLine> picture = new List<InternalLine>();
|
|
|
+ while (!allLines[i].StartsWith("</svg"))
|
|
|
+ {
|
|
|
+ List<InternalLine> element = ParseSingleSVGElement(allLines);
|
|
|
+ if (element != null)
|
|
|
+ {
|
|
|
+ picture.AddRange(element);
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ if (i > allLines.Length - 1) throw new FileImporterException("unterminated input file: missing </svg> tag", "the file must not contain empty lines", i + 1);
|
|
|
+ }
|
|
|
+ return picture;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<InternalLine> ParseSingleSVGElement(string[] allLines)
|
|
|
+ {
|
|
|
+ String[] currentElement = GetCurrentElement(allLines);
|
|
|
+ return ParseSingleLineSVGElement(currentElement);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<InternalLine> ParseSingleLineSVGElement(string[] currentElement)
|
|
|
+ {
|
|
|
+ List<Point> points = null;
|
|
|
+ List<InternalLine> element = null;
|
|
|
+ switch (currentElement[0])
|
|
|
+ {
|
|
|
+ case "<rect":
|
|
|
+ points = ParseRect(currentElement);
|
|
|
+ break;
|
|
|
+ case "<circle":
|
|
|
+ points = ParseCircle(currentElement);
|
|
|
+ break;
|
|
|
+ case "<ellipse":
|
|
|
+ points = ParseEllipse(currentElement);
|
|
|
+ break;
|
|
|
+ case "<line":
|
|
|
+ points = ParseLine(currentElement);
|
|
|
+ break;
|
|
|
+ case "<polyline":
|
|
|
+ points = ParsePolyline(currentElement);
|
|
|
+ break;
|
|
|
+ case "<polygon":
|
|
|
+ points = ParsePolygon(currentElement);
|
|
|
+ break;
|
|
|
+ case "<path":
|
|
|
+ element = ParsePath(currentElement);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (element == null)
|
|
|
+ {
|
|
|
+ element = new List<InternalLine>();
|
|
|
+ element.Add(new InternalLine(points));
|
|
|
+ }
|
|
|
+ return element;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> ParseRect(string[] currentElement)
|
|
|
+ {
|
|
|
+ double x = 0;
|
|
|
+ double y = 0;
|
|
|
+ double w = 0;
|
|
|
+ double h = 0;
|
|
|
+ double rx = 0;
|
|
|
+ double ry = 0;
|
|
|
+ for (int j = 0; j < currentElement.Length; j++)
|
|
|
+ {
|
|
|
+ if (currentElement[j].StartsWith("x="))
|
|
|
+ {
|
|
|
+ x = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("y="))
|
|
|
+ {
|
|
|
+ y = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("width="))
|
|
|
+ {
|
|
|
+ w = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("height="))
|
|
|
+ {
|
|
|
+ h = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("rx="))
|
|
|
+ {
|
|
|
+ rx = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("ry="))
|
|
|
+ {
|
|
|
+ ry = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Point> rect = new List<Point>();
|
|
|
+ rect.Add(ScaleAndCreatePoint(x, y));
|
|
|
+ rect.Add(ScaleAndCreatePoint(x + w, y));
|
|
|
+ rect.Add(ScaleAndCreatePoint(x + w, y + h));
|
|
|
+ rect.Add(ScaleAndCreatePoint(x, y + h));
|
|
|
+ rect.Add(ScaleAndCreatePoint(x, y));
|
|
|
+ return rect;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> ParseCircle(string[] currentElement)
|
|
|
+ {
|
|
|
+ double x = 0;
|
|
|
+ double y = 0;
|
|
|
+ double r = 0;
|
|
|
+ for (int j = 0; j < currentElement.Length; j++)
|
|
|
+ {
|
|
|
+ if (currentElement[j].StartsWith("cx="))
|
|
|
+ {
|
|
|
+ x = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("cy="))
|
|
|
+ {
|
|
|
+ y = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("r="))
|
|
|
+ {
|
|
|
+ r = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return SampleEllipse(x, y, r, r);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> ParseEllipse(string[] currentElement)
|
|
|
+ {
|
|
|
+ double x = 0;
|
|
|
+ double y = 0;
|
|
|
+ double rx = 0;
|
|
|
+ double ry = 0;
|
|
|
+ for (int j = 0; j < currentElement.Length; j++)
|
|
|
+ {
|
|
|
+ if (currentElement[j].StartsWith("cx="))
|
|
|
+ {
|
|
|
+ x = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("cy="))
|
|
|
+ {
|
|
|
+ y = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("rx="))
|
|
|
+ {
|
|
|
+ rx = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("ry="))
|
|
|
+ {
|
|
|
+ ry = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return SampleEllipse(x, y, rx, ry);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> ParseLine(string[] currentElement)
|
|
|
+ {
|
|
|
+ double x1 = 0;
|
|
|
+ double y1 = 0;
|
|
|
+ double x2 = 0;
|
|
|
+ double y2 = 0;
|
|
|
+ for (int j = 0; j < currentElement.Length; j++)
|
|
|
+ {
|
|
|
+ if (currentElement[j].StartsWith("x1="))
|
|
|
+ {
|
|
|
+ x1 = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("y1="))
|
|
|
+ {
|
|
|
+ y1 = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("x2="))
|
|
|
+ {
|
|
|
+ x2 = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ else if (currentElement[j].StartsWith("y2="))
|
|
|
+ {
|
|
|
+ y2 = Convert.ToDouble(ParseSingleSVGAttribute(currentElement[j]), CultureInfo.InvariantCulture);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Point> line = new List<Point>();
|
|
|
+ line.Add(ScaleAndCreatePoint(x1, y1));
|
|
|
+ line.Add(ScaleAndCreatePoint(x2, y2));
|
|
|
+ return line;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> ParsePolyline(string[] currentElement)
|
|
|
+ {
|
|
|
+ String[] points = null;
|
|
|
+ for (int j = 0; j < currentElement.Length; j++)
|
|
|
+ {
|
|
|
+ if (currentElement[j].StartsWith("points="))
|
|
|
+ {
|
|
|
+ List<String> pointDefs = new List<string>();
|
|
|
+ pointDefs.Add(currentElement[j].Substring(8));
|
|
|
+ j++;
|
|
|
+ while (!currentElement[j].EndsWith("\""))
|
|
|
+ {
|
|
|
+ pointDefs.Add(currentElement[j]);
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ pointDefs.Add(currentElement[j].Trim('"'));
|
|
|
+ points = pointDefs.ToArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Point> polyline = new List<Point>();
|
|
|
+ for (int k = 0; k < points.Length - 1; k += 2)
|
|
|
+ {
|
|
|
+ polyline.Add(ScaleAndCreatePoint(Convert.ToDouble(points[k], CultureInfo.InvariantCulture), Convert.ToDouble(points[k + 1], CultureInfo.InvariantCulture)));
|
|
|
+ }
|
|
|
+ return polyline;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> ParsePolygon(string[] currentElement)
|
|
|
+ {
|
|
|
+ String[] points = null;
|
|
|
+ for (int j = 0; j < currentElement.Length; j++)
|
|
|
+ {
|
|
|
+ if (currentElement[j].StartsWith("points="))
|
|
|
+ {
|
|
|
+ List<String> pointDefs = new List<string>();
|
|
|
+ pointDefs.Add(currentElement[j].Substring(8));
|
|
|
+ j++;
|
|
|
+ while (!currentElement[j].EndsWith("\""))
|
|
|
+ {
|
|
|
+ pointDefs.Add(currentElement[j]);
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ pointDefs.Add(currentElement[j].Trim('"'));
|
|
|
+ points = pointDefs.ToArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Point> polygon = new List<Point>();
|
|
|
+ for (int k = 0; k < points.Length - 1; k += 2)
|
|
|
+ {
|
|
|
+ polygon.Add(ScaleAndCreatePoint(Convert.ToDouble(points[k], CultureInfo.InvariantCulture), Convert.ToDouble(points[k + 1], CultureInfo.InvariantCulture)));
|
|
|
+ }
|
|
|
+ polygon.Add(ScaleAndCreatePoint(Convert.ToDouble(points[0], CultureInfo.InvariantCulture), Convert.ToDouble(points[1], CultureInfo.InvariantCulture)));
|
|
|
+ return polygon;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<InternalLine> ParsePath(string[] currentElement)
|
|
|
+ {
|
|
|
+ List<String> pathElements = new List<string>();
|
|
|
+ for (int j = 0; j < currentElement.Length; j++)
|
|
|
+ {
|
|
|
+ if (currentElement[j].StartsWith("d="))
|
|
|
+ {
|
|
|
+ pathElements.Add(currentElement[j].Substring(3));
|
|
|
+ j++;
|
|
|
+ while (!currentElement[j].EndsWith("\""))
|
|
|
+ {
|
|
|
+ pathElements.Add(currentElement[j]);
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ pathElements.Add(currentElement[j].Trim('"'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ NormalizePathDeclaration(pathElements);
|
|
|
+ List<InternalLine> element = new List<InternalLine>();
|
|
|
+ List<Point> currentLine = new List<Point>();
|
|
|
+ double lastBezierControlPointX = 0;
|
|
|
+ double lastBezierControlPointY = 0;
|
|
|
+ double lastPositionX;
|
|
|
+ double lastPositionY;
|
|
|
+ double initialPositionX = -1;
|
|
|
+ double initialPositionY = -1;
|
|
|
+ bool newSubpath = true;
|
|
|
+ Tuple<List<Point>, double, double> valuesArc;
|
|
|
+ Tuple<List<Point>, double, double, double, double> valuesBezierCurve;
|
|
|
+ var valuesSinglePoint = Parse_M_L(pathElements);
|
|
|
+ currentLine = new List<Point>();
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ String currentToken;
|
|
|
+ while (!(pathElements.Count == 0))
|
|
|
+ {
|
|
|
+ if (newSubpath)
|
|
|
+ {
|
|
|
+ initialPositionX = lastPositionX;
|
|
|
+ initialPositionY = lastPositionY;
|
|
|
+ newSubpath = false;
|
|
|
+ }
|
|
|
+ currentToken = pathElements.First();
|
|
|
+ if (currentToken.Equals("M"))
|
|
|
+ {
|
|
|
+ element.Add(new InternalLine(currentLine));
|
|
|
+ valuesSinglePoint = Parse_M_L(pathElements);
|
|
|
+ currentLine = new List<Point>();
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("m"))
|
|
|
+ {
|
|
|
+ element.Add(new InternalLine(currentLine));
|
|
|
+ valuesSinglePoint = Parse_m_l(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine = new List<Point>();
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("Z") || currentToken.Equals("z"))
|
|
|
+ {
|
|
|
+ valuesSinglePoint = Parse_Z(pathElements, initialPositionX, initialPositionY);
|
|
|
+ newSubpath = true;
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ element.Add(new InternalLine(currentLine));
|
|
|
+ currentLine = new List<Point>();
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("L"))
|
|
|
+ {
|
|
|
+ valuesSinglePoint = Parse_M_L(pathElements);
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("l"))
|
|
|
+ {
|
|
|
+ valuesSinglePoint = Parse_m_l(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("H"))
|
|
|
+ {
|
|
|
+ valuesSinglePoint = Parse_H(pathElements, lastPositionY);
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("h"))
|
|
|
+ {
|
|
|
+ valuesSinglePoint = Parse_h(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("V"))
|
|
|
+ {
|
|
|
+ valuesSinglePoint = Parse_V(pathElements, lastPositionX);
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("v"))
|
|
|
+ {
|
|
|
+ valuesSinglePoint = Parse_v(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine.Add(valuesSinglePoint.Item1);
|
|
|
+ lastPositionX = valuesSinglePoint.Item2;
|
|
|
+ lastPositionY = valuesSinglePoint.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("C"))
|
|
|
+ {
|
|
|
+ valuesBezierCurve = Parse_C(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine.AddRange(valuesBezierCurve.Item1);
|
|
|
+ lastPositionX = valuesBezierCurve.Item2;
|
|
|
+ lastPositionY = valuesBezierCurve.Item3;
|
|
|
+ lastBezierControlPointX = valuesBezierCurve.Item4;
|
|
|
+ lastBezierControlPointY = valuesBezierCurve.Item5;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("c"))
|
|
|
+ {
|
|
|
+ valuesBezierCurve = Parse_C(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine.AddRange(valuesBezierCurve.Item1);
|
|
|
+ lastPositionX = valuesBezierCurve.Item2;
|
|
|
+ lastPositionY = valuesBezierCurve.Item3;
|
|
|
+ lastBezierControlPointX = valuesBezierCurve.Item4;
|
|
|
+ lastBezierControlPointY = valuesBezierCurve.Item5;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("S"))
|
|
|
+ {
|
|
|
+ valuesBezierCurve = Parse_S(pathElements, lastPositionX, lastPositionY, lastBezierControlPointX, lastBezierControlPointY);
|
|
|
+ currentLine.AddRange(valuesBezierCurve.Item1);
|
|
|
+ lastPositionX = valuesBezierCurve.Item2;
|
|
|
+ lastPositionY = valuesBezierCurve.Item3;
|
|
|
+ lastBezierControlPointX = valuesBezierCurve.Item4;
|
|
|
+ lastBezierControlPointY = valuesBezierCurve.Item5;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("s"))
|
|
|
+ {
|
|
|
+ valuesBezierCurve = Parse_s(pathElements, lastPositionX, lastPositionY, lastBezierControlPointX, lastBezierControlPointY);
|
|
|
+ currentLine.AddRange(valuesBezierCurve.Item1);
|
|
|
+ lastPositionX = valuesBezierCurve.Item2;
|
|
|
+ lastPositionY = valuesBezierCurve.Item3;
|
|
|
+ lastBezierControlPointX = valuesBezierCurve.Item4;
|
|
|
+ lastBezierControlPointY = valuesBezierCurve.Item5;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("Q"))
|
|
|
+ {
|
|
|
+ valuesBezierCurve = Parse_Q(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine.AddRange(valuesBezierCurve.Item1);
|
|
|
+ lastPositionX = valuesBezierCurve.Item2;
|
|
|
+ lastPositionY = valuesBezierCurve.Item3;
|
|
|
+ lastBezierControlPointX = valuesBezierCurve.Item4;
|
|
|
+ lastBezierControlPointY = valuesBezierCurve.Item5;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("q"))
|
|
|
+ {
|
|
|
+ valuesBezierCurve = Parse_q(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine.AddRange(valuesBezierCurve.Item1);
|
|
|
+ lastPositionX = valuesBezierCurve.Item2;
|
|
|
+ lastPositionY = valuesBezierCurve.Item3;
|
|
|
+ lastBezierControlPointX = valuesBezierCurve.Item4;
|
|
|
+ lastBezierControlPointY = valuesBezierCurve.Item5;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("T"))
|
|
|
+ {
|
|
|
+ valuesBezierCurve = Parse_T(pathElements, lastPositionX, lastPositionY, lastBezierControlPointX, lastBezierControlPointY);
|
|
|
+ currentLine.AddRange(valuesBezierCurve.Item1);
|
|
|
+ lastPositionX = valuesBezierCurve.Item2;
|
|
|
+ lastPositionY = valuesBezierCurve.Item3;
|
|
|
+ lastBezierControlPointX = valuesBezierCurve.Item4;
|
|
|
+ lastBezierControlPointY = valuesBezierCurve.Item5;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("t"))
|
|
|
+ {
|
|
|
+ valuesBezierCurve = Parse_t(pathElements, lastPositionX, lastPositionY, lastBezierControlPointX, lastBezierControlPointY);
|
|
|
+ currentLine.AddRange(valuesBezierCurve.Item1);
|
|
|
+ lastPositionX = valuesBezierCurve.Item2;
|
|
|
+ lastPositionY = valuesBezierCurve.Item3;
|
|
|
+ lastBezierControlPointX = valuesBezierCurve.Item4;
|
|
|
+ lastBezierControlPointY = valuesBezierCurve.Item5;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("A"))
|
|
|
+ {
|
|
|
+ valuesArc = Parse_A(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine.AddRange(valuesArc.Item1);
|
|
|
+ lastPositionX = valuesArc.Item2;
|
|
|
+ lastPositionY = valuesArc.Item3;
|
|
|
+ }
|
|
|
+ else if (currentToken.Equals("a"))
|
|
|
+ {
|
|
|
+ valuesArc = Parse_a(pathElements, lastPositionX, lastPositionY);
|
|
|
+ currentLine.AddRange(valuesArc.Item1);
|
|
|
+ lastPositionX = valuesArc.Item2;
|
|
|
+ lastPositionY = valuesArc.Item3;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new FileImporterException("invalid path argument or path data formatting: read argument " + pathElements.First(), "valid path arguments are: {M,Z,L,H,V,C,S,Q,T,A} in upper and lower case", i + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (currentLine.Count > 1)
|
|
|
+ {
|
|
|
+ element.Add(new InternalLine(currentLine));
|
|
|
+ }
|
|
|
+ return element;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void NormalizePathDeclaration(List<string> pathElements)
|
|
|
+ {
|
|
|
+ Char lastCommand = 'M';
|
|
|
+ int argumentCounter = 0;
|
|
|
+ for (int j = 0; j < pathElements.Count; j++)
|
|
|
+ {
|
|
|
+ String currentElement = pathElements.ElementAt(j);
|
|
|
+ if (currentElement.Length != 1)
|
|
|
+ {
|
|
|
+ if (((currentElement.First() >= 'A' && currentElement.First() <= 'Z') || (currentElement.First() >= 'a' && currentElement.First() <= 'z')) && currentElement.First() != 'e')
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(j);
|
|
|
+ pathElements.Insert(j, currentElement.First() + "");
|
|
|
+ pathElements.Insert(j + 1, currentElement.Substring(1));
|
|
|
+ lastCommand = currentElement.First();
|
|
|
+ argumentCounter = 0;
|
|
|
+ }
|
|
|
+ else if ((currentElement.First() >= '0' && currentElement.First() <= '9') || currentElement.First() == '-' || currentElement.First() == '+' || currentElement.First() != 'e')
|
|
|
+ {
|
|
|
+ bool repeatCommandDescriptor = false;
|
|
|
+ switch (lastCommand)
|
|
|
+ {
|
|
|
+ case 'M':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'm':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'L':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'l':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'V':
|
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'v':
|
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'H':
|
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'h':
|
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'C':
|
|
|
+ if (argumentCounter >= 6) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'c':
|
|
|
+ if (argumentCounter >= 6) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'S':
|
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 's':
|
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'Q':
|
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'q':
|
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'T':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 't':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'A':
|
|
|
+ if (argumentCounter >= 7) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'a':
|
|
|
+ if (argumentCounter >= 7) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (repeatCommandDescriptor)
|
|
|
+ {
|
|
|
+ pathElements.Insert(j, lastCommand + "");
|
|
|
+ j++;
|
|
|
+ argumentCounter = 0;
|
|
|
+ }
|
|
|
+ bool decimalPointEncountered = false;
|
|
|
+ for (int k = 1; k < currentElement.Length; k++)
|
|
|
+ {
|
|
|
+ if (!decimalPointEncountered && currentElement.ElementAt(k) == '.')
|
|
|
+ {
|
|
|
+ decimalPointEncountered = true;
|
|
|
+ }
|
|
|
+ else if (!((currentElement.ElementAt(k) >= '0' && currentElement.ElementAt(k) <= '9') || currentElement.First() == '-' || currentElement.First() == '+' || currentElement.First() != 'e'))
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(j);
|
|
|
+ pathElements.Insert(j, currentElement.Substring(0, k - 1));
|
|
|
+ pathElements.Insert(j + 1, currentElement.Substring(k));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ argumentCounter++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (int k = 1; k < currentElement.Length; k++)
|
|
|
+ {
|
|
|
+ if (((currentElement.ElementAt(k) >= '0' && currentElement.ElementAt(k) <= '9')) || currentElement.ElementAt(k) == '-' || currentElement.ElementAt(k) == '+' || (currentElement.ElementAt(k) >= 'A' && currentElement.ElementAt(k) <= 'Z') || (currentElement.ElementAt(k) >= 'a' && currentElement.ElementAt(k) <= 'z'))
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(j);
|
|
|
+ pathElements.Insert(j + 1, currentElement.Substring(k));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if ((currentElement.First() >= 'A' && currentElement.First() <= 'Z') || (currentElement.First() >= 'a' && currentElement.First() <= 'z'))
|
|
|
+ {
|
|
|
+ lastCommand = currentElement.First();
|
|
|
+ argumentCounter = 0;
|
|
|
+ }
|
|
|
+ else if (!(currentElement.First() >= '0' && currentElement.First() <= '9'))
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(j);
|
|
|
+ j--;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bool repeatCommandDescriptor = false;
|
|
|
+ switch (lastCommand)
|
|
|
+ {
|
|
|
+ case 'M':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'm':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'L':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'l':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'V':
|
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'v':
|
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'H':
|
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'h':
|
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'C':
|
|
|
+ if (argumentCounter >= 6) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'c':
|
|
|
+ if (argumentCounter >= 6) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'S':
|
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 's':
|
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'Q':
|
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'q':
|
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'T':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 't':
|
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'A':
|
|
|
+ if (argumentCounter >= 7) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ case 'a':
|
|
|
+ if (argumentCounter >= 7) repeatCommandDescriptor = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (repeatCommandDescriptor)
|
|
|
+ {
|
|
|
+ pathElements.Insert(j, lastCommand + "");
|
|
|
+ j++;
|
|
|
+ argumentCounter = 0;
|
|
|
+ }
|
|
|
+ argumentCounter++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<Point, double, double> Parse_Z(List<string> pathElements, double initialPositionX, double initialPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ return new Tuple<Point, double, double>(ScaleAndCreatePoint(initialPositionX, initialPositionY), initialPositionX, initialPositionY);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<Point, double, double> Parse_M_L(List<string> pathElements)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ return new Tuple<Point, double, double>(ScaleAndCreatePoint(x, y), x, y);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<Point, double, double> Parse_m_l(List<string> pathElements, double lastPositionX, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ x = lastPositionX + x;
|
|
|
+ y = lastPositionY + y;
|
|
|
+ return new Tuple<Point, double, double>(ScaleAndCreatePoint(x, y), x, y);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<Point, double, double> Parse_H(List<string> pathElements, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ return new Tuple<Point, double, double>(ScaleAndCreatePoint(x, lastPositionY), x, lastPositionY);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<Point, double, double> Parse_h(List<string> pathElements, double lastPositionX, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ x = lastPositionX + x;
|
|
|
+ return new Tuple<Point, double, double>(ScaleAndCreatePoint(x, lastPositionY), x, lastPositionY);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<Point, double, double> Parse_V(List<string> pathElements, double lastPositionX)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ return new Tuple<Point, double, double>(ScaleAndCreatePoint(lastPositionX, y), lastPositionX, y);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<Point, double, double> Parse_v(List<string> pathElements, double lastPositionX, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ y = lastPositionY + y;
|
|
|
+ return new Tuple<Point, double, double>(ScaleAndCreatePoint(lastPositionX, y), lastPositionX, y);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double, double, double> Parse_C(List<string> pathElements, double lastPositionX, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x1 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y1 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x2 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y2 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ return new Tuple<List<Point>, double, double, double, double>(SampleCubicBezier(lastPositionX, lastPositionY, x1, y1, x2, y2, x, y), x, y, x2, y2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double, double, double> Parse_c(List<string> pathElements, double lastPositionX, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x1 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y1 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x2 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y2 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ x1 = lastPositionX + x1;
|
|
|
+ y1 = lastPositionY + y1;
|
|
|
+ x2 = lastPositionX + x2;
|
|
|
+ y2 = lastPositionY + y2;
|
|
|
+ x = lastPositionX + x;
|
|
|
+ y = lastPositionY + y;
|
|
|
+ return new Tuple<List<Point>, double, double, double, double>(SampleCubicBezier(lastPositionX, lastPositionY, x1, y1, x2, y2, x, y), x, y, x2, y2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double, double, double> Parse_S(List<string> pathElements, double lastPositionX, double lastPositionY, double lastBezierControlPointX, double lastBezierControlPointY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x2 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y2 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x1 = lastPositionX + (lastPositionX - lastBezierControlPointX);
|
|
|
+ double y1 = lastPositionY + (lastPositionY - lastBezierControlPointY);
|
|
|
+ return new Tuple<List<Point>, double, double, double, double>(SampleCubicBezier(lastPositionX, lastPositionY, x1, y1, x2, y2, x, y), x, y, x2, y2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double, double, double> Parse_s(List<string> pathElements, double lastPositionX, double lastPositionY, double lastBezierControlPointX, double lastBezierControlPointY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x2 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y2 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x1 = lastPositionX + (lastPositionX - lastBezierControlPointX);
|
|
|
+ double y1 = lastPositionY + (lastPositionY - lastBezierControlPointY);
|
|
|
+ x2 = lastPositionX + x2;
|
|
|
+ y2 = lastPositionY + y2;
|
|
|
+ x = lastPositionX + x;
|
|
|
+ y = lastPositionY + y;
|
|
|
+ return new Tuple<List<Point>, double, double, double, double>(SampleCubicBezier(lastPositionX, lastPositionY, x1, y1, x2, y2, x, y), x, y, x2, y2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double, double, double> Parse_Q(List<string> pathElements, double lastPositionX, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x1 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y1 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ return new Tuple<List<Point>, double, double, double, double>(SampleQuadraticBezier(lastPositionX, lastPositionY, x1, y1, x, y), x, y, x1, y1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double, double, double> Parse_q(List<string> pathElements, double lastPositionX, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x1 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y1 = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ x1 = lastPositionX + x1;
|
|
|
+ y1 = lastPositionY + y1;
|
|
|
+ x = lastPositionX + x;
|
|
|
+ y = lastPositionY + y;
|
|
|
+ return new Tuple<List<Point>, double, double, double, double>(SampleQuadraticBezier(lastPositionX, lastPositionY, x1, y1, x, y), x, y, x1, y1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double, double, double> Parse_T(List<string> pathElements, double lastPositionX, double lastPositionY, double lastBezierControlPointX, double lastBezierControlPointY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x1 = lastPositionX + (lastPositionX - lastBezierControlPointX);
|
|
|
+ double y1 = lastPositionY + (lastPositionY - lastBezierControlPointY);
|
|
|
+ return new Tuple<List<Point>, double, double, double, double>(SampleQuadraticBezier(lastPositionX, lastPositionY, x1, y1, x, y), x, y, x1, y1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double, double, double> Parse_t(List<string> pathElements, double lastPositionX, double lastPositionY, double lastBezierControlPointX, double lastBezierControlPointY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ x = lastPositionX + x;
|
|
|
+ y = lastPositionY + y;
|
|
|
+ double x1 = lastPositionX + (lastPositionX - lastBezierControlPointX);
|
|
|
+ double y1 = lastPositionY + (lastPositionY - lastBezierControlPointY);
|
|
|
+ return new Tuple<List<Point>, double, double, double, double>(SampleQuadraticBezier(lastPositionX, lastPositionY, x1, y1, x, y), x, y, x1, y1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double> Parse_A(List<string> pathElements, double lastPositionX, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double rx = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double ry = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double thetha = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ bool largeArcFlag = Convert.ToInt16(pathElements.First()) == 1 ? true : false;
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ bool sweepFlag = Convert.ToInt16(pathElements.First()) == 1 ? true : false;
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ x = x - lastPositionX;
|
|
|
+ y = y - lastPositionY;
|
|
|
+ return new Tuple<List<Point>, double, double>(SampleArc(lastPositionX, lastPositionY, rx, ry, x, y, thetha, largeArcFlag, sweepFlag), x, y);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<List<Point>, double, double> Parse_a(List<string> pathElements, double lastPositionX, double lastPositionY)
|
|
|
+ {
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double rx = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double ry = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double thetha = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ bool largeArcFlag = Convert.ToInt16(pathElements.First()) == 1 ? true : false;
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ bool sweepFlag = Convert.ToInt16(pathElements.First()) == 1 ? true : false;
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double x = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ double y = Convert.ToDouble(pathElements.First(), CultureInfo.InvariantCulture);
|
|
|
+ pathElements.RemoveAt(0);
|
|
|
+ return new Tuple<List<Point>, double, double>(SampleArc(lastPositionX, lastPositionY, rx, ry, x, y, thetha, largeArcFlag, sweepFlag), x, y);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> SampleArc(double lastPositionX, double lastPositionY, double rx, double ry, double nextPositionXRelative, double nextPositionYRelative, double thetha, bool largeArcFlag, bool sweepFlag)
|
|
|
+ {
|
|
|
+ double cos = Math.Cos(thetha / 180 * Math.PI);
|
|
|
+ double sin = Math.Sin(thetha / 180 * Math.PI);
|
|
|
+ double targetXTransformed = cos * nextPositionXRelative - sin * nextPositionYRelative;
|
|
|
+ double targetYTransformed = sin * nextPositionXRelative + cos * nextPositionYRelative;
|
|
|
+ var values = SampleEllipticArcBiasedNoRotation(rx, ry, targetXTransformed, targetYTransformed, largeArcFlag, sweepFlag);
|
|
|
+ List<Point> result = new List<Point>();
|
|
|
+ for (int j = 0; j < values.Item1.Length; j++)
|
|
|
+ {
|
|
|
+ double xCoordinateRelative = cos * values.Item1[j] + sin * values.Item2[j];
|
|
|
+ double yCoordinateRelative = cos * values.Item2[j] - sin * values.Item1[j];
|
|
|
+ double xCoordinateAbsolute = lastPositionX + xCoordinateRelative;
|
|
|
+ double yCoordinateAbsolute = lastPositionY + yCoordinateRelative;
|
|
|
+ result.Add(ScaleAndCreatePoint(xCoordinateAbsolute, yCoordinateAbsolute));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<double[], double[]> SampleEllipticArcBiasedNoRotation(double rx, double ry, double targetXTransformed, double targetYTransformed, bool largeArcFlag, bool sweepFlag)
|
|
|
+ {
|
|
|
+ double xStretchFactor = rx / ry;
|
|
|
+ var values = SampleCircleArcBiasedNoRotation(ry, targetXTransformed / xStretchFactor, targetYTransformed, largeArcFlag, sweepFlag);
|
|
|
+ for (int j = 0; j < values.Item1.Length; j++)
|
|
|
+ {
|
|
|
+ values.Item1[j] = values.Item1[j] * xStretchFactor;
|
|
|
+ }
|
|
|
+ return values;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<double[], double[]> SampleCircleArcBiasedNoRotation(double r, double nextPositionXRelative, double nextPositionYRelative, bool largeArcFlag, bool sweepFlag)
|
|
|
+ {
|
|
|
+
|
|
|
+ double radsq = r * r;
|
|
|
+ double q = Math.Sqrt(((nextPositionXRelative) * (nextPositionXRelative)) + ((nextPositionYRelative) * (nextPositionYRelative)));
|
|
|
+ double x3 = (nextPositionXRelative) / 2;
|
|
|
+ double y3 = (nextPositionYRelative) / 2;
|
|
|
+ bool xPlusFlag;
|
|
|
+ bool yPlusFlag;
|
|
|
+ if (nextPositionXRelative > 0)
|
|
|
+ {
|
|
|
+ yPlusFlag = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ yPlusFlag = false;
|
|
|
+ }
|
|
|
+ if (nextPositionYRelative > 0)
|
|
|
+ {
|
|
|
+ xPlusFlag = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ xPlusFlag = true;
|
|
|
+ }
|
|
|
+ if (sweepFlag != largeArcFlag)
|
|
|
+ {
|
|
|
+ xPlusFlag = !xPlusFlag;
|
|
|
+ yPlusFlag = !yPlusFlag;
|
|
|
+ }
|
|
|
+ double xC;
|
|
|
+ double yC;
|
|
|
+ if (xPlusFlag) xC = x3 + Math.Sqrt(radsq - ((q / 2) * (q / 2))) * ((nextPositionYRelative) / q);
|
|
|
+ else xC = x3 - Math.Sqrt(radsq - ((q / 2) * (q / 2))) * ((nextPositionYRelative) / q);
|
|
|
+ if (yPlusFlag) yC = y3 + Math.Sqrt(radsq - ((q / 2) * (q / 2))) * ((nextPositionXRelative) / q);
|
|
|
+ else yC = y3 - Math.Sqrt(radsq - ((q / 2) * (q / 2))) * ((nextPositionXRelative) / q);
|
|
|
+ var values = SampleCircleArcBiasedAroundCenter(-xC, -yC, nextPositionXRelative - xC, nextPositionYRelative - yC, r, largeArcFlag, sweepFlag);
|
|
|
+ for (int j = 0; j < values.Item1.Length; j++)
|
|
|
+ {
|
|
|
+ values.Item1[j] = values.Item1[j] + xC;
|
|
|
+ values.Item2[j] = values.Item2[j] + yC;
|
|
|
+ }
|
|
|
+ return values;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<double[], double[]> SampleCircleArcBiasedAroundCenter(double xStartPoint, double yStartPoint, double xFinalPoint, double yFinalPoint, double r, bool largeArcFlag, bool clockwise)
|
|
|
+ {
|
|
|
+ double phiEnd = Math.Atan2(yFinalPoint, xFinalPoint);
|
|
|
+ double phiStart = Math.Atan2(yStartPoint, xStartPoint);
|
|
|
+ double angle = ((double)2 * Math.PI) / (double)samplingRateEllipse;
|
|
|
+ double angleDifference = Math.Abs(phiStart - phiEnd);
|
|
|
+ if (angleDifference > 2 * Math.PI || angleDifference < 0) throw new Exception("angleDifference out of range: " + angleDifference);
|
|
|
+ if (largeArcFlag)
|
|
|
+ {
|
|
|
+ if (angleDifference < Math.PI) angleDifference = ((double)2 * Math.PI) - angleDifference;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (angleDifference > Math.PI) angleDifference = ((double)2 * Math.PI) - angleDifference;
|
|
|
+ }
|
|
|
+ int numberOfPoints = (int)Math.Ceiling(angleDifference / angle);
|
|
|
+ double[] xValues = new double[numberOfPoints];
|
|
|
+ double[] yValues = new double[numberOfPoints];
|
|
|
+ double phiCurrent = phiStart;
|
|
|
+ for (int j = 0; j < numberOfPoints - 1; j++)
|
|
|
+ {
|
|
|
+ if (clockwise) phiCurrent -= angle;
|
|
|
+ else phiCurrent += angle;
|
|
|
+ yValues[j] = Math.Sin(phiCurrent) * r;
|
|
|
+ xValues[j] = Math.Cos(phiCurrent) * r;
|
|
|
+ }
|
|
|
+ xValues[numberOfPoints - 1] = xFinalPoint;
|
|
|
+ yValues[numberOfPoints - 1] = yFinalPoint;
|
|
|
+ return new Tuple<double[], double[]>(xValues, yValues);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> SampleCubicBezier(double lastPositionX, double lastPositionY, double controlPoint1X, double controlPoint1Y, double controlPoint2X, double controlPoint2Y, double nextPositionX, double nextPositionY)
|
|
|
+ {
|
|
|
+ var line1 = CreateDiscreteLine(lastPositionX, lastPositionY, controlPoint1X, controlPoint1Y);
|
|
|
+ var line2 = CreateDiscreteLine(controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y);
|
|
|
+ var line3 = CreateDiscreteLine(controlPoint2X, controlPoint2Y, nextPositionX, nextPositionY);
|
|
|
+ var quadraticBezier1 = ComputeBezierStep(line1.Item1, line1.Item2, line2.Item1, line2.Item2);
|
|
|
+ var quadraticBezier2 = ComputeBezierStep(line2.Item1, line2.Item2, line3.Item1, line3.Item2);
|
|
|
+ var values = ComputeBezierStep(quadraticBezier1.Item1, quadraticBezier1.Item2, quadraticBezier2.Item1, quadraticBezier2.Item2);
|
|
|
+ List<Point> result = new List<Point>();
|
|
|
+ for (int j = 0; j < samplingRateBezier; j++)
|
|
|
+ {
|
|
|
+ result.Add(ScaleAndCreatePoint(values.Item1[j], values.Item2[j]));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> SampleQuadraticBezier(double lastPositionX, double lastPositionY, double controlPointX, double controlPointY, double nextPositionX, double nextPositionY)
|
|
|
+ {
|
|
|
+ var line1 = CreateDiscreteLine(lastPositionX, lastPositionY, controlPointX, controlPointY);
|
|
|
+ var line2 = CreateDiscreteLine(controlPointX, controlPointY, nextPositionX, nextPositionY);
|
|
|
+ var values = ComputeBezierStep(line1.Item1, line1.Item2, line2.Item1, line2.Item2);
|
|
|
+ List<Point> result = new List<Point>();
|
|
|
+ for (int j = 0; j < samplingRateBezier; j++)
|
|
|
+ {
|
|
|
+ result.Add(ScaleAndCreatePoint(values.Item1[j], values.Item2[j]));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<double[], double[]> CreateDiscreteLine(double point1X, double point1Y, double point2X, double point2Y)
|
|
|
+ {
|
|
|
+ double[] resultX = new double[samplingRateBezier];
|
|
|
+ double[] resultY = new double[samplingRateBezier];
|
|
|
+ for (int j = 0; j < samplingRateBezier; j++)
|
|
|
+ {
|
|
|
+ var pointResult = LinearInterpolationForBezier(point1X, point1Y, point2X, point2Y, j);
|
|
|
+ resultX[j] = pointResult.Item1;
|
|
|
+ resultY[j] = pointResult.Item2;
|
|
|
+ }
|
|
|
+ return new Tuple<double[], double[]>(resultX, resultY);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<double[], double[]> ComputeBezierStep(double[] line1X, double[] line1Y, double[] line2X, double[] line2Y)
|
|
|
+ {
|
|
|
+ double[] resultX = new double[samplingRateBezier];
|
|
|
+ double[] resultY = new double[samplingRateBezier];
|
|
|
+ for (int j = 0; j < samplingRateBezier; j++)
|
|
|
+ {
|
|
|
+ var pointResult = LinearInterpolationForBezier(line1X[j], line1Y[j], line2X[j], line2Y[j], j);
|
|
|
+ resultX[j] = pointResult.Item1;
|
|
|
+ resultY[j] = pointResult.Item2;
|
|
|
+ }
|
|
|
+ return new Tuple<double[], double[]>(resultX, resultY);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Tuple<double, double> LinearInterpolationForBezier(double point1X, double point1Y, double point2X, double point2Y, int j)
|
|
|
+ {
|
|
|
+ double factor = ((double)1 / (double)(samplingRateBezier - 1)) * (double)j;
|
|
|
+ double x = point1X + ((point2X - point1X) * factor);
|
|
|
+ double y = point1Y + ((point2Y - point1Y) * factor);
|
|
|
+ return new Tuple<double, double>(x, y);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<InternalLine> ParseMultiLineSVGElement(string[] currentElement, string[] allLines)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private String ParseSingleSVGAttribute(String definition)
|
|
|
+ {
|
|
|
+ return definition.Split('"')[1];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private String[] GetCurrentElement(String[] allLines)
|
|
|
+ {
|
|
|
+ List<String> currentElementTemp = allLines[i].Split(whitespaces).ToList();
|
|
|
+ while (!currentElementTemp.Last().EndsWith(">"))
|
|
|
+ {
|
|
|
+ i++;
|
|
|
+ currentElementTemp.AddRange(allLines[i].Split(whitespaces).ToList());
|
|
|
+ }
|
|
|
+ return currentElementTemp.ToArray();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Point ScaleAndCreatePoint(double x, double y)
|
|
|
+ {
|
|
|
+ return new Point((int)Math.Round(x * scale), (int)Math.Round(y * scale));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Point> SampleEllipse(double x, double y, double rx, double ry)
|
|
|
+ {
|
|
|
+ List<Point> ellipse = new List<Point>();
|
|
|
+ double angle = ((double)2 * Math.PI) / (double)samplingRateEllipse;
|
|
|
+ double yScale = ry / rx;
|
|
|
+ double[] xValues = new double[samplingRateEllipse / 4];
|
|
|
+ double[] yValues = new double[samplingRateEllipse / 4];
|
|
|
+ for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
|
+ {
|
|
|
+ xValues[j] = Math.Sin((double)j * angle) * rx;
|
|
|
+ yValues[j] = Math.Cos((double)j * angle) * rx;
|
|
|
+ }
|
|
|
+ for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
|
+ {
|
|
|
+ int xCoord = Convert.ToInt32(Math.Round(x + xValues[j]));
|
|
|
+ int yCoord = Convert.ToInt32(Math.Round(y - yValues[j] * yScale));
|
|
|
+ ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
|
+ }
|
|
|
+ for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
|
+ {
|
|
|
+ int xCoord = Convert.ToInt32(Math.Round(x + yValues[j]));
|
|
|
+ int yCoord = Convert.ToInt32(Math.Round(y + xValues[j] * yScale));
|
|
|
+ ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
|
+ }
|
|
|
+ for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
|
+ {
|
|
|
+ int xCoord = Convert.ToInt32(Math.Round(x - xValues[j]));
|
|
|
+ int yCoord = Convert.ToInt32(Math.Round(y + yValues[j] * yScale));
|
|
|
+ ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
|
+ }
|
|
|
+ for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
|
+ {
|
|
|
+ int xCoord = Convert.ToInt32(Math.Round(x - yValues[j]));
|
|
|
+ int yCoord = Convert.ToInt32(Math.Round(y - xValues[j] * yScale));
|
|
|
+ ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
|
+ }
|
|
|
+ ellipse.Add(ScaleAndCreatePoint(Convert.ToInt32(Math.Round(x + 0)), Convert.ToInt32(Math.Round(y - rx * yScale))));
|
|
|
+ return ellipse;
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|