从NSBezierPath中切出一个矩形

是否可以删除由路径中的“ 1”区域定义的“ 0”块?     
已邀请:
绝对。这是裁剪区域的作用:
// Save the current clipping region
[NSGraphicsContext saveGraphicsState];
NSRect dontDrawThisRect = NSMakeRect(x, y, w, h);
// Either:
NSRectClip(dontDrawThisRect);
// Or (usually for more complex shapes):
//[[NSBezierPath bezierPathWithRect:dontDrawThisRect] addClip];
[myBezierPath fill];    // or stroke, or whatever you do
// Restore the clipping region for further drawing
[NSGraphicsContext restoreGraphicsState];
    
正如评论中指出的那样,卡斯韦尔先生的答案实际上与《任择议定书》要求的相反。此代码示例演示如何从圆(或从任何其他贝塞尔曲线路径中的任何贝塞尔曲线路径)中删除rect。诀窍是“反向”要删除的路径,然后将其附加到原始路径:
NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(0, 0, 100, 100)];
NSBezierPath *rectPath = [NSBezierPath bezierPathWithRect:NSMakeRect(25, 25, 50, 50)];
rectPath = [rectPath bezierPathByReversingPath];
[circlePath appendBezierPath:rectPath];
注意:如果贝塞尔曲线路径相互交叉,则情况会变得有些棘手。然后,您必须设置正确的“绕线规则”。     

要回复问题请先登录注册