Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Vector and Point operations macro #5

Open
codecat opened this issue Feb 18, 2015 · 3 comments
Open

Proposal: Vector and Point operations macro #5

codecat opened this issue Feb 18, 2015 · 3 comments

Comments

@codecat
Copy link
Contributor

codecat commented Feb 18, 2015

So apparently, we can do something like this:

#define CGV(x, y) CGVectorMake(x, y)
#define CGP(x, y) CGPointMake(x, y)
#define CGVop(a, op, b) CGV(a.dx op b.dx, a.dy op b.dy)
#define CGPop(a, op, b) CGP(a.x op b.x, a.y op b.y)

CGVop stands for "CGVector operation". Then, we can do something like this:

CGVector a = CGV(10, 10);
CGVector b = CGV(2, 2);
CGVector c = CGVop(a, *, b); // {20, 20}

The downsides are that you'd need a different macro in order to do something like CGVop(a, *, 2.0f), and it looks kinda ugly. But it's short. I like short. Too bad ObjC doesn't have any kind of operator overloading.

It also raises problems when you do something like this CGVop(CGV(10, 10), +, CGVop(20, 20)), which will execute the left hand and right hand side, twice.

Additionally, I've also created some shorthands for CGVectorFromPoint and CGPointFromVector:

#define P2V(p) CGVectorFromPoint(p)
#define V2P(v) CGPointFromVector(v)

Thoughts?

@codecat
Copy link
Contributor Author

codecat commented Feb 18, 2015

The other choice is offer an alternative Objective C++ implementation ^^

@samgreen
Copy link
Owner

Hey Angelo thanks for all the feedback! I'll think it over today and get back to you. I have a couple of ideas in this vein and I'd like to get them implemented. Additionally I'm considering creating a podspec to release this library as a CocoaPod. Do you use pods at all?

@codecat
Copy link
Contributor Author

codecat commented Feb 18, 2015

I haven't yet. Should really give it a try someday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants