You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#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:
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?
So apparently, we can do something like this:
CGVop
stands for "CGVector operation". Then, we can do something like this: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
andCGPointFromVector
:Thoughts?
The text was updated successfully, but these errors were encountered: