Forums | MacLife
Wide is the new black
You are not logged in.
#1 2008-04-04 10:42 am
- xcode
- Member
- Registered: 2003-12-13
- Posts: 34
Adding CGPoints?
Is there an easy way of adding two CGPoints?
I'm looking to add and subtract points on a plane defined as CGPoints.
Such as (1,2) + (1,2) = (2,4)
I can't figure this out! 
Thank you
Offline
#2 2008-04-04 11:21 am
Re: Adding CGPoints?
No there isn't. However, I do have a few suggestions.
If you are using C++, it's possible to create your own structure or class that overloads some of the operators. You could then use this class to keep track of all of your points, and convert it to a CGPoint when you actually need to draw something. Here are some FAQs for operator overloading to get you started. If you are using C, the there is no way for you to overload your operators to use other types like primitives.
That said, is there any reason you're using Carbon? Carbon has been deprecated, and also doesn't have 64 bit versions of the libraries. Any new development should be done in Cocoa. While it is something new to learn, it really is much easier to use than Carbon, especially for interfaces. Though you must use ObjectiveC, it is a true extension to C, plus you can combine it with C++ if you use ObjectiveC++. (by changing the extension of your file to .mm)
Offline
