NSBezierPath bounds and containsPoint, having troubles.
NSBezierPath bounds and containsPoint, having troubles.
- Subject: NSBezierPath bounds and containsPoint, having troubles.
- From: "Brian O'Brien" <email@hidden>
- Date: Wed, 11 Jan 2006 15:31:46 -0700
I've been having two problems with NSBezierPaths...
1) the bounds returned seem wrong.
2) the interior test seem wrong. (even when I can get the bounds to
work)
Here is a sample code to try to demonstrate the problems I'm having.
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
int fround(float x)
{
if (x < 0.0)
return ((int) x - 0.5f);
return((int) x + 0.5f);
}
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int x, y, x1, y1, x2, y2, w, h;
NSRect r;
NSRect bounds;
NSPoint pt;
r.origin.x = 10.0f;
r.origin.y = 10.0f;
r.size.width = 5.0f;
r.size.height = 5.0f;
NSBezierPath *p = [NSBezierPath bezierPathWithOvalInRect:r];
bounds = [p bounds];
printf("The bounds are ((%f,%f), (%f, %f))\n", bounds.origin.x,
bounds.origin.y, bounds.size.width, bounds.size.height);
x1 = fround(bounds.origin.x);
y1 = fround(bounds.origin.y);
w = fround(bounds.size.width);
h = fround(bounds.size.height);
printf("The bounds are ((%d,%d), (%d,%d))\n", x1, y1, w, h);
x2 = x1 + w + 1;
y2 = y1 + h + 1;
for (y=y1; y < y2; ++y)
{
for (x=x1; x < x2; ++x)
{
pt.x = (float)x;
pt.y = (float)y;
if ([p containsPoint:pt])
printf("#");
else
printf("-");
}
printf("\n");
}
[pool release];
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden