CodeConnect/TouchVS

Geometry.Parse is failing

SaphuA opened this issue · 3 comments

Geometry.Parse is failing on my machine. Any idea why?

    public static Geometry GetSegment(int totalSegments, int index) // totalSegments = 5, index = 0
    {
        var arcAngle = FULL_CIRCLE / totalSegments; // 72
        var startAngle = -arcAngle / 2 + index * arcAngle; // -36
        var endAngle = startAngle + arcAngle; // 36
        var point1 = ToCartesian(startAngle, OUTER_RADIUS); // {74,1986545873549;34,3769410125095}
        var point2 = ToCartesian(endAngle, OUTER_RADIUS); // {285,801345412645;34,3769410125095}
        var point3 = ToCartesian(endAngle, INNER_RADIUS); // {209,389262614624;139,549150281253}
        var point4 = ToCartesian(startAngle, INNER_RADIUS); // {150,610737385376;139,549150281253}
        var pathDefinition = $"M {point1.X} {point1.Y} A {OUTER_RADIUS} {OUTER_RADIUS} 0 0 1 {point2.X} {point2.Y} L {point3.X} {point3.Y} A {INNER_RADIUS} {INNER_RADIUS} 0 0 0 {point4.X} {point4.Y} z";
        // M 74,1986545873549 34,3769410125095 A 180 180 0 0 1 285,801345412645 34,3769410125095 L 209,389262614624 139,549150281253 A 50 50 0 0 0 150,610737385376 139,549150281253 z
        var geometry = Geometry.Parse(pathDefinition);  // throws exception
        return geometry;
    }

This is the exception:

Unexpected token 'M 74,1986545873549 34,3769410125095 A 180 180 0 0 1 285,801345412645 34,3769410125095 L 209,389262614624 139,549150281253 A 50 50 0 0 0 150,610737385376 139,549150281253 z' encountered at position '85'.

Position 85 is the L character.

It happens because your machine's decimal separator is , while Geometry.Parse expects .

Let me know if #8 fixes it

Yes it's fixed. Good job!