Browse Source

Merge pull request #61 from jmiskovic/add/vectors-as-numbers

Vector ops accepting numbers for components
Bjorn 3 years ago
parent
commit
8f70c17387

+ 7 - 2
api/lovr/math/Vec2/add.lua

@@ -8,7 +8,12 @@ return {
     },
     x = {
       type = 'number',
-      description = 'A number to add to each component.'
+      description = 'A value to add to x component.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to add to y component.'
     }
   },
   returns = {
@@ -23,7 +28,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y' },
       returns = { 'v' }
     }
   },

+ 20 - 4
api/lovr/math/Vec2/distance.lua

@@ -2,17 +2,33 @@ return {
   summary = 'Get the distance to another vector.',
   description = 'Returns the distance to another vector.',
   arguments = {
-    {
-      name = 'u',
+    u = {
       type = 'Vec2',
       description = 'The vector to measure the distance to.'
+    },
+    x = {
+      type = 'number',
+      description = 'A value of x component to measure distance to.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to measure distance to.'
     }
   },
   returns = {
-    {
-      name = 'distance',
+    distance = {
       type = 'number',
       description = 'The distance to `u`.'
+    },
+  },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'distance' }
+    },
+    {
+      arguments = { 'x', 'y' },
+      returns = { 'distance' }
     }
   },
   related = {

+ 7 - 2
api/lovr/math/Vec2/div.lua

@@ -8,7 +8,12 @@ return {
     },
     x = {
       type = 'number',
-      description = 'The number to divide each component by.'
+      description = 'A value to divide x component by.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to divide y component by.'
     }
   },
   returns = {
@@ -23,7 +28,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y' },
       returns = { 'v' }
     }
   },

+ 21 - 5
api/lovr/math/Vec2/dot.lua

@@ -2,23 +2,39 @@ return {
   summary = 'Get the dot product with another vector.',
   description = 'Returns the dot product between this vector and another one.',
   arguments = {
-    {
-      name = 'u',
+    u = {
       type = 'Vec2',
       description = 'The vector to compute the dot product with.'
+    },
+    x = {
+      type = 'number',
+      description = 'A value of x component to compute the dot product with.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to compute the dot product with.'
     }
   },
   returns = {
-    {
-      name = 'dot',
+    dot = {
       type = 'number',
       description = 'The dot product between `v` and `u`.'
     }
   },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'dot' }
+    },
+    {
+      arguments = { 'x', 'y' },
+      returns = { 'dot' }
+    }
+  },
   notes = [[
     This is computed as:
 
-        dot = v.x * u.x + v.y * u.y + v.z * u.z
+        dot = v.x * u.x + v.y * u.y
 
     The vectors are not normalized before computing the dot product.
   ]]

+ 19 - 2
api/lovr/math/Vec2/lerp.lua

@@ -12,6 +12,14 @@ return {
       type = 'Vec2',
       description = 'The vector to lerp towards.'
     },
+    x = {
+      type = 'number',
+      description = 'A value of x component to lerp towards.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to lerp towards.'
+    },
     {
       name = 't',
       type = 'number',
@@ -19,12 +27,21 @@ return {
     }
   },
   returns = {
-    {
-      name = 'v',
+    v = {
       type = 'Vec2',
       description = 'The original vector, containing the new lerped values.'
     }
   },
+  variants = {
+    {
+      arguments = { 'u', 't' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x', 'y', 't' },
+      returns = { 'v' }
+    }
+  },
   related = {
     'Quat:slerp'
   }

+ 7 - 2
api/lovr/math/Vec2/mul.lua

@@ -8,7 +8,12 @@ return {
     },
     x = {
       type = 'number',
-      description = 'The number to multiply each component by.'
+      description = 'A value to multiply x component by.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to multiply y component by.'
     }
   },
   returns = {
@@ -23,7 +28,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y' },
       returns = { 'v' }
     }
   },

+ 8 - 3
api/lovr/math/Vec2/sub.lua

@@ -8,8 +8,13 @@ return {
     },
     x = {
       type = 'number',
-      description = 'A number to subtract from each component.'
-    }
+      description = 'A value to subtract from x component.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to subtract from y component.'
+    },
   },
   returns = {
     v = {
@@ -23,7 +28,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y' },
       returns = { 'v' }
     }
   },

+ 12 - 2
api/lovr/math/Vec3/add.lua

@@ -8,7 +8,17 @@ return {
     },
     x = {
       type = 'number',
-      description = 'A number to add to each component.'
+      description = 'A value to add to x component.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to add to y component.'
+    },
+    z = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to add to z component.'
     }
   },
   returns = {
@@ -23,7 +33,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y', 'z' },
       returns = { 'v' }
     }
   },

+ 24 - 4
api/lovr/math/Vec3/cross.lua

@@ -5,19 +5,39 @@ return {
     new `v` will be perpendicular to both the old `v` and `u`.
   ]],
   arguments = {
-    {
-      name = 'u',
+    u = {
       type = 'Vec3',
       description = 'The vector to compute the cross product with.'
+    },
+    x = {
+      type = 'number',
+      description = 'A value of x component to compute cross product with.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to compute cross product with.'
+    },
+    z = {
+      type = 'number',
+      description = 'A value of z component to compute cross product with.'
     }
   },
   returns = {
-    {
-      name = 'v',
+    v = {
       type = 'Vec3',
       description = 'The original vector, with the cross product as its values.'
     }
   },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x', 'y', 'z' },
+      returns = { 'v' }
+    }
+  },
   notes = 'The vectors are not normalized before or after computing the cross product.',
   related = {
     'Vec3:dot'

+ 24 - 3
api/lovr/math/Vec3/distance.lua

@@ -2,19 +2,40 @@ return {
   summary = 'Get the distance to another vector.',
   description = 'Returns the distance to another vector.',
   arguments = {
-    {
+    u = {
       name = 'u',
       type = 'Vec3',
       description = 'The vector to measure the distance to.'
+    },
+    x = {
+      type = 'number',
+      description = 'A value of x component to measure distance to.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to measure distance to.'
+    },
+    z = {
+      type = 'number',
+      description = 'A value of z component to measure distance to.'
     }
   },
   returns = {
-    {
-      name = 'distance',
+    distance = {
       type = 'number',
       description = 'The distance to `u`.'
     }
   },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'distance' }
+    },
+    {
+      arguments = { 'x', 'y', 'z' },
+      returns = { 'distance' }
+    }
+  },
   related = {
     'Vec3:length'
   }

+ 12 - 2
api/lovr/math/Vec3/div.lua

@@ -8,7 +8,17 @@ return {
     },
     x = {
       type = 'number',
-      description = 'The number to divide each component by.'
+      description = 'A value to divide x component by.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to divide y component by.'
+    },
+    z = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to divide z component by.'
     }
   },
   returns = {
@@ -23,7 +33,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y', 'z' },
       returns = { 'v' }
     }
   },

+ 24 - 4
api/lovr/math/Vec3/dot.lua

@@ -2,19 +2,39 @@ return {
   summary = 'Get the dot product with another vector.',
   description = 'Returns the dot product between this vector and another one.',
   arguments = {
-    {
-      name = 'u',
+    u = {
       type = 'Vec3',
       description = 'The vector to compute the dot product with.'
+    },
+    x = {
+      type = 'number',
+      description = 'A value of x component to compute the dot product with.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to compute the dot product with.'
+    },
+    z = {
+      type = 'number',
+      description = 'A value of z component to compute the dot product with.'
     }
   },
   returns = {
-    {
-      name = 'dot',
+    dot = {
       type = 'number',
       description = 'The dot product between `v` and `u`.'
     }
   },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'dot' }
+    },
+    {
+      arguments = { 'x', 'y', 'z' },
+      returns = { 'dot' }
+    }
+  },
   notes = [[
     This is computed as:
 

+ 25 - 6
api/lovr/math/Vec3/lerp.lua

@@ -7,24 +7,43 @@ return {
     input vector, and a value of `.5` will set the components to be halfway between the two vectors.
   ]],
   arguments = {
-    {
-      name = 'u',
+    u = {
       type = 'Vec3',
       description = 'The vector to lerp towards.'
     },
-    {
-      name = 't',
+    x = {
+      type = 'number',
+      description = 'A value of x component to lerp towards.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to lerp towards.'
+    },
+    z = {
+      type = 'number',
+      description = 'A value of z component to lerp towards.'
+    },
+    t = {
       type = 'number',
       description = 'The lerping parameter.'
     }
   },
   returns = {
-    {
-      name = 'v',
+    v = {
       type = 'Vec3',
       description = 'The original vector, containing the new lerped values.'
     }
   },
+  variants = {
+    {
+      arguments = { 'u', 't' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x', 'y', 'z', 't' },
+      returns = { 'v' }
+    }
+  },
   related = {
     'Quat:slerp'
   }

+ 12 - 2
api/lovr/math/Vec3/mul.lua

@@ -8,7 +8,17 @@ return {
     },
     x = {
       type = 'number',
-      description = 'The number to multiply each component by.'
+      description = 'A value to multiply x component by.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to multiply y component by.'
+    },
+    z = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to multiply z component by.'
     }
   },
   returns = {
@@ -23,7 +33,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y', 'z' },
       returns = { 'v' }
     }
   },

+ 12 - 2
api/lovr/math/Vec3/sub.lua

@@ -8,7 +8,17 @@ return {
     },
     x = {
       type = 'number',
-      description = 'A number to subtract from each component.'
+      description = 'A value to subtract from x component.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to subtract from y component.'
+    },
+    z = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to subtract from z component.'
     }
   },
   returns = {
@@ -23,7 +33,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y', 'z' },
       returns = { 'v' }
     }
   },

+ 17 - 2
api/lovr/math/Vec4/add.lua

@@ -8,7 +8,22 @@ return {
     },
     x = {
       type = 'number',
-      description = 'A number to add to each component.'
+      description = 'A value to add to x component.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to add to y component.'
+    },
+    z = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to add to z component.'
+    },
+    w = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to add to w component.'
     }
   },
   returns = {
@@ -23,7 +38,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y', 'z', 'w' },
       returns = { 'v' }
     }
   },

+ 28 - 4
api/lovr/math/Vec4/distance.lua

@@ -2,19 +2,43 @@ return {
   summary = 'Get the distance to another vector.',
   description = 'Returns the distance to another vector.',
   arguments = {
-    {
-      name = 'u',
+    u = {
       type = 'Vec4',
       description = 'The vector to measure the distance to.'
+    },
+    x = {
+      type = 'number',
+      description = 'A value of x component to measure distance to.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to measure distance to.'
+    },
+    z = {
+      type = 'number',
+      description = 'A value of z component to measure distance to.'
+    },
+    w = {
+      type = 'number',
+      description = 'A value of w component to measure distance to.'
     }
   },
   returns = {
-    {
-      name = 'distance',
+    distance = {
       type = 'number',
       description = 'The distance to `u`.'
     }
   },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'distance' }
+    },
+    {
+      arguments = { 'x', 'y', 'z', 'w' },
+      returns = { 'distance' }
+    }
+  },
   related = {
     'Vec4:length'
   }

+ 17 - 2
api/lovr/math/Vec4/div.lua

@@ -8,7 +8,22 @@ return {
     },
     x = {
       type = 'number',
-      description = 'The number to divide each component by.'
+      description = 'A value to divide x component by.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to divide y component by.'
+    },
+    z = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to divide z component by.'
+    },
+    w = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to divide w component by.'
     }
   },
   returns = {
@@ -23,7 +38,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y', 'z', 'w' },
       returns = { 'v' }
     }
   },

+ 28 - 4
api/lovr/math/Vec4/dot.lua

