Added a few more members to SKPath

This commit is contained in:
Matthew Leibowitz 2016-08-20 02:27:06 +02:00
Родитель 9f25361744
Коммит a9dbb10461
5 изменённых файлов: 88 добавлений и 1 удалений

Просмотреть файл

@ -62,6 +62,43 @@ namespace SkiaSharp
}
}
public int PointCount {
get {
return SkiaApi.sk_path_count_points (Handle);
}
}
public SKPoint this [int index] {
get {
return GetPoint (index);
}
}
public SKPoint[] Points {
get {
return GetPoints (PointCount);
}
}
public SKPoint GetPoint (int index)
{
SKPoint point;
SkiaApi.sk_path_get_point (Handle, index, out point);
return point;
}
public SKPoint[] GetPoints (int max)
{
SKPoint[] points = new SKPoint [max];
GetPoints (points, max);
return points;
}
public int GetPoints (SKPoint[] points, int max)
{
return SkiaApi.sk_path_get_points (Handle, points, max);
}
public void MoveTo (float x, float y)
{
SkiaApi.sk_path_move_to (Handle, x, y);

Просмотреть файл

@ -382,6 +382,12 @@ namespace SkiaSharp
public extern static void sk_path_add_rounded_rect (sk_path_t t, ref SKRect rect, float rx, float ry, SKPathDirection dir);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_path_add_circle (sk_path_t t, float x, float y, float radius, SKPathDirection dir);
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static int sk_path_count_points (sk_path_t path);
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_path_get_point (sk_path_t path, int index, out SKPoint point);
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static int sk_path_get_points (sk_path_t path, [Out] SKPoint[] points, int max);
// iterator
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]

2
skia

@ -1 +1 @@
Subproject commit 081595dac0040797ac8a964a75834f7d1c0b47d2
Subproject commit 6bb81a8b1603664b7a7c9ef286d99bf1f9ec7009

Просмотреть файл

@ -103,6 +103,9 @@
<Compile Include="..\Tests\SKPaintTest.cs" >
<Link>SKPaintTest.cs</Link>
</Compile>
<Compile Include="..\Tests\SKPathTest.cs" >
<Link>SKPathTest.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\samples\SharedDemo\content-font.ttf">

41
tests/Tests/SKPathTest.cs Normal file
Просмотреть файл

@ -0,0 +1,41 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using NUnit.Framework;
namespace SkiaSharp.Tests
{
[TestFixture]
public class SKPathTest : SKTest
{
[Test]
public void PathPointsAreCorrect()
{
using (var path = new SKPath ()) {
// set up the xamagon
path.MoveTo (71.4311121f, 56f);
path.CubicTo (68.6763107f, 56.0058575f, 65.9796704f, 57.5737917f, 64.5928855f, 59.965729f);
path.LineTo (43.0238921f, 97.5342563f);
path.CubicTo (41.6587026f, 99.9325978f, 41.6587026f, 103.067402f, 43.0238921f, 105.465744f);
path.LineTo (64.5928855f, 143.034271f);
path.CubicTo (65.9798162f, 145.426228f, 68.6763107f, 146.994582f, 71.4311121f, 147f);
path.LineTo (114.568946f, 147f);
path.CubicTo (117.323748f, 146.994143f, 120.020241f, 145.426228f, 121.407172f, 143.034271f);
path.LineTo (142.976161f, 105.465744f);
path.CubicTo (144.34135f, 103.067402f, 144.341209f, 99.9325978f, 142.976161f, 97.5342563f);
path.LineTo (121.407172f, 59.965729f);
path.CubicTo (120.020241f, 57.5737917f, 117.323748f, 56.0054182f, 114.568946f, 56f);
path.LineTo (71.4311121f, 56f);
path.Close ();
// the right number/count
Assert.AreEqual (25, path.PointCount);
Assert.AreEqual (25, path.Points.Length);
// the right value
Assert.AreEqual (new SKPoint (68.6763107f, 56.0058575f), path.GetPoint (1));
Assert.AreEqual (new SKPoint (68.6763107f, 56.0058575f), path.Points [1]);
}
}
}
}