GithubHelp home page GithubHelp logo

cgvector-awesome's People

Contributors

codecat avatar samgreen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cgvector-awesome's Issues

License

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

Wrong optimizations for 64 bit CPUs

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.

Proposal: Vector and Point operations macro

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.