Browse Source

tmp: geometry pase/tostring pr:3367 - merged

add failing test for Geometry Parse -> it should be expected result be PathGeometry (as in WPF)
add failing tests for PathGeometry.ToString()
fix Geometry.Parse create PathGeometry
make PathGeometry.ToString work properly
Andrey Kunchev 6 years ago
parent
commit
dd6a28d187
  1. 5
      src/Avalonia.Visuals/Media/ArcSegment.cs
  2. 3
      src/Avalonia.Visuals/Media/BezierSegment .cs
  3. 2
      src/Avalonia.Visuals/Media/Geometry.cs
  4. 3
      src/Avalonia.Visuals/Media/LineSegment.cs
  5. 3
      src/Avalonia.Visuals/Media/PathFigure.cs
  6. 4
      src/Avalonia.Visuals/Media/PathGeometry.cs
  7. 3
      src/Avalonia.Visuals/Media/QuadraticBezierSegment .cs
  8. 49
      tests/Avalonia.Visuals.UnitTests/Media/PathMarkupParserTests.cs

5
src/Avalonia.Visuals/Media/ArcSegment.cs

@ -1,6 +1,8 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Globalization;
namespace Avalonia.Media
{
public sealed class ArcSegment : PathSegment
@ -99,5 +101,8 @@ namespace Avalonia.Media
{
ctx.ArcTo(Point, Size, RotationAngle, IsLargeArc, SweepDirection);
}
public override string ToString()
=> $"A {Size} {RotationAngle.ToString(CultureInfo.InvariantCulture)} {(IsLargeArc ? 1 : 0)} {(int)SweepDirection} {Point}";
}
}

3
src/Avalonia.Visuals/Media/BezierSegment .cs

@ -61,5 +61,8 @@ namespace Avalonia.Media
{
ctx.CubicBezierTo(Point1, Point2, Point3);
}
public override string ToString()
=> $"C {Point1} {Point2} {Point3}";
}
}

2
src/Avalonia.Visuals/Media/Geometry.cs

@ -74,7 +74,7 @@ namespace Avalonia.Media
/// </summary>
/// <param name="s">The string.</param>
/// <returns>A <see cref="StreamGeometry"/>.</returns>
public static Geometry Parse(string s) => StreamGeometry.Parse(s);
public static Geometry Parse(string s) => PathGeometry.Parse(s);
/// <summary>
/// Clones the geometry.

3
src/Avalonia.Visuals/Media/LineSegment.cs

@ -27,5 +27,8 @@ namespace Avalonia.Media
{
ctx.LineTo(Point);
}
public override string ToString()
=> $"L {Point}";
}
}

3
src/Avalonia.Visuals/Media/PathFigure.cs

@ -98,5 +98,8 @@ namespace Avalonia.Media
}
private PathSegments _segments;
public override string ToString()
=> $"M {StartPoint} {string.Join(" ", _segments)}{(IsClosed ? "Z" : "")}";
}
}

4
src/Avalonia.Visuals/Media/PathGeometry.cs

@ -112,5 +112,9 @@ namespace Avalonia.Media
() => InvalidateGeometry());
_figuresPropertiesObserver = figures?.TrackItemPropertyChanged(_ => InvalidateGeometry());
}
public override string ToString()
=> $"{(FillRule != FillRule.EvenOdd ? "F1 " : "")}{(string.Join(" ", Figures))}";
}
}

3
src/Avalonia.Visuals/Media/QuadraticBezierSegment .cs

@ -42,5 +42,8 @@ namespace Avalonia.Media
{
ctx.QuadraticBezierTo(Point1, Point2);
}
public override string ToString()
=> $"Q {Point1} {Point2}";
}
}

49
tests/Avalonia.Visuals.UnitTests/Media/PathMarkupParserTests.cs

@ -161,6 +161,13 @@ namespace Avalonia.Visuals.UnitTests.Media
}
}
[Fact]
public void Geometry_Parse_Should_Create_PathGeometry()
{
var target = Geometry.Parse("M0 0L10 10z");
Assert.IsType<PathGeometry>(target);
}
[Theory]
[InlineData("M5.5.5 5.5.5 5.5.5")]
[InlineData("F1M9.0771,11C9.1161,10.701,9.1801,10.352,9.3031,10L9.0001,10 9.0001,6.166 3.0001,9.767 3.0001,10 "
@ -221,6 +228,48 @@ namespace Avalonia.Visuals.UnitTests.Media
context.Verify(v => v.EndFigure(It.IsAny<bool>()), Times.AtLeastOnce());
}
[Theory]
[InlineData("M 5.5, 5 L 5.5, 5 L 5.5, 5")]
[InlineData("F1 M 9.0771, 11 C 9.1161, 10.701 9.1801, 10.352 9.3031, 10 L 9.0001, 10 L 9.0001, 6.166 L 3.0001, 9.767 L 3.0001, 10 "
+ "L 9.99999999997669E-05, 10 L 9.99999999997669E-05, 0 L 3.0001, 0 L 3.0001, 0.234 L 9.0001, 3.834 L 9.0001, 0 "
+ "L 12.0001, 0 L 12.0001, 8.062 C 12.1861, 8.043 12.3821, 8.031 12.5941, 8.031 C 15.3481, 8.031 15.7961, 9.826 "
+ "15.9201, 11 L 16.0001, 16 L 9.0001, 16 L 9.0001, 12.562 L 9.0001, 11Z")]
[InlineData("F1 M 24, 14 A 2, 2 0 1 1 20, 14 A 2, 2 0 1 1 24, 14Z")]
[InlineData("M 0, 0 L 10, 10Z")]
[InlineData("M 50, 50 L 100, 100 L 150, 50")]
[InlineData("M 50, 50 L -10, -10 L 10, 50")]
[InlineData("M 50, 50 L 100, 100 L 150, 50Z M 50, 50 L 70, 70 L 120, 50Z")]
[InlineData("M 80, 200 A 100, 50 45 1 0 100, 50")]
[InlineData("F1 M 16, 12 C 16, 14.209 14.209, 16 12, 16 C 9.791, 16 8, 14.209 8, 12 C 8, 11.817 8.03, 11.644 8.054, 11.467 L 6.585, 10 "
+ "L 4, 10 L 4, 6.414 L 2.5, 7.914 L 0, 5.414 L 0, 3.586 L 3.586, 0 L 4.414, 0 L 7.414, 3 L 7.586, 3 L 9, 1.586 L "
+ "11.914, 4.5 L 10.414, 6 L 12.461, 8.046 C 14.45, 8.278 16, 9.949 16, 12")]
public void Parsed_Geometry_ToString_Should_Produce_Valid_Value(string pathData)
{
var target = PathGeometry.Parse(pathData);
string output = target.ToString();
Assert.Equal(pathData, output);
}
[Theory]
[InlineData("M5.5.5 5.5.5 5.5.5", "M 5.5, 0.5 L 5.5, 0.5 L 5.5, 0.5")]
[InlineData("F1 M24,14 A2,2,0,1,1,20,14 A2,2,0,1,1,24,14 z", "F1 M 24, 14 A 2, 2 0 1 1 20, 14 A 2, 2 0 1 1 24, 14Z")]
[InlineData("F1M16,12C16,14.209 14.209,16 12,16 9.791,16 8,14.209 8,12 8,11.817 8.03,11.644 8.054,11.467L6.585,10 4,10 "
+ "4,6.414 2.5,7.914 0,5.414 0,3.586 3.586,0 4.414,0 7.414,3 7.586,3 9,1.586 11.914,4.5 10.414,6 "
+ "12.461,8.046C14.45,8.278,16,9.949,16,12",
"F1 M 16, 12 C 16, 14.209 14.209, 16 12, 16 C 9.791, 16 8, 14.209 8, 12 C 8, 11.817 8.03, 11.644 8.054, 11.467 L 6.585, 10 "
+ "L 4, 10 L 4, 6.414 L 2.5, 7.914 L 0, 5.414 L 0, 3.586 L 3.586, 0 L 4.414, 0 L 7.414, 3 L 7.586, 3 L 9, 1.586 L "
+ "11.914, 4.5 L 10.414, 6 L 12.461, 8.046 C 14.45, 8.278 16, 9.949 16, 12")]
public void Parsed_Geometry_ToString_Should_Format_Value(string pathData, string formattedPathData)
{
var target = PathGeometry.Parse(pathData);
string output = target.ToString();
Assert.Equal(formattedPathData, output);
}
[Theory]
[InlineData("0 0")]
[InlineData("j")]

Loading…
Cancel
Save