@@ -2,19 +2,43 @@ return {
   summary = 'Get the dot product with another vector.',
   description = 'Returns the dot product between this vector and another one.',
   arguments = {
-    {
-      name = 'u',
+    u = {
       type = 'Vec4',
       description = 'The vector to compute the dot product with.'
+    },
+    x = {
+      type = 'number',
+      description = 'A value of x component to compute the dot product with.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to compute the dot product with.'
+    },
+    z = {
+      type = 'number',
+      description = 'A value of z component to compute the dot product with.'
+    },
+    w = {
+      type = 'number',
+      description = 'A value of w component to compute the dot product with.'
     }
   },
   returns = {
-    {
-      name = 'dot',
+    dot = {
       type = 'number',
       description = 'The dot product between `v` and `u`.'
     }
   },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'dot' }
+    },
+    {
+      arguments = { 'x', 'y', 'z', 'w' },
+      returns = { 'dot' }
+    }
+  },
   notes = [[
     This is computed as:
 

+ 29 - 6
api/lovr/math/Vec4/lerp.lua

@@ -7,24 +7,47 @@ return {
     input vector, and a value of `.5` will set the components to be halfway between the two vectors.
   ]],
   arguments = {
-    {
-      name = 'u',
+    u = {
       type = 'Vec4',
       description = 'The vector to lerp towards.'
     },
-    {
-      name = 't',
+    x = {
+      type = 'number',
+      description = 'A value of x component to lerp towards.'
+    },
+    y = {
+      type = 'number',
+      description = 'A value of y component to lerp towards.'
+    },
+    z = {
+      type = 'number',
+      description = 'A value of z component to lerp towards.'
+    },
+    w = {
+      type = 'number',
+      description = 'A value of w component to lerp towards.'
+    },    
+    t = {
       type = 'number',
       description = 'The lerping parameter.'
     }
   },
   returns = {
-    {
-      name = 'v',
+    v = {
       type = 'Vec4',
       description = 'The original vector, containing the new lerped values.'
     }
   },
+  variants = {
+    {
+      arguments = { 'u', 't' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x', 'y', 'z', 'w', 't' },
+      returns = { 'v' }
+    }
+  },
   related = {
     'Quat:slerp'
   }

+ 17 - 2
api/lovr/math/Vec4/mul.lua

@@ -8,7 +8,22 @@ return {
     },
     x = {
       type = 'number',
-      description = 'The number to multiply each component by.'
+      description = 'A value to multiply x component by.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to multiply y component by.'
+    },
+    z = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to multiply z component by.'
+    },
+    w = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to multiply w component by.'
     }
   },
   returns = {
@@ -23,7 +38,7 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y', 'z', 'w' },
       returns = { 'v' }
     }
   },

+ 22 - 7
api/lovr/math/Vec4/sub.lua

@@ -3,17 +3,32 @@ return {
   description = 'Subtracts a vector or a number from the vector.',
   arguments = {
     u = {
-      type = 'Vec2',
+      type = 'Vec4',
       description = 'The other vector.'
     },
     x = {
       type = 'number',
-      description = 'A number to subtract from each component.'
+      description = 'A value to subtract from x component.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to subtract from y component.'
+    },
+    z = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to subtract from z component.'
+    },
+    w = {
+      type = 'number',
+      default = 'x',
+      description = 'A value to subtract from w component.'
     }
   },
   returns = {
     v = {
-      type = 'Vec2',
+      type = 'Vec4',
       description = 'The original vector.'
     }
   },
@@ -23,13 +38,13 @@ return {
       returns = { 'v' }
     },
     {
-      arguments = { 'x' },
+      arguments = { 'x', 'y', 'z', 'w' },
       returns = { 'v' }
     }
   },
   related = {
-    'Vec2:add',
-    'Vec2:mul',
-    'Vec2:div'
+    'Vec4:add',
+    'Vec4:mul',
+    'Vec4:div'
   }
 }