Skip to content

Instantly share code, notes, and snippets.

@Kaiochao
Created June 3, 2017 01:29
Show Gist options
  • Save Kaiochao/520f10187f8c9317f85932b7e2fcbde9 to your computer and use it in GitHub Desktop.
Save Kaiochao/520f10187f8c9317f85932b7e2fcbde9 to your computer and use it in GitHub Desktop.
BYOND 2D Vectors
vector2
var
x
y
New(x = 0, y = 0)
src.x = x
src.y = y
proc
vector2(x, y)
return new/vector2(x, y)
vector2_add(vector2/a, vector2/b)
return new/vector2(a.x + b.x, a.y + b.y)
vector2_subtract(vector2/a, vector2/b)
return new/vector2(a.x - b.x, a.y - b.y)
vector2_multiply(vector2/a, s)
return new/vector2(a.x * s, a.y * s)
vector2_divide(vector2/a, s)
return new/vector2(a.x / s, a.y / s)
vector2_dot(vector2/a, vector2/b)
return a.x * b.x + a.y * b.y
vector2_magnitude(vector2/a)
return sqrt(vector2_dot(a, a))
vector2_normalize(vector2/a)
return vector2_divide(a, vector2_magnitude(a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment