Created
November 16, 2022 23:22
-
-
Save xenobrain/e3d603ae6c7a7c0211551fd8b42074d8 to your computer and use it in GitHub Desktop.
DragonRuby MatrixFunctions monkey patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Vec2Extensions | |
def + other | |
return super other if other.is_a? Vec2 | |
vec2 x + other, y + other if other.is_a? Numeric | |
end | |
def - other | |
return vec2 x - other.x, y - other.y if other.is_a? Vec2 | |
vec2 x - other, y - other if other.is_a? Numeric | |
end | |
def * other | |
return super other if other.is_a? Vec2 | |
vec2 x * other, y * other if other.is_a? Numeric | |
end | |
def / other | |
vec2 x / other, y / other if other.is_a? Numeric | |
end | |
end | |
class Vec2 | |
prepend Vec2Extensions | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment