private static void OutputClippedRectangle() { var rect1 = new RectangularePolygon(10, 10, 40, 40); var rect2 = new RectangularePolygon(20, 0, 20, 20); var paths = rect1.Clip(rect2); paths.SaveImage("Clipping", "RectangleWithTopClipped.png"); }
public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius) { var rect = new RectangularePolygon(-0.5f, -0.5f, cornerRadius, cornerRadius); IPath cornerToptLeft = rect.Clip(new EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius)); var center = new Vector2(imageWidth / 2F, imageHeight / 2F); float rightPos = imageWidth - cornerToptLeft.Bounds.Width + 1; float bottomPos = imageHeight - cornerToptLeft.Bounds.Height + 1; IPath cornerTopRight = cornerToptLeft.RotateDegree(90).Translate(rightPos, 0); IPath cornerBottomLeft = cornerToptLeft.RotateDegree(-90).Translate(0, bottomPos); IPath cornerBottomRight = cornerToptLeft.RotateDegree(180).Translate(rightPos, bottomPos); return(new PathCollection(cornerToptLeft, cornerBottomLeft, cornerTopRight, cornerBottomRight)); }
public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius) { // first create a square var rect = new RectangularePolygon(-0.5f, -0.5f, cornerRadius, cornerRadius); // then cut out of the square a circle so we are left with a corner var cornerToptLeft = rect.Clip(new EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius)); // corner is now a corner shape positions top left //lets make 3 more positioned correctly, we can do that by translating the orgional around the center of the image var center = new Vector2(imageWidth / 2, imageHeight / 2); float rightPos = imageWidth - cornerToptLeft.Bounds.Width + 1; float bottomPos = imageHeight - cornerToptLeft.Bounds.Height + 1; // move it across the width of the image - the width of the shape var cornerTopRight = cornerToptLeft.RotateDegree(90).Translate(rightPos, 0); var cornerBottomLeft = cornerToptLeft.RotateDegree(-90).Translate(0, bottomPos); var cornerBottomRight = cornerToptLeft.RotateDegree(180).Translate(rightPos, bottomPos); return(new PathCollection(cornerToptLeft, cornerBottomLeft, cornerTopRight, cornerBottomRight)); }
private static IPath GetClippedRect(int imageWidth, int imageHeight, float cornerRadius) { var rect = new RectangularePolygon(-0.5f, -0.5f, imageWidth + 0.5f, imageHeight + 0.5f); return(rect.Clip(new EllipsePolygon(imageWidth * 0.5f, imageHeight * 0.5f, cornerRadius))); }