private static Vector2[] clip(SimpleConvexPolygon poly1, SimpleConvexPolygon poly2) { var clipper = new ConvexPolygonClipper <SimpleConvexPolygon, SimpleConvexPolygon>(ref poly1, ref poly2); Span <Vector2> buffer = stackalloc Vector2[clipper.GetClipBufferSize()]; return(clipper.Clip(buffer).ToArray()); }
protected void DrawClipped <T>(ref T polygon, TextureGL texture, ColourInfo drawColour, RectangleF?textureRect = null, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null) where T : IConvexPolygon { var maskingQuad = GLWrapper.CurrentMaskingInfo.ConservativeScreenSpaceQuad; var clipper = new ConvexPolygonClipper <Quad, T>(ref maskingQuad, ref polygon); Span <Vector2> buffer = stackalloc Vector2[clipper.GetClipBufferSize()]; Span <Vector2> clippedRegion = clipper.Clip(buffer); for (int i = 2; i < clippedRegion.Length; i++) { DrawTriangle(texture, new Triangle(clippedRegion[0], clippedRegion[i - 1], clippedRegion[i]), drawColour, textureRect, vertexAction, inflationPercentage); } }