Support algebraic operations on Vector types

This is a nice feature in PaperJS and one of the few things I miss in raylib compared to working with other tools.

Vector2 vector1 = (Vector2){3, 5};
Vector2 vector2 = (Vector2){1, 7};
Vector2 result;

result = vector1 + vector2; // result is {4, 12}
result = vector1 * vector2; // result is {3, 35}
et cetera


  • Yes, that would be great... unfortunately, C language does not support operator overloading, that's a C++ feature. raylib uses internally its own math library (; it's portable and implements some math funtions (mostly for 3D). I can add some Vector2 functions for basic operations:

    Vector2 Vector2Add(Vector2 v1, Vector2 v2);
    Vector2 Vector2Subtract(Vector2 v1, Vector2 v2);
    Vector2 Vector2Product(Vector2 v1, Vector2 v2);

    But for basic Vector2 operations it's not that helpful...
  • Ah, gotcha! Thank you for explaining. Please don't worry about adding those functions - I think you're right that they're not worth the trouble (it's not an order of magnitude type of convenience improvement like operator overloading would be). If I find that I do miss them, I can cook them up myself.
Sign In or Register to comment.