Document vector integer division

This commit is contained in:
Matthias Richter 2018-05-27 11:52:33 +02:00
parent 158d12e94d
commit 77bdf42c68
2 changed files with 21 additions and 1 deletions

View File

@ -53,6 +53,7 @@ List of Functions
* :func:`vector.randomDirection(len_min, len_max) <vector.randomDirection>`
* :func:`vector.mul(s, x,y) <vector.mul>`
* :func:`vector.div(s, x,y) <vector.div>`
* :func:`vector.idiv(s, x,y) <vector.idiv>`
* :func:`vector.add(x1,y1, x2,y2) <vector.add>`
* :func:`vector.sub(x1,y1, x2,y2) <vector.sub>`
* :func:`vector.permul(x1,y1, x2,y2) <vector.permul>`
@ -163,9 +164,26 @@ chain operations (see example).
**Example**::
x,y = vec.div(self.zoom, vec.sub(x,y, w/2,h/2))
x,y = vec.div(self.zoom, x-w/2, y-h/2)
.. function:: vector.idiv(s, x,y)
:param number s: A scalar.
:param numbers x,y: A vector.
:returns: ``x//s, y//s``.
Computes integer division ``x//s,y//s`` (only Lua 5.3 and up). The order of
arguments is chosen so that it's possible to chain operations (see example).
**Example**::
i,k = vec.idiv(grid.cellsize, x,y)
i,k = vec.idiv(grid.cellsize, love.mouse.getPosition())
.. function:: vector.add(x1,y1, x2,y2)
:param numbers x1,y1: First vector.

View File

@ -86,7 +86,9 @@ Vector arithmetic
``vector * number = vector``
Scalar multiplication/scaling: \\(s \\cdot (x,y) = (s\\cdot x, s\\cdot y)\\)
``vector / number = vector``
Scalar multiplication/scaling: \\((a,b) / s = (a/s, b/s)\\).
Scalar division: \\((a,b) / s = (a/s, b/s)\\).
``vector // number = vector``
Scalar integer division (only Lua 5.3 and up): \\((a,b) // s = (a//s, b//s)\\).
Common relations are also defined: