VectorBoolean / VectorBoolean / MyDocument.m

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
//
//  MyDocument.m
//  VectorBoolean
//
//  Created by Andrew Finnell on 5/31/11.
//  Copyright 2011 Fortunate Bear, LLC. All rights reserved.
//

#import "MyDocument.h"
#import "CanvasView.h"
#import "Canvas.h"
#import "NSBezierPath+Boolean.h"

@interface MyDocument ()

- (void) addSomeOverlap;
- (void) addCircleInRectangle;
- (void) addRectangleInCircle;
- (void) addCircleOnRectangle;
- (void) addHoleyRectangleWithRectangle;
- (void) addCircleOnTwoRectangles;
- (void) addCircleOverlappingCircle;
- (void) addComplexShapes;
- (void) addComplexShapes2;
- (void) addTriangleInsideRectangle;
- (void) addDiamondOverlappingRectangle;
- (void) addDiamondInsideRectangle;
- (void) addNonOverlappingContours;
- (void) addMoreNonOverlappingContours;
- (void) addConcentricContours;
- (void) addMoreConcentricContours;
- (void) addOverlappingHole;
- (void) addHoleOverlappingHole;
- (void) addCurvyShapeOverlappingRectangle;

- (void) addRectangle:(NSRect)rect;
- (void) addCircleAtPoint:(NSPoint)center withRadius:(CGFloat)radius;
- (void) addTriangle:(NSPoint)point1 point2:(NSPoint)point2 point3:(NSPoint)point3;
- (void) addQuadrangle:(NSPoint)point1 point2:(NSPoint)point2 point3:(NSPoint)point3 point4:(NSPoint)point4;

- (void) addRectangle:(NSRect)rect toPath:(NSBezierPath *)rectangle;
- (void) addCircleAtPoint:(NSPoint)center withRadius:(CGFloat)radius toPath:(NSBezierPath *)circle;
- (void) addTriangle:(NSPoint)point1 point2:(NSPoint)point2 point3:(NSPoint)point3 toPath:(NSBezierPath *)path;
- (void) addQuadrangle:(NSPoint)point1 point2:(NSPoint)point2 point3:(NSPoint)point3 point4:(NSPoint)point4 toPath:(NSBezierPath *)path;

@end

@implementation MyDocument

- (id)init
{
    self = [super init];
    if (self) {
        _resetAction = @selector(addSomeOverlap);
    }
    return self;
}

- (NSString *)windowNibName
{
    // Override returning the nib file name of the document
    // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
    return @"MyDocument";
}

- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    [super windowControllerDidLoadNib:aController];
    // Add any code here that needs to be executed once the windowController has loaded the document's window.
    
    [self onReset:nil];
}

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
    /*
     Insert code here to write your document to data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning nil.
    You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
    */
    if (outError) {
        *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
    }
    return nil;
}

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
    /*
    Insert code here to read your document from the given data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning NO.
    You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
    */
    if (outError) {
        *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
    }
    return YES;
}

- (IBAction) onReset:(id)sender
{
    [_view.canvas clear];
    
    [self performSelector:_resetAction];
    
    [_view setNeedsDisplay:YES];
}

- (void) addSomeOverlap
{
    [self addRectangle:NSMakeRect(50, 50, 300, 200)];
    [self addCircleAtPoint:NSMakePoint(355, 240) withRadius:125];
}

- (void) addCircleInRectangle
{
    [self addRectangle:NSMakeRect(50, 50, 350, 300)];
    [self addCircleAtPoint:NSMakePoint(210, 200) withRadius:125];    
}

- (void) addRectangleInCircle
{
    [self addRectangle:NSMakeRect(150, 150, 150, 150)];
    [self addCircleAtPoint:NSMakePoint(200, 200) withRadius:185];    
}

- (void) addCircleOnRectangle
{
    [self addRectangle:NSMakeRect(15, 15, 370, 370)];
    [self addCircleAtPoint:NSMakePoint(200, 200) withRadius:185];    
}

- (void) addHoleyRectangleWithRectangle
{
    NSBezierPath *holeyRectangle = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(50, 50, 350, 300) toPath:holeyRectangle];
    [self addCircleAtPoint:NSMakePoint(210, 200) withRadius:125 toPath:holeyRectangle];    
    [_view.canvas addPath:holeyRectangle withColor:[NSColor blueColor]];

    NSBezierPath *rectangle = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(180, 5, 100, 400) toPath:rectangle];
    [_view.canvas addPath:rectangle withColor:[NSColor redColor]];
}

- (void) addCircleOnTwoRectangles
{
    NSBezierPath *rectangles = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(50, 5, 100, 400) toPath:rectangles];
    [self addRectangle:NSMakeRect(350, 5, 100, 400) toPath:rectangles];
    [_view.canvas addPath:rectangles withColor:[NSColor blueColor]];

    [self addCircleAtPoint:NSMakePoint(200, 200) withRadius:185];    
}

- (void) addCircleOverlappingCircle
{
    NSBezierPath *circle = [NSBezierPath bezierPath];
    [self addCircleAtPoint:NSMakePoint(355, 240) withRadius:125 toPath:circle];
    [_view.canvas addPath:circle withColor:[NSColor blueColor]];
    
    [self addCircleAtPoint:NSMakePoint(210, 110) withRadius:100];
}

- (void) addComplexShapes
{
    NSBezierPath *holeyRectangle = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(50, 50, 350, 300) toPath:holeyRectangle];
    [self addCircleAtPoint:NSMakePoint(210, 200) withRadius:125 toPath:holeyRectangle];    

    NSBezierPath *rectangle = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(180, 5, 100, 400) toPath:rectangle];

    NSBezierPath *allParts = [holeyRectangle fb_union:rectangle];
    NSBezierPath *intersectingParts = [holeyRectangle fb_intersect:rectangle];
    
    [_view.canvas addPath:allParts withColor:[NSColor blueColor]];
    [_view.canvas addPath:intersectingParts withColor:[NSColor redColor]];
}

- (void) addComplexShapes2
{
    NSBezierPath *rectangles = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(50, 5, 100, 400) toPath:rectangles];
    [self addRectangle:NSMakeRect(350, 5, 100, 400) toPath:rectangles];

    NSBezierPath *circle = [NSBezierPath bezierPath];
    [self addCircleAtPoint:NSMakePoint(200, 200) withRadius:185 toPath:circle];    

    NSBezierPath *allParts = [rectangles fb_union:circle];
    NSBezierPath *intersectingParts = [rectangles fb_intersect:circle];

    [_view.canvas addPath:allParts withColor:[NSColor blueColor]];
    [_view.canvas addPath:intersectingParts withColor:[NSColor redColor]];
}

- (void) addTriangleInsideRectangle
{
    [self addRectangle:NSMakeRect(100, 100, 300, 300)];
    [self addTriangle:NSMakePoint(100, 400) point2:NSMakePoint(400, 400) point3:NSMakePoint(250, 250)];
}

- (void) addDiamondOverlappingRectangle
{
    [self addRectangle:NSMakeRect(50, 50, 200, 200)];
    [self addQuadrangle:NSMakePoint(50, 250) point2:NSMakePoint(150, 400) point3:NSMakePoint(250, 250) point4:NSMakePoint(150, 100)];
}

- (void) addDiamondInsideRectangle
{
    [self addRectangle:NSMakeRect(100, 100, 300, 300)];
    [self addQuadrangle:NSMakePoint(100, 250) point2:NSMakePoint(250, 400) point3:NSMakePoint(400, 250) point4:NSMakePoint(250, 100)];
}

- (void) addNonOverlappingContours
{
    [self addRectangle:NSMakeRect(100, 200, 200, 200)];
    
    NSBezierPath *circles = [NSBezierPath bezierPath];
    [self addCircleAtPoint:NSMakePoint(200, 300) withRadius:85 toPath:circles];    
    [self addCircleAtPoint:NSMakePoint(200, 95) withRadius:85 toPath:circles];
    [_view.canvas addPath:circles withColor:[NSColor redColor]];
}

- (void) addMoreNonOverlappingContours
{
    NSBezierPath *rectangles = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(100, 200, 200, 200) toPath:rectangles];
    [self addRectangle:NSMakeRect(175, 70, 50, 50) toPath:rectangles];    
    [_view.canvas addPath:rectangles withColor:[NSColor blueColor]];

    NSBezierPath *circles = [NSBezierPath bezierPath];
    [self addCircleAtPoint:NSMakePoint(200, 300) withRadius:85 toPath:circles];    
    [self addCircleAtPoint:NSMakePoint(200, 95) withRadius:85 toPath:circles];
    [_view.canvas addPath:circles withColor:[NSColor redColor]];
}

- (void) addConcentricContours
{
    NSBezierPath *holeyRectangle = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(50, 50, 350, 300) toPath:holeyRectangle];
    [self addCircleAtPoint:NSMakePoint(210, 200) withRadius:125 toPath:holeyRectangle];    
    [_view.canvas addPath:holeyRectangle withColor:[NSColor blueColor]];

    [self addCircleAtPoint:NSMakePoint(210, 200) withRadius:140];
}

- (void) addMoreConcentricContours
{
    NSBezierPath *holeyRectangle = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(50, 50, 350, 300) toPath:holeyRectangle];
    [self addCircleAtPoint:NSMakePoint(210, 200) withRadius:125 toPath:holeyRectangle];    
    [_view.canvas addPath:holeyRectangle withColor:[NSColor blueColor]];
    
    [self addCircleAtPoint:NSMakePoint(210, 200) withRadius:70];
}

- (void) addOverlappingHole
{
    NSBezierPath *holeyRectangle = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(50, 50, 350, 300) toPath:holeyRectangle];
    [self addCircleAtPoint:NSMakePoint(210, 200) withRadius:125 toPath:holeyRectangle];    
    [_view.canvas addPath:holeyRectangle withColor:[NSColor blueColor]];

    NSBezierPath *circle = [NSBezierPath bezierPath];
    [self addCircleAtPoint:NSMakePoint(180, 180) withRadius:125 toPath:circle];    
    [_view.canvas addPath:circle withColor:[NSColor redColor]];
}

- (void) addHoleOverlappingHole
{
    NSBezierPath *holeyRectangle1 = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(50, 50, 350, 300) toPath:holeyRectangle1];
    [self addCircleAtPoint:NSMakePoint(210, 200) withRadius:125 toPath:holeyRectangle1];    
    [_view.canvas addPath:holeyRectangle1 withColor:[NSColor blueColor]];
    
    
    NSBezierPath *holeyRectangle2 = [NSBezierPath bezierPath];
    [self addRectangle:NSMakeRect(225, 65, 160, 160) toPath:holeyRectangle2];
    [self addCircleAtPoint:NSMakePoint(305, 145) withRadius:65 toPath:holeyRectangle2];    
    [_view.canvas addPath:holeyRectangle2 withColor:[NSColor redColor]];
}

- (void) addCurvyShapeOverlappingRectangle
{
    NSBezierPath *rectangle = [NSBezierPath bezierPath];
    CGFloat top = 65.0 + 160.0 / 3.0;
    [rectangle moveToPoint:NSMakePoint(40, top)];
    [rectangle lineToPoint:NSMakePoint(410, top)];
    [rectangle lineToPoint:NSMakePoint(410, 50)];
    [rectangle lineToPoint:NSMakePoint(40, 50)];
    [rectangle lineToPoint:NSMakePoint(40, top)];
    [_view.canvas addPath:rectangle withColor:[NSColor redColor]];
    
    NSBezierPath *curveyShape = [NSBezierPath bezierPath];
    [curveyShape moveToPoint:NSMakePoint(335.000000, 203.000000)];
    [curveyShape curveToPoint:NSMakePoint(335.000000, 200.000000) controlPoint1:NSMakePoint(335.000000, 202.000000) controlPoint2:NSMakePoint(335.000000, 201.000000)];
    [curveyShape curveToPoint:NSMakePoint(270.000000, 90.000000) controlPoint1:NSMakePoint(335.000000, 153.000000) controlPoint2:NSMakePoint(309.000000, 111.000000)];
    [curveyShape curveToPoint:NSMakePoint(240.000000, 145.000000) controlPoint1:NSMakePoint(252.000000, 102.000000) controlPoint2:NSMakePoint(240.000000, 122.000000)];
    [curveyShape curveToPoint:NSMakePoint(305.000000, 210.000000) controlPoint1:NSMakePoint(240.000000, 181.000000) controlPoint2:NSMakePoint(269.000000, 210.000000)];
    [curveyShape curveToPoint:NSMakePoint(335.000000, 203.000000) controlPoint1:NSMakePoint(316.000000, 210.000000) controlPoint2:NSMakePoint(326.000000, 207.000000)];
    [_view.canvas addPath:curveyShape withColor:[NSColor blueColor]];
}

- (void) addRectangle:(NSRect)rect
{
    NSBezierPath *rectangle = [NSBezierPath bezierPath];
    [self addRectangle:rect toPath:rectangle];
    [_view.canvas addPath:rectangle withColor:[NSColor blueColor]];
}

- (void) addCircleAtPoint:(NSPoint)center withRadius:(CGFloat)radius
{
    NSBezierPath *circle = [NSBezierPath bezierPath];
    [self addCircleAtPoint:center withRadius:radius toPath:circle];
    [_view.canvas addPath:circle withColor:[NSColor redColor]];
}

- (void) addTriangle:(NSPoint)point1 point2:(NSPoint)point2 point3:(NSPoint)point3
{
    NSBezierPath *triangle = [NSBezierPath bezierPath];
    [self addTriangle:point1 point2:point2 point3:point3 toPath:triangle];
    [_view.canvas addPath:triangle withColor:[NSColor redColor]];
}

- (void) addQuadrangle:(NSPoint)point1 point2:(NSPoint)point2 point3:(NSPoint)point3 point4:(NSPoint)point4
{
    NSBezierPath *quandrangle = [NSBezierPath bezierPath];
    [self addQuadrangle:point1 point2:point2 point3:point3 point4:point4 toPath:quandrangle];
    [_view.canvas addPath:quandrangle withColor:[NSColor redColor]];
}

- (void) addRectangle:(NSRect)rect toPath:(NSBezierPath *)rectangle
{
    [rectangle appendBezierPathWithRect:rect];
}

- (void) addCircleAtPoint:(NSPoint)center withRadius:(CGFloat)radius toPath:(NSBezierPath *)circle
{
    static const CGFloat FBMagicNumber = 0.55228475;
    CGFloat controlPointLength = radius * FBMagicNumber;
    [circle moveToPoint:NSMakePoint(center.x - radius, center.y)];
    [circle curveToPoint:NSMakePoint(center.x, center.y + radius) controlPoint1:NSMakePoint(center.x - radius, center.y + controlPointLength) controlPoint2:NSMakePoint(center.x - controlPointLength, center.y + radius)];
    [circle curveToPoint:NSMakePoint(center.x + radius, center.y) controlPoint1:NSMakePoint(center.x + controlPointLength, center.y + radius) controlPoint2:NSMakePoint(center.x + radius, center.y + controlPointLength)];
    [circle curveToPoint:NSMakePoint(center.x, center.y - radius) controlPoint1:NSMakePoint(center.x + radius, center.y - controlPointLength) controlPoint2:NSMakePoint(center.x + controlPointLength, center.y - radius)];
    [circle curveToPoint:NSMakePoint(center.x - radius, center.y) controlPoint1:NSMakePoint(center.x - controlPointLength, center.y - radius) controlPoint2:NSMakePoint(center.x - radius, center.y - controlPointLength)];
}

- (void) addTriangle:(NSPoint)point1 point2:(NSPoint)point2 point3:(NSPoint)point3 toPath:(NSBezierPath *)path
{
    [path moveToPoint:point1];
    [path lineToPoint:point2];
    [path lineToPoint:point3];
    [path lineToPoint:point1];
}

- (void) addQuadrangle:(NSPoint)point1 point2:(NSPoint)point2 point3:(NSPoint)point3 point4:(NSPoint)point4 toPath:(NSBezierPath *)path
{
    [path moveToPoint:point1];
    [path lineToPoint:point2];
    [path lineToPoint:point3];
    [path lineToPoint:point4];
    [path lineToPoint:point1];
}


- (IBAction) onUnion:(id)sender
{
    [self onReset:sender];
    
    NSBezierPath *result = [[_view.canvas pathAtIndex:0] fb_union:[_view.canvas pathAtIndex:1]];
    [_view.canvas clear];
    [_view.canvas addPath:result withColor:[NSColor blueColor]];
}

- (IBAction) onIntersect:(id)sender
{
    [self onReset:sender];
    
    NSBezierPath *result = [[_view.canvas pathAtIndex:0] fb_intersect:[_view.canvas pathAtIndex:1]];
    [_view.canvas clear];
    [_view.canvas addPath:result withColor:[NSColor blueColor]];
}

- (IBAction) onDifference:(id)sender // Punch
{
    [self onReset:sender];
    
    NSBezierPath *result = [[_view.canvas pathAtIndex:0] fb_difference:[_view.canvas pathAtIndex:1]];
    [_view.canvas clear];
    [_view.canvas addPath:result withColor:[NSColor blueColor]];
}

- (IBAction) onJoin:(id)sender // XOR
{
    [self onReset:sender];
    
    NSBezierPath *result = [[_view.canvas pathAtIndex:0] fb_xor:[_view.canvas pathAtIndex:1]];
    [_view.canvas clear];
    [_view.canvas addPath:result withColor:[NSColor blueColor]];
}

- (IBAction) onCircleOverlappingRectangle:(id)sender
{
    _resetAction = @selector(addSomeOverlap);
    [self onReset:sender];
}

- (IBAction) onCircleInRectangle:(id)sender
{
    _resetAction = @selector(addCircleInRectangle);
    [self onReset:sender];
}

- (IBAction) onRectangleInCircle:(id)sender
{
    _resetAction = @selector(addRectangleInCircle);
    [self onReset:sender];
}

- (IBAction) onCircleOnRectangle:(id)sender
{
    _resetAction = @selector(addCircleOnRectangle);
    [self onReset:sender];
}

- (IBAction) onRectangleWithHoleOverlappingRectangle:(id)sender
{
    _resetAction = @selector(addHoleyRectangleWithRectangle);
    [self onReset:sender];
}

- (IBAction) onTwoRectanglesOverlappingCircle:(id)sender
{
    _resetAction = @selector(addCircleOnTwoRectangles);
    [self onReset:sender];
}

- (IBAction) onCircleOverlappingCircle:(id)sender
{
    _resetAction = @selector(addCircleOverlappingCircle);
    [self onReset:sender];    
}

- (IBAction) onComplexShapes:(id)sender
{
    _resetAction = @selector(addComplexShapes);
    [self onReset:sender];        
}

- (IBAction) onComplexShapes2:(id)sender
{
    _resetAction = @selector(addComplexShapes2);
    [self onReset:sender];        
}

- (IBAction) onTriangleInsideRectangle:(id)sender
{
    _resetAction = @selector(addTriangleInsideRectangle);
    [self onReset:sender];        
}

- (IBAction) onDiamondOverlappingRectangle:(id)sender
{
    _resetAction = @selector(addDiamondOverlappingRectangle);
    [self onReset:sender];        
}

- (IBAction) onDiamondInsideRectangle:(id)sender
{
    _resetAction = @selector(addDiamondInsideRectangle);
    [self onReset:sender];        
}

- (IBAction) onNonOverlappingContours:(id)sender
{
    _resetAction = @selector(addNonOverlappingContours);
    [self onReset:sender];            
}

- (IBAction) onMoreNonOverlappingContours:(id)sender
{
    _resetAction = @selector(addMoreNonOverlappingContours);
    [self onReset:sender];            
}

- (IBAction) onConcentricContours:(id)sender
{
    _resetAction = @selector(addConcentricContours);
    [self onReset:sender];            
}

- (IBAction) onMoreConcentricContours:(id)sender
{
    _resetAction = @selector(addMoreConcentricContours);
    [self onReset:sender];            
}

- (IBAction) onCircleOverlappingHole:(id)sender
{
    _resetAction = @selector(addOverlappingHole);
    [self onReset:sender];                
}

- (IBAction) onHoleOverlappingHole:(id)sender
{
    _resetAction = @selector(addHoleOverlappingHole);
    [self onReset:sender];                
}

- (IBAction) onCurvyShapeOverlappingRectangle:(id)sender
{
    _resetAction = @selector(addCurvyShapeOverlappingRectangle);
    [self onReset:sender];                
}

- (IBAction) onShowPoints:(id)sender
{
    _view.canvas.showPoints = !_view.canvas.showPoints;
    [_view setNeedsDisplay:YES];
}

- (IBAction) onShowIntersections:(id)sender
{
    _view.canvas.showIntersections = !_view.canvas.showIntersections;
    [_view setNeedsDisplay:YES];    
}

- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem
{
    NSMenuItem *menuItem = (NSMenuItem *)anItem;
    if ( [anItem action] == @selector(onCircleOverlappingRectangle:) ) {
        [menuItem setState:_resetAction == @selector(addSomeOverlap) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onCircleInRectangle:) ) {
        [menuItem setState:_resetAction == @selector(addCircleInRectangle) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onRectangleInCircle:) ) {
        [menuItem setState:_resetAction == @selector(addRectangleInCircle) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onCircleOnRectangle:) ) {
        [menuItem setState:_resetAction == @selector(addCircleOnRectangle) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onRectangleWithHoleOverlappingRectangle:) ) {
        [menuItem setState:_resetAction == @selector(addHoleyRectangleWithRectangle) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onTwoRectanglesOverlappingCircle:) ) {
        [menuItem setState:_resetAction == @selector(addCircleOnTwoRectangles) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onCircleOverlappingCircle:) ) {
        [menuItem setState:_resetAction == @selector(addCircleOverlappingCircle) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onComplexShapes:) ) {
        [menuItem setState:_resetAction == @selector(addComplexShapes) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onComplexShapes2:) ) {
        [menuItem setState:_resetAction == @selector(addComplexShapes2) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onTriangleInsideRectangle:) ) {
        [menuItem setState:_resetAction == @selector(addTriangleInsideRectangle) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onDiamondOverlappingRectangle:) ) {
        [menuItem setState:_resetAction == @selector(addDiamondOverlappingRectangle) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onDiamondInsideRectangle:) ) {
        [menuItem setState:_resetAction == @selector(addDiamondInsideRectangle) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onNonOverlappingContours:) ) {
        [menuItem setState:_resetAction == @selector(addNonOverlappingContours) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onMoreNonOverlappingContours:) ) {
        [menuItem setState:_resetAction == @selector(addMoreNonOverlappingContours) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onConcentricContours:) ) {
        [menuItem setState:_resetAction == @selector(addConcentricContours) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onMoreConcentricContours:) ) {
        [menuItem setState:_resetAction == @selector(addMoreConcentricContours) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onCircleOverlappingHole:) ) {
        [menuItem setState:_resetAction == @selector(addOverlappingHole) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onHoleOverlappingHole:) ) {
        [menuItem setState:_resetAction == @selector(addHoleOverlappingHole) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onCurvyShapeOverlappingRectangle:) ) {
        [menuItem setState:_resetAction == @selector(addCurvyShapeOverlappingRectangle) ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onShowPoints:) ) {
        [menuItem setState:_view.canvas.showPoints ? NSOnState : NSOffState];
    } else if ( [anItem action] == @selector(onShowIntersections:) ) {
        [menuItem setState:_view.canvas.showIntersections ? NSOnState : NSOffState];
    }

    
    return YES;
}

@end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.