Browse Source

rm metamethods; Vec2;

bjorn 5 years ago
parent
commit
ededcc43cf

+ 35 - 0
api/lovr/math/Vec2/add.lua

@@ -0,0 +1,35 @@
+return {
+  summary = 'Add a vector or a number to the vector.',
+  description = 'Adds a vector or a number to the vector.',
+  arguments = {
+    u = {
+      type = 'Vec2',
+      description = 'The other vector.'
+    },
+    x = {
+      type = 'number',
+      description = 'A number to add to each component.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec2',
+      description = 'The original vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec2:sub',
+    'Vec2:mul',
+    'Vec2:div'
+  }
+}

+ 21 - 0
api/lovr/math/Vec2/distance.lua

@@ -0,0 +1,21 @@
+return {
+  summary = 'Get the distance to another vector.',
+  description = 'Returns the distance to another vector.',
+  arguments = {
+    {
+      name = 'u',
+      type = 'Vec2',
+      description = 'The vector to measure the distance to.'
+    }
+  },
+  returns = {
+    {
+      name = 'distance',
+      type = 'number',
+      description = 'The distance to `u`.'
+    }
+  },
+  related = {
+    'Vec2:length'
+  }
+}

+ 35 - 0
api/lovr/math/Vec2/div.lua

@@ -0,0 +1,35 @@
+return {
+  summary = 'Divides the vector by a vector or a number.',
+  description = 'Divides the vector by a vector or a number.',
+  arguments = {
+    u = {
+      type = 'Vec2',
+      description = 'The other vector to divide the components by.'
+    },
+    x = {
+      type = 'number',
+      description = 'The number to divide each component by.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec2',
+      description = 'The original vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec2:add',
+    'Vec2:sub',
+    'Vec2:mul'
+  }
+}

+ 25 - 0
api/lovr/math/Vec2/dot.lua

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

+ 8 - 10
api/lovr/math/vec3/__len.lua → api/lovr/math/Vec2/length.lua

@@ -1,13 +1,7 @@
 return {
   summary = 'Get the length of the vector.',
   description = 'Returns the length of the vector.',
-  arguments = {
-    {
-      name = 'v',
-      type = 'vec3',
-      description = 'The vector.'
-    }
-  },
+  arguments = {},
   returns = {
     {
       name = 'length',
@@ -15,9 +9,13 @@ return {
       description = 'The length of the vector.'
     }
   },
+  notes = [[
+    The length is equivalent to this:
+
+        math.sqrt(v.x * v.x + v.y * v.y)
+  ]],
   related = {
-    'vec3:length',
-    'vec3:normalize',
-    'vec3:distance'
+    'Vec2:normalize',
+    'Vec2:distance'
   }
 }

+ 31 - 0
api/lovr/math/Vec2/lerp.lua

@@ -0,0 +1,31 @@
+return {
+  summary = 'Moves this vector some amount towards another one.',
+  description = [[
+    Performs a linear interpolation between this vector and another one, which can be used to
+    smoothly animate between two vectors, based on a parameter value.  A parameter value of `0` will
+    leave the vector unchanged, a parameter value of `1` will set the vector to be equal to the
+    input vector, and a value of `.5` will set the components to be halfway between the two vectors.
+  ]],
+  arguments = {
+    {
+      name = 'u',
+      type = 'Vec2',
+      description = 'The vector to lerp towards.'
+    },
+    {
+      name = 't',
+      type = 'number',
+      description = 'The lerping parameter.'
+    }
+  },
+  returns = {
+    {
+      name = 'v',
+      type = 'Vec2',
+      description = 'The original vector, containing the new lerped values.'
+    }
+  },
+  related = {
+    'Quat:slerp'
+  }
+}

+ 35 - 0
api/lovr/math/Vec2/mul.lua

@@ -0,0 +1,35 @@
+return {
+  summary = 'Multiply the vector by a vector or a number.',
+  description = 'Multiplies the vector by a vector or a number.',
+  arguments = {
+    u = {
+      type = 'Vec2',
+      description = 'The other vector to multiply the components by.'
+    },
+    x = {
+      type = 'number',
+      description = 'The number to multiply each component by.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec2',
+      description = 'The original vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec2:add',
+    'Vec2:sub',
+    'Vec2:div'
+  }
+}

+ 17 - 0
api/lovr/math/Vec2/normalize.lua

@@ -0,0 +1,17 @@
+return {
+  summary = 'Normalize the length of the vector to 1.',
+  description = [[
+    Adjusts the values in the vector so that its direction stays the same but its length becomes 1.
+  ]],
+  arguments = {},
+  returns = {
+    {
+      name = 'v',
+      type = 'Vec2',
+      description = 'The original vector.'
+    }
+  },
+  related = {
+    'Vec2:length'
+  }
+}

+ 39 - 0
api/lovr/math/Vec2/set.lua

@@ -0,0 +1,39 @@
+return {
+  summary = 'Set the components of the vector.',
+  description = 'Sets the components of the vector, either from numbers or an existing vector.',
+  arguments = {
+    x = {
+      type = 'number',
+      default = '0',
+      description = 'The new x value of the vector.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'The new y value of the vector.'
+    },
+    u = {
+      type = 'Vec2',
+      description = 'The vector to copy the values from.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec2',
+      description = 'The input vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'x', 'y' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec2:unpack'
+  }
+}

+ 35 - 0
api/lovr/math/Vec2/sub.lua

@@ -0,0 +1,35 @@
+return {
+  summary = 'Subtract a vector or a number from the vector.',
+  description = 'Subtracts a vector or a number from the vector.',
+  arguments = {
+    u = {
+      type = 'Vec2',
+      description = 'The other vector.'
+    },
+    x = {
+      type = 'number',
+      description = 'A number to subtract from each component.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec2',
+      description = 'The original vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec2:add',
+    'Vec2:mul',
+    'Vec2:div'
+  }
+}

+ 20 - 0
api/lovr/math/Vec2/unpack.lua

@@ -0,0 +1,20 @@
+return {
+  summary = 'Get the components of the vector.',
+  description = 'Returns the 2 components of the vector as numbers.',
+  arguments = {},
+  returns = {
+    {
+      name = 'x',
+      type = 'number',
+      description = 'The x value.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      description = 'The y value.'
+    }
+  },
+  related = {
+    'Vec2:set'
+  }
+}

+ 0 - 48
api/lovr/math/mat4/__mul.lua

@@ -1,48 +0,0 @@
-return {
-  summary = 'Multiply a matrix with another matrix or a vector.',
-  description = [[
-    Multiplies this matrix by another value.  Multiplying by a matrix combines their two transforms
-    together.  Multiplying by a vector applies the transformation from the matrix to the vector and
-    returns the vector.
-  ]],
-  arguments = {
-    m = {
-      type = 'mat4',
-      description = 'The matrix.'
-    },
-    n = {
-      type = 'mat4',
-      description = 'Another matrix.'
-    },
-    v = {
-      type = 'vec3',
-      description = 'The vector.'
-    }
-  },
-  returns = {
-    m = {
-      type = 'mat4',
-      description = 'A new matrix containing the multiplied result.'
-    },
-    u = {
-      type = 'vec3',
-      description = 'A new transformed vector.'
-    }
-  },
-  variants = {
-    {
-      arguments = { 'm', 'n' },
-      returns = { 'm' }
-    },
-    {
-      arguments = { 'v' },
-      returns = { 'u' }
-    }
-  },
-  related = {
-    'mat4:mul',
-    'mat4:translate',
-    'mat4:rotate',
-    'mat4:scale'
-  }
-}

+ 0 - 22
api/lovr/math/quat/__len.lua

@@ -1,22 +0,0 @@
-return {
-  summary = 'Get the length of the quaternion.',
-  description = 'Returns the length of the quaternion.',
-  arguments = {
-    {
-      name = 'q',
-      type = 'quat',
-      description = 'The quaternion.'
-    }
-  },
-  returns = {
-    {
-      name = 'length',
-      type = 'number',
-      description = 'The length of the quaternion.'
-    }
-  },
-  related = {
-    'quat:length',
-    'quat:normalize'
-  }
-}

+ 0 - 45
api/lovr/math/quat/__mul.lua

@@ -1,45 +0,0 @@
-return {
-  summary = 'Multiply a quaternion by another quaternion or a vector.',
-  description = [[
-    Multiplies this quaternion by another value.  If the value is a quaternion, the rotations in the
-    two quaternions are applied sequentially and a new quaternion is returned with the result.  If
-    the value is a vector, then a new rotated vector is returned.
-  ]],
-  arguments = {
-    q = {
-      type = 'quat',
-      description = 'A quaternion.'
-    },
-    r = {
-      type = 'quat',
-      description = 'A quaternion to combine with the original.'
-    },
-    v = {
-      type = 'vec3',
-      description = 'A vector to rotate.'
-    }
-  },
-  returns = {
-    s = {
-      type = 'quat',
-      description = 'The combined quaternion.'
-    },
-    u = {
-      type = 'vec3',
-      description = 'The rotated vector.'
-    }
-  },
-  variants = {
-    {
-      arguments = { 'q', 'r' },
-      returns = { 's' },
-    },
-    {
-      arguments = { 'q', 'v' },
-      returns = { 'u' }
-    }
-  },
-  related = {
-    'quat:mul'
-  }
-}

+ 0 - 29
api/lovr/math/vec3/__add.lua

@@ -1,29 +0,0 @@
-return {
-  summary = 'Add two vectors.',
-  description = 'Adds two vectors, returning a new vector containing the sum.',
-  arguments = {
-    {
-      name = 'v',
-      type = 'vec3',
-      description = 'The first vector.'
-    },
-    {
-      name = 'u',
-      type = 'vec3',
-      description = 'The second vector.'
-    }
-  },
-  returns = {
-    {
-      name = 'out',
-      type = 'vec3',
-      description = 'The result.'
-    }
-  },
-  related = {
-    'vec3:add',
-    'vec3:__sub',
-    'vec3:__mul',
-    'vec3:__div'
-  }
-}

+ 0 - 34
api/lovr/math/vec3/__div.lua

@@ -1,34 +0,0 @@
-return {
-  summary = 'Divide vectors by vectors or numbers.',
-  description = [[
-    Divides a vector by another vector or a vector by a number.  Returns a new vector that contains
-    the divided values.
-  ]],
-  arguments = {
-    v = {
-      type = 'vec3',
-      description = 'The first vector.'
-    },
-    u = {
-      type = 'vec3',
-      description = 'The second vector.'
-    },
-    x = {
-      type = 'number',
-      description = 'A number to divide each value in the vector by.'
-    }
-  },
-  returns = {
-    {
-      name = 'out',
-      type = 'vec3',
-      description = 'The result.'
-    }
-  },
-  related = {
-    'vec3:div',
-    'vec3:__add',
-    'vec3:__sub',
-    'vec3:__mul'
-  }
-}

+ 0 - 43
api/lovr/math/vec3/__mul.lua

@@ -1,43 +0,0 @@
-return {
-  summary = 'Multiply vectors by vectors or numbers.',
-  description = [[
-    Multiplies a vector by another vector or a vector by a number.  Returns a new vector that
-    contains the multiplied values.
-  ]],
-  arguments = {
-    v = {
-      type = 'vec3',
-      description = 'The first vector.'
-    },
-    u = {
-      type = 'vec3',
-      description = 'The second vector.'
-    },
-    x = {
-      type = 'number',
-      description = 'A number to scale each value in the vector by.'
-    }
-  },
-  returns = {
-    out = {
-      type = 'vec3',
-      description = 'The result.'
-    }
-  },
-  variants = {
-    {
-      arguments = { 'v', 'u' },
-      returns = { 'out' }
-    },
-    {
-      arguments = { 'v', 'x' },
-      returns = { 'out' }
-    }
-  },
-  related = {
-    'vec3:mul',
-    'vec3:__add',
-    'vec3:__sub',
-    'vec3:__div'
-  }
-}

+ 0 - 31
api/lovr/math/vec3/__sub.lua

@@ -1,31 +0,0 @@
-return {
-  summary = 'Subtract two vectors.',
-  description = [[
-    Subtracts two vectors, returning a new vector containing the difference.
-  ]],
-  arguments = {
-    {
-      name = 'v',
-      type = 'vec3',
-      description = 'The first vector.'
-    },
-    {
-      name = 'u',
-      type = 'vec3',
-      description = 'The second vector.'
-    }
-  },
-  returns = {
-    {
-      name = 'out',
-      type = 'vec3',
-      description = 'The result.'
-    }
-  },
-  related = {
-    'vec3:sub',
-    'vec3:__add',
-    'vec3:__mul',
-    'vec3:__div'
-  }
-}

+ 0 - 18
api/lovr/math/vec3/__unm.lua

@@ -1,18 +0,0 @@
-return {
-  summary = 'Negate a vector.',
-  description = 'Returns a new vector with the negated components of the original.',
-  arguments = {
-    {
-      name = 'v',
-      type = 'vec3',
-      description = 'The first vector.'
-    }
-  },
-  returns = {
-    {
-      name = 'negated',
-      type = 'vec3',
-      description = 'The result.'
-    }
-  }
-}

+ 23 - 17
api/lovr/math/vec3/add.lua

@@ -1,29 +1,35 @@
 return {
-  summary = 'Add a vector to this vector.',
-  description = 'Adds a vector to this vector.',
+  summary = 'Add a vector or a number to the vector.',
+  description = 'Adds a vector or a number to the vector.',
   arguments = {
-    {
-      name = 'u',
-      type = 'vec3',
+    u = {
+      type = 'Vec3',
       description = 'The other vector.'
+    },
+    x = {
+      type = 'number',
+      description = 'A number to add to each component.'
     }
   },
   returns = {
-    {
-      name = 'v',
-      type = 'vec3',
+    v = {
+      type = 'Vec3',
       description = 'The original vector.'
     }
   },
-  notes = [[
-    This function modifies `v` and sets the values to equal the summed values, like this:
-
-        v.x, v.y, v.z = v.x + u.x, v.y + u.y, v.z + u.z
-  ]],
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
   related = {
-    'vec3:__add',
-    'vec3:sub',
-    'vec3:mul',
-    'vec3:div'
+    'Vec3:sub',
+    'Vec3:mul',
+    'Vec3:div'
   }
 }

+ 3 - 3
api/lovr/math/vec3/cross.lua

@@ -7,19 +7,19 @@ return {
   arguments = {
     {
       name = 'u',
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The vector to compute the cross product with.'
     }
   },
   returns = {
     {
       name = 'v',
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The original vector, with the cross product as its values.'
     }
   },
   notes = 'The vectors are not normalized before or after computing the cross product.',
   related = {
-    'vec3:dot'
+    'Vec3:dot'
   }
 }

+ 2 - 5
api/lovr/math/vec3/distance.lua

@@ -4,7 +4,7 @@ return {
   arguments = {
     {
       name = 'u',
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The vector to measure the distance to.'
     }
   },
@@ -16,9 +16,6 @@ return {
     }
   },
   related = {
-    'vec3:__len',
-    'vec3:length',
-    'vec3:dot',
-    'vec3:cross'
+    'Vec3:length'
   }
 }

+ 5 - 16
api/lovr/math/vec3/div.lua

@@ -3,7 +3,7 @@ return {
   description = 'Divides the vector by a vector or a number.',
   arguments = {
     u = {
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The other vector to divide the components by.'
     },
     x = {
@@ -13,7 +13,7 @@ return {
   },
   returns = {
     v = {
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The original vector.'
     }
   },
@@ -27,20 +27,9 @@ return {
       returns = { 'v' }
     }
   },
-  notes = [[
-    This function modifies `v` and sets the values to equal the divided values.  When dividing by a
-    vector, the division is component-wise, like this:
-
-        v.x, v.y, v.z = v.x / u.x, v.y / u.y, v.z / u.z
-
-    Dividing by a number divides each component of the vector by that number:
-
-        v.x, v.y, v.z = v.x / x, v.y / x, v.z / x
-  ]],
   related = {
-    'vec3:__div',
-    'vec3:add',
-    'vec3:sub',
-    'vec3:mul'
+    'Vec3:add',
+    'Vec3:sub',
+    'Vec3:mul'
   }
 }

+ 2 - 5
api/lovr/math/vec3/dot.lua

@@ -4,7 +4,7 @@ return {
   arguments = {
     {
       name = 'u',
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The vector to compute the dot product with.'
     }
   },
@@ -23,9 +23,6 @@ return {
     The vectors are not normalized before computing the dot product.
   ]],
   related = {
-    'vec3:cross',
-    'vec3:__len',
-    'vec3:length',
-    'vec3:distance'
+    'Vec3:cross'
   }
 }

+ 2 - 3
api/lovr/math/vec3/length.lua

@@ -15,8 +15,7 @@ return {
         math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
   ]],
   related = {
-    'vec3:__len',
-    'vec3:normalize',
-    'vec3:distance'
+    'Vec3:normalize',
+    'Vec3:distance'
   }
 }

+ 3 - 3
api/lovr/math/vec3/lerp.lua

@@ -9,7 +9,7 @@ return {
   arguments = {
     {
       name = 'u',
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The vector to lerp towards.'
     },
     {
@@ -21,11 +21,11 @@ return {
   returns = {
     {
       name = 'v',
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The original vector, containing the new lerped values.'
     }
   },
   related = {
-    'quat:slerp'
+    'Quat:slerp'
   }
 }

+ 5 - 16
api/lovr/math/vec3/mul.lua

@@ -3,7 +3,7 @@ return {
   description = 'Multiplies the vector by a vector or a number.',
   arguments = {
     u = {
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The other vector to multiply the components by.'
     },
     x = {
@@ -13,7 +13,7 @@ return {
   },
   returns = {
     v = {
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The original vector.'
     }
   },
@@ -27,20 +27,9 @@ return {
       returns = { 'v' }
     }
   },
-  notes = [[
-    This function modifies `v` and sets the values to equal the multiplied values.  When multiplying
-    by a vector, the multiplication is component-wise, like this:
-
-        v.x, v.y, v.z = v.x * u.x, v.y * u.y, v.z * u.z
-
-    Multiplying by a number scales each component of the vector by that number:
-
-        v.x, v.y, v.z = v.x * x, v.y * x, v.z * x
-  ]],
   related = {
-    'vec3:__mul',
-    'vec3:add',
-    'vec3:sub',
-    'vec3:div'
+    'Vec3:add',
+    'Vec3:sub',
+    'Vec3:div'
   }
 }

+ 2 - 3
api/lovr/math/vec3/normalize.lua

@@ -7,12 +7,11 @@ return {
   returns = {
     {
       name = 'v',
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The original vector.'
     }
   },
   related = {
-    'vec3:__len',
-    'vec3:length'
+    'Vec3:length'
   }
 }

+ 3 - 5
api/lovr/math/vec3/set.lua

@@ -18,13 +18,13 @@ return {
       description = 'The new z value of the vector.'
     },
     u = {
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The vector to copy the values from.'
     }
   },
   returns = {
     v = {
-      type = 'vec3',
+      type = 'Vec3',
       description = 'The input vector.'
     }
   },
@@ -39,8 +39,6 @@ return {
     }
   },
   related = {
-    'vec3:unpack',
-    'lovr.math.vec3',
-    'Pool:vec3'
+    'Vec3:unpack'
   }
 }

+ 23 - 17
api/lovr/math/vec3/sub.lua

@@ -1,29 +1,35 @@
 return {
-  summary = 'Subtract a vector from this vector.',
-  description = 'Subtracts a vector from this vector.',
+  summary = 'Subtract a vector or a number from the vector.',
+  description = 'Subtracts a vector or a number from the vector.',
   arguments = {
-    {
-      name = 'u',
-      type = 'vec3',
+    u = {
+      type = 'Vec3',
       description = 'The other vector.'
+    },
+    x = {
+      type = 'number',
+      description = 'A number to subtract from each component.'
     }
   },
   returns = {
-    {
-      name = 'v',
-      type = 'vec3',
+    v = {
+      type = 'Vec3',
       description = 'The original vector.'
     }
   },
-  notes = [[
-    This function modifies `v` and sets the values to equal the subtracted values, like this:
-
-        v.x, v.y, v.z = v.x - u.x, v.y - u.y, v.z - u.z
-  ]],
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
   related = {
-    'vec3:__sub',
-    'vec3:add',
-    'vec3:mul',
-    'vec3:div'
+    'Vec3:add',
+    'Vec3:mul',
+    'Vec3:div'
   }
 }

+ 2 - 2
api/lovr/math/vec3/unpack.lua

@@ -1,6 +1,6 @@
 return {
   summary = 'Get the components of the vector.',
-  description = 'Returns the 3 components of vector as numbers.',
+  description = 'Returns the 3 components of the vector as numbers.',
   arguments = {},
   returns = {
     {
@@ -20,6 +20,6 @@ return {
     }
   },
   related = {
-    'vec3:set'
+    'Vec3:set'
   }
 }