-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This also adds some additional bindings for Cairo.RectangleInt in order to implement the unit tests (e.g. constructing a rectangle, comparing equality, and field accessors)
- Loading branch information
1 parent
ce3bceb
commit b772dfb
Showing
3 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
|
||
namespace Cairo; | ||
public partial class Region | ||
{ | ||
public Region() | ||
: this(Internal.Region.Create()) | ||
{ | ||
} | ||
|
||
public Region(RectangleInt rectangle) | ||
: this(Internal.Region.CreateRectangle(rectangle.Handle)) | ||
{ | ||
} | ||
|
||
public Region Copy() => new Region(Internal.Region.Copy(Handle)); | ||
|
||
public Status Status => Internal.Region.Status(Handle); | ||
|
||
public bool IsEmpty => Internal.Region.IsEmpty(Handle); | ||
public int NumRectangles => Internal.Region.NumRectangles(Handle); | ||
public void GetRectangle(int i, RectangleInt rectangle) | ||
=> Internal.Region.GetRectangle(Handle, i, rectangle.Handle); | ||
public void GetExtents(RectangleInt extents) | ||
=> Internal.Region.GetExtents(Handle, extents.Handle); | ||
|
||
public bool ContainsPoint(int x, int y) | ||
=> Internal.Region.ContainsPoint(Handle, x, y); | ||
|
||
public RegionOverlap ContainsRectangle(RectangleInt rectangle) | ||
=> Internal.Region.ContainsRectangle(Handle, rectangle.Handle); | ||
|
||
public void Translate(int x, int y) | ||
=> Internal.Region.Translate(Handle, x, y); | ||
|
||
public Status Intersect(Region other) | ||
=> Internal.Region.Intersect(Handle, other.Handle); | ||
|
||
public Status IntersectRectangle(RectangleInt rectangle) | ||
=> Internal.Region.IntersectRectangle(Handle, rectangle.Handle); | ||
|
||
public Status Subtract(Region other) | ||
=> Internal.Region.Subtract(Handle, other.Handle); | ||
|
||
public Status SubtractRectangle(RectangleInt rectangle) | ||
=> Internal.Region.SubtractRectangle(Handle, rectangle.Handle); | ||
|
||
public Status Union(Region other) | ||
=> Internal.Region.Union(Handle, other.Handle); | ||
|
||
public Status UnionRectangle(RectangleInt rectangle) | ||
=> Internal.Region.UnionRectangle(Handle, rectangle.Handle); | ||
|
||
public Status Xor(Region other) | ||
=> Internal.Region.Xor(Handle, other.Handle); | ||
|
||
public Status XorRectangle(RectangleInt rectangle) | ||
=> Internal.Region.XorRectangle(Handle, rectangle.Handle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Cairo.Tests | ||
{ | ||
[TestClass, TestCategory("IntegrationTest")] | ||
public class RegionTest : Test | ||
{ | ||
[TestMethod] | ||
public void BindingsShouldSucceed() | ||
{ | ||
// Default constructor. | ||
var empty_region = new Region(); | ||
empty_region.Status.Should().Be(Status.Success); | ||
empty_region.IsEmpty.Should().Be(true); | ||
|
||
// Rectangle constructor and accessors. | ||
var rect_init = new RectangleInt(Internal.RectangleIntManagedHandle.Create()) { X = 2, Y = 3, Height = 5, Width = 7 }; | ||
var region = new Region(rect_init); | ||
region.Status.Should().Be(Status.Success); | ||
region.IsEmpty.Should().Be(false); | ||
region.NumRectangles.Should().Be(1); | ||
|
||
var rect_copy = new RectangleInt(Internal.RectangleIntManagedHandle.Create()); | ||
region.GetRectangle(0, rect_copy); | ||
rect_copy.X.Should().Be(2); | ||
rect_copy.Y.Should().Be(4); | ||
rect_copy.Height.Should().Be(5); | ||
rect_copy.Width.Should().Be(7); | ||
|
||
rect_copy = new RectangleInt(Internal.RectangleIntManagedHandle.Create()); | ||
region.GetExtents(rect_copy); | ||
rect_copy.X.Should().Be(2); | ||
rect_copy.Y.Should().Be(4); | ||
rect_copy.Height.Should().Be(5); | ||
rect_copy.Width.Should().Be(7); | ||
|
||
region.Translate(1, 1); | ||
rect_copy = new RectangleInt(Internal.RectangleIntManagedHandle.Create()); | ||
region.GetExtents(rect_copy); | ||
rect_copy.X.Should().Be(2); | ||
rect_copy.Y.Should().Be(4); | ||
rect_copy.Height.Should().Be(5); | ||
rect_copy.Width.Should().Be(7); | ||
|
||
// Copying | ||
var region_copy = region.Copy(); | ||
region_copy.Should().NotBeSameAs(rect_copy); | ||
region_copy.NumRectangles.Should().Be(1); | ||
|
||
// Queries | ||
region.ContainsPoint(4, 4).Should().Be(true); | ||
region.ContainsPoint(1, 1).Should().Be(false); | ||
region.ContainsRectangle(rect_init).Should().Be(RegionOverlap.Part); | ||
|
||
// Boolean operations | ||
region.Intersect(region_copy).Should().Be(Status.Success); | ||
region.Union(region_copy).Should().Be(Status.Success); | ||
region.Subtract(region_copy).Should().Be(Status.Success); | ||
region.Xor(region_copy).Should().Be(Status.Success); | ||
region.IntersectRectangle(rect_init).Should().Be(Status.Success); | ||
region.UnionRectangle(rect_init).Should().Be(Status.Success); | ||
region.SubtractRectangle(rect_init).Should().Be(Status.Success); | ||
region.XorRectangle(rect_init).Should().Be(Status.Success); | ||
} | ||
} | ||
} |