Fix now unsupported behaviour in ConvexPolygonClipper

This commit is contained in:
Dan Balasescu
2023-07-07 21:21:28 +09:00
parent d7ff5d6478
commit 5bb54e8b15
3 changed files with 10 additions and 4 deletions

View File

@@ -104,7 +104,7 @@ namespace osu.Framework.Tests.Polygons
private static Vector2[] clip(SimpleConvexPolygon poly1, SimpleConvexPolygon poly2)
{
var clipper = new ConvexPolygonClipper<SimpleConvexPolygon, SimpleConvexPolygon>(ref poly1, ref poly2);
var clipper = new ConvexPolygonClipper<SimpleConvexPolygon, SimpleConvexPolygon>(poly1, poly2);
Span<Vector2> buffer = stackalloc Vector2[clipper.GetClipBufferSize()];

View File

@@ -300,12 +300,12 @@ namespace osu.Framework.Tests.Polygons
}
private Span<Vector2> clip(SimpleConvexPolygon clipPolygon, SimpleConvexPolygon subjectPolygon)
=> new ConvexPolygonClipper<SimpleConvexPolygon, SimpleConvexPolygon>(ref clipPolygon, ref subjectPolygon).Clip();
=> new ConvexPolygonClipper<SimpleConvexPolygon, SimpleConvexPolygon>(clipPolygon, subjectPolygon).Clip();
private Span<Vector2> clip<TClip, TSubject>(TClip clipPolygon, TSubject subjectPolygon)
where TClip : IConvexPolygon
where TSubject : IConvexPolygon
=> new ConvexPolygonClipper<TClip, TSubject>(ref clipPolygon, ref subjectPolygon).Clip();
=> new ConvexPolygonClipper<TClip, TSubject>(clipPolygon, subjectPolygon).Clip();
private void assertPolygonEquals(IPolygon expected, IPolygon actual, bool reverse)
=> Assert.That(Vector2Extensions.GetOrientation(actual.GetVertices()),

View File

@@ -22,6 +22,12 @@ namespace osu.Framework.Utils
this.subjectPolygon = subjectPolygon;
}
public ConvexPolygonClipper(TClip clipPolygon, TSubject subjectPolygon)
{
this.clipPolygon = clipPolygon;
this.subjectPolygon = subjectPolygon;
}
/// <summary>
/// Determines the minimum buffer size required to clip the two polygons.
/// </summary>
@@ -46,7 +52,7 @@ namespace osu.Framework.Utils
/// </summary>
/// <param name="buffer">The buffer to contain the clipped vertices. Must have a length of <see cref="GetClipBufferSize"/>.</param>
/// <returns>A clockwise-ordered set of vertices representing the result of clipping <see cref="subjectPolygon"/> by <see cref="clipPolygon"/>.</returns>
public Span<Vector2> Clip(in Span<Vector2> buffer)
public Span<Vector2> Clip(Span<Vector2> buffer)
{
if (buffer.Length < GetClipBufferSize())
{