Re: A pie analyzer
Re: A pie analyzer
- Subject: Re: A pie analyzer
- From: Shaun Wexler <email@hidden>
- Date: Sun, 20 Apr 2003 22:13:29 -0700
On Saturday, April 19, 2003, at 01:23 PM, Scott Anguish wrote:
http://homepage.mac.com/tonyswu/temp/c1.gif
My problem is, NSView only allows me to add tooltip for a rect.
I thought about using NSBezierPath's containsPoint method.
But I am not sure if it's a good idea since i'll be calling this
method for average 5 to 8 times each time a user moves his mouse.
I'd suggest trying it and see if it bogs down. NSBezierPath may very
well be optimized to check the bounds of the shape before actually
checking the shape itself.
I would hope so!
Also, (being unfamiliar with non-IB tooltip handling), using a timer to
delay the tooltip calculation until its display was necessary would be
another optimization.
The other alternative is to figure it out mathematically (determine
the rotational angle of the point to see which 'slice' it would be in,
and then it's distance from the center to see if it is actually within
the slice). Good old geometry.. :-) That's pretty much an atan, two
squares and a square root (plus of course some add/sub action)
He should compute the square of the diameter ONCE for comparison
purposes, rather than the sqrt (or fqsrte) of each cursor location,
which would eliminate that instruction. Correct? And I have a nice
fast_atan2f() function which can be used to save many cycles, as well.
Since you know the shape of the target area, this is probably the
best method to use.
Certainly the "cleanest" way to code it, IMO. After examining his
.gif, I see that he uses alpha, which would make it less than robust
and/or much harder to code.
I'd recommend against the testing the pixel color method.
I suggested the pixel color method, since he was interested in
performance, and that's used in some OpenGL app's, for efficiency.
Calculating an atan and a sqrt whenever the mouse moves is certainly
not a high-performance implementation. Granted, this would only be
when the cursor was in the view's rect, and hopefully then only upon a
MouseMoved event, but hey... ;-)
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.