raylib
raylib copied to clipboard
[Raymath] Add C++ operator overloads for common math function
This PR adds operator overloads for C++ for the math operations that have raymath functions. Vectror2, 3, 4, and Quaternion are supported. All operators are defined inline, and the define RAYLIB_DISABLE_VECTOR_OPERATORS can be used to disable this functionality.
While raylib is C, and not C++ and normally C++ code should be kept out of raylib, these operators offer exceptional utility and thus are an exception.
For credit, this idea was from @Peter0x44 initially.
Actually, I got the idea from box2d which does the same thing.
Should the operators call raymath functions or should they just be inlined? There is a policy that the functions don't call each other, not sure if it should be extended to these operators or not.
I very specifically had them call the raymath functions so that we did not duplicate code. If a change has to be made to some math function, I don't want that change to have to be made in two places. The goal of this is to minimize maintenance cost.
I would say most of the functions the operators call are not subject to change so inlining them might be better to stay consistent. But that's up to Ray.
@JeffM2501 @Peter0x44 Thanks for the improvement, it looks good to me, let me know if it is ready to be merged!
I think it is good for 5.5
@JeffM2501 @Peter0x44 thanks for the improvement! merged! I'm reviewing the formating and details myself!
@JeffM2501 @Peter0x44 Just noticed there are no operators for Matrix, should there be some added?
@JeffM2501 @Peter0x44 Just noticed there are no operators for
Matrix, should there be some added? I just added some matrix operators. I'm not sure they are super important.
@JeffM2501 @Peter0x44 Just noticed there are no operators for
Matrix, should there be some added?
I have made another PR for matrix operators and merged back the formatting changes.
@RobLoach for visibility, this can have possible conflicts with the operators that raylib-cpp does, you should be aware of it when you update raylib-cpp to 5.5 :)
Oh, this is :fire::fire::fire::fire::fire::fire:
Feel free to move anything else in too :wink: