0

I need some help reversing a triangle cutout.

I can make the rectangle with a triangle cutout on it's right:

enter image description here

using these coordinates:

NSInteger imageWidth=12, imageHeight=22;
NSImage* destImage = [[NSImage alloc] initWithSize:NSMakeSize(imageWidth,imageHeight)];
[destImage lockFocus];

// Constructing the path
NSBezierPath *leftTriangle = [NSBezierPath bezierPath];
[leftTriangle setLineWidth:1.0];
[leftTriangle moveToPoint:NSMakePoint(imageWidth+1, 0.0)];
[leftTriangle lineToPoint:NSMakePoint( 0, imageHeight/2.0)];
[leftTriangle lineToPoint:NSMakePoint( imageWidth+1, imageHeight)];
[leftTriangle closePath];
[[NSColor controlColor] setFill];
[[NSColor clearColor] setStroke];

...

What coordinates would I use to make the cutout on the other side, like this:

enter image description here

UPDATE: Inelegantly solved:

It helped to remember that measurements begin at the bottom left.

NSBezierPath *rightTriangle = [NSBezierPath bezierPath]; [rightTriangle setLineWidth:1.0]; [rightTriangle moveToPoint:NSMakePoint(0.0, 29)]; [rightTriangle lineToPoint:NSMakePoint( imageWidth, 20)]; [rightTriangle lineToPoint:NSMakePoint(0.0, 11)];

ICL1901
  • 7,632
  • 14
  • 90
  • 138
  • I don't understand the dimensions in that code; it looks like the triangle is unrelated to the image it appears within. How is the triangle rendered within the image? – trojanfoe Oct 09 '13 at 13:55
  • To be honest, I copied that code. I guess I should figure out my own code – ICL1901 Oct 09 '13 at 14:48
  • 1
    Well it looks like that code generates an image with just the triangle in, which must then be composited onto the main image somewhere else. So the solution lies in the code you show (to reverse the direction of the triangle) and in that other code (to place it on the left side of the image). – trojanfoe Oct 09 '13 at 14:50
  • Thank you for that info. I will try to remember where I got that snippet, and / or just rewrite. If I can find it quickly, I will add to my question. I appreciate the help. – ICL1901 Oct 09 '13 at 15:05
  • I've added some more code, where this routine is called. I will go through it myself. Pressure day.. – ICL1901 Oct 09 '13 at 15:12
  • @trojanfoe, rereading your comments gave me the focus I needed, and I solved the issue today. If you write you comment as an answer, I can accept it. And thanks. – ICL1901 Oct 10 '13 at 15:37
  • Don't worry it's not important; If I was solving this issue I would have the triangle images pre-made, included as part of the app resources, and would then composite them at runtime with the target image. Code to do compositing is pretty commonly available from this, and other, sites. – trojanfoe Oct 10 '13 at 15:44
  • Yea, I may change to compositing images. I have an animation working between frames. I'll see how it looks, and thanks again. – ICL1901 Oct 10 '13 at 16:54

0 Answers0