NSBezierPath containsPoint is buggy?
NSBezierPath containsPoint is buggy?
- Subject: NSBezierPath containsPoint is buggy?
- From: "Brian O'Brien" <email@hidden>
- Date: Mon, 16 Jan 2006 16:23:55 -0700
I have written an application that draws shapes on the screen.
The application then needs to know if a point is inside one of these
shapes.
However my log shows that there is a problem with the NSBezierPath
containsPoint method.
Here is the code more or less:
(I haven't shown the affine transform code to keep things simple..)
int fround(float x)
{
if (x < 0.0)
return((int) (x - 0.5f));
return((int) (x + 0.5f));
}
- (IBAction)doIt:(id)sender
{
int x, y, x1, y1, x2, y2, w, h;
NSRect r;
NSRect pathBounds;
NSPoint pt;
r.origin.x = 100.0f;
r.origin.y = 100.0f;
r.size.width = 40.0f;
r.size.height = 40.0f;
NSBezierPath *p = [NSBezierPath bezierPathWithOvalInRect:r];
pathBounds = [p bounds];
printf("The paths bounding box is ((%f,%f), (%f, %f))\n",
pathBounds.origin.x, pathBounds.origin.y, pathBounds.size.width,
pathBounds.size.height);
x1 = fround(pathBounds.origin.x);
y1 = fround(pathBounds.origin.y);
w = fround(pathBounds.size.width);
h = fround(pathBounds.size.height);
x2 = x1 + w + 1;
y2 = y1 + h + 1;
printf("The paths integer bounding box is ((%d,%d), (%d,%d))\n",
x1, y1, w, h);
printf("The bounds are ((%d,%d), (%d,%d))\n", x1, y1, x2, y2);
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");
}
}
Here is a log of one of an oval that has been slightly rotated....
there are holes..
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - - # # # # # # # # # # # - - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - # # # # # # # # # # # # # # # # - - - - - - - -
- - - - - - - - - -
- - - - - - - - - # # # # # # # # # # # # # # # # # # # # # - - - - -
- - - - - - - - - -
- - - - - - - # # # # # # # # # # # # # # # # # # # # # # # # # - - -
- - - - - - - - - -
- - - - - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # -
- - - - - - - - - -
- - - - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
- - - - - - - - - -
- - - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # - - - - - - - -
- - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # - - - - - - -
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # - - - - - -
- - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # - - - - -
- - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # - - - -
- - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # - - - -
- - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # - - -
- - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # - -
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # -
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # -
- - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # -
- - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - - - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - - - - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - - - - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - - - - - - # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # #
- - - - - - - - # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # - - - - # <--- Definitely wrong
- - - - - - - - - # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # -
- - - - - - - - - - # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # - -
- - - - - - - - - - - - # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # - - -
- - - - - - - - - - - - - # # # # # # # # # # # # # # # # # # # # # #
# # # # # # - - - -
- - - - - - - - - - - - - - - # # # # # # # # # # # # # # # # # # # #
# # # # # - - - - -
- - - - - - - - - - - - - - - - - # # # # # # # # # # # # # # # # # #
# # # - - - - - - -
- - - - - - - - - - - - - - - - - - - - # # # # # # # # # # # # # # #
# - - - - - - - - -
I think that this demonstrates that there is a bug in the interior
test of the
bezier curve. Can anyone else duplicate this problem and/or have a
workaround?
_______________________________________________
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