Skip to content

Commit 193b587

Browse files
authored
Convert SKRect to CGRect correctly (#2243)
1 parent aeefa65 commit 193b587

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

source/SkiaSharp.Views/SkiaSharp.Views.Apple/AppleExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static SKRect ToSKRect(this CGRect rect)
4545

4646
public static CGRect ToRect(this SKRect rect)
4747
{
48-
return new CGRect(rect.Left, rect.Top, rect.Right, rect.Bottom);
48+
return new CGRect(rect.Left, rect.Top, rect.Width, rect.Height);
4949
}
5050

5151
// CGSize

tests/SkiaSharp.iOS.Tests/iOSExtensionsTests.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Xunit;
1+
using CoreGraphics;
2+
using Foundation;
3+
using Xunit;
24

35
namespace SkiaSharp.Views.iOS.Tests
46
{
@@ -63,5 +65,39 @@ public void EncodedDataBackedImageToUIImage(byte alpha)
6365

6466
ValidateTestBitmap(uiImage, alpha);
6567
}
68+
69+
[SkippableTheory]
70+
[InlineData(0, 0, 0, 0)]
71+
[InlineData(5, 5, 5, 5)]
72+
[InlineData(1, 2, 3, 4)]
73+
[InlineData(1, 1, 0, 0)]
74+
[InlineData(0, 0, 1, 1)]
75+
[InlineData(100, 100, 100, 100)]
76+
public void SKRectToCGRect(int x, int y, int w, int h)
77+
{
78+
var initial = SKRect.Create(x, y, w, h);
79+
var expected = new CGRect(x, y, w, h);
80+
81+
var actual = initial.ToRect();
82+
83+
Assert.Equal(expected, actual);
84+
}
85+
86+
[SkippableTheory]
87+
[InlineData(0, 0, 0, 0)]
88+
[InlineData(5, 5, 5, 5)]
89+
[InlineData(1, 2, 3, 4)]
90+
[InlineData(1, 1, 0, 0)]
91+
[InlineData(0, 0, 1, 1)]
92+
[InlineData(100, 100, 100, 100)]
93+
public void CGRectToSKRect(int x, int y, int w, int h)
94+
{
95+
var initial = new CGRect(x, y, w, h);
96+
var expected = SKRect.Create(x, y, w, h);
97+
98+
var actual = initial.ToSKRect();
99+
100+
Assert.Equal(expected, actual);
101+
}
66102
}
67103
}

0 commit comments

Comments
 (0)