Skip to content

Commit

Permalink
Convert SKRect to CGRect correctly (#2243)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow authored Sep 8, 2022
1 parent aeefa65 commit 193b587
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static SKRect ToSKRect(this CGRect rect)

public static CGRect ToRect(this SKRect rect)
{
return new CGRect(rect.Left, rect.Top, rect.Right, rect.Bottom);
return new CGRect(rect.Left, rect.Top, rect.Width, rect.Height);
}

// CGSize
Expand Down
38 changes: 37 additions & 1 deletion tests/SkiaSharp.iOS.Tests/iOSExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Xunit;
using CoreGraphics;
using Foundation;
using Xunit;

namespace SkiaSharp.Views.iOS.Tests
{
Expand Down Expand Up @@ -63,5 +65,39 @@ public void EncodedDataBackedImageToUIImage(byte alpha)

ValidateTestBitmap(uiImage, alpha);
}

[SkippableTheory]
[InlineData(0, 0, 0, 0)]
[InlineData(5, 5, 5, 5)]
[InlineData(1, 2, 3, 4)]
[InlineData(1, 1, 0, 0)]
[InlineData(0, 0, 1, 1)]
[InlineData(100, 100, 100, 100)]
public void SKRectToCGRect(int x, int y, int w, int h)
{
var initial = SKRect.Create(x, y, w, h);
var expected = new CGRect(x, y, w, h);

var actual = initial.ToRect();

Assert.Equal(expected, actual);
}

[SkippableTheory]
[InlineData(0, 0, 0, 0)]
[InlineData(5, 5, 5, 5)]
[InlineData(1, 2, 3, 4)]
[InlineData(1, 1, 0, 0)]
[InlineData(0, 0, 1, 1)]
[InlineData(100, 100, 100, 100)]
public void CGRectToSKRect(int x, int y, int w, int h)
{
var initial = new CGRect(x, y, w, h);
var expected = SKRect.Create(x, y, w, h);

var actual = initial.ToSKRect();

Assert.Equal(expected, actual);
}
}
}

0 comments on commit 193b587

Please sign in to comment.