Re: CGPoint wrapper?
Re: CGPoint wrapper?
- Subject: Re: CGPoint wrapper?
- From: Graff <email@hidden>
- Date: Thu, 23 Oct 2008 11:00:51 -0400
On Oct 23, 2008, at 3:06 AM, Ken Ferry wrote:
On Wed, Oct 22, 2008 at 9:09 PM, Graff <email@hidden> wrote:
NSPoint and CGPoint are structs that are essentially the same. You
can
convert between them with a simple cast:
NSPoint point = *(NSPoint *)&myCGPoint;
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaDrawingGuide/QuartzOpenGL/chapter_10_section_2.html
You can also use the function NSPointFromCGPoint() which does the
exact
same thing for you:
NSPoint point = NSPointFromCGPoint(myCGPoint);
(Declared in NSGeometry.h)
The function is actually implemented a bit better than the cast
above, in
that the function does not violate strict aliasing[1].
-Ken
[1]:
http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html
Very interesting, I hadn't considered that issue. Thanks for pointing
it out.
When I looked up that function on the internet I saw that it was
defined as a simple cast. Now that I look at the actual header file
on my system I see that Apple is now performing the cast by way of a
union (referred to as type-punning in the article you linked). It's
an elegant solution and very instructional.
- Graff
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden