samgreen / cgvector-awesome Goto Github PK
View Code? Open in Web Editor NEWAdditions to CoreGraphics CGVector, most useful with Apple's SpriteKit
Additions to CoreGraphics CGVector, most useful with Apple's SpriteKit
Doesn't seem to me like this code contains any kind of license. Would be great to have that so I can reuse it as appropriate.
Thanks
On 64 bit CPUs, some functions return invalid values due to the optimization that seems to be specifically made for 32 bit. CGVectorMultiplyByScalar
for example.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.