Fixed the logic for SKRegion.SetPath. Closes #316
This commit is contained in:
Родитель
9d3fa22b63
Коммит
a56d09cd3b
|
@ -95,7 +95,20 @@ namespace SkiaSharp
|
|||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException (nameof (path));
|
||||
return SkiaApi.sk_region_set_path(Handle, path.Handle, Handle);
|
||||
|
||||
using (var clip = new SKRegion()) {
|
||||
SKRect rect;
|
||||
if (path.GetBounds(out rect)) {
|
||||
var recti = new SKRectI(
|
||||
(int)rect.Left,
|
||||
(int)rect.Top,
|
||||
(int)Math.Ceiling(rect.Right),
|
||||
(int)Math.Ceiling(rect.Bottom));
|
||||
clip.SetRect(recti);
|
||||
}
|
||||
|
||||
return SkiaApi.sk_region_set_path(Handle, path.Handle, clip.Handle);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Op(SKRectI rect, SKRegionOperation op)
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace SkiaSharp.Tests
|
||||
{
|
||||
public class SKRegionTest : SKTest
|
||||
{
|
||||
[Test]
|
||||
public void SetPathWithoutClipDoesNotCreateEmptyRegion()
|
||||
{
|
||||
var path = new SKPath();
|
||||
path.AddRect(SKRect.Create(10, 20, 30, 40));
|
||||
|
||||
var region = new SKRegion();
|
||||
var isNonEmpty = region.SetPath(path);
|
||||
|
||||
Assert.IsTrue(isNonEmpty);
|
||||
Assert.AreEqual(SKRectI.Truncate(path.Bounds), region.Bounds);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetPathWithEmptyClipDoesCreatesEmptyRegion()
|
||||
{
|
||||
var path = new SKPath();
|
||||
path.AddRect(SKRect.Create(10, 20, 30, 40));
|
||||
|
||||
var region = new SKRegion();
|
||||
var isNonEmpty = region.SetPath(path, new SKRegion());
|
||||
|
||||
Assert.IsFalse(isNonEmpty);
|
||||
Assert.AreEqual(SKRectI.Empty, region.Bounds);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetPathWithClipDoesCreatesCorrectRegion()
|
||||
{
|
||||
var clipRect = new SKRectI(25, 25, 50, 50);
|
||||
var clip = new SKRegion();
|
||||
clip.SetRect(clipRect);
|
||||
|
||||
var rect = new SKRectI(10, 20, 30, 40);
|
||||
var path = new SKPath();
|
||||
path.AddRect(rect);
|
||||
|
||||
var region = new SKRegion();
|
||||
var isNonEmpty = region.SetPath(path, clip);
|
||||
|
||||
Assert.IsTrue(isNonEmpty);
|
||||
Assert.AreEqual(SKRectI.Intersect(clipRect, rect), region.Bounds);
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче