From 77bdf42c680a091097294948d7827882c92ad244 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sun, 27 May 2018 11:52:33 +0200 Subject: [PATCH] Document vector integer division --- docs/vector-light.rst | 18 ++++++++++++++++++ docs/vector.rst | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/vector-light.rst b/docs/vector-light.rst index 2d26082..801a092 100644 --- a/docs/vector-light.rst +++ b/docs/vector-light.rst @@ -53,6 +53,7 @@ List of Functions * :func:`vector.randomDirection(len_min, len_max) ` * :func:`vector.mul(s, x,y) ` * :func:`vector.div(s, x,y) ` +* :func:`vector.idiv(s, x,y) ` * :func:`vector.add(x1,y1, x2,y2) ` * :func:`vector.sub(x1,y1, x2,y2) ` * :func:`vector.permul(x1,y1, x2,y2) ` @@ -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. diff --git a/docs/vector.rst b/docs/vector.rst index 16192d0..c1a709c 100644 --- a/docs/vector.rst +++ b/docs/vector.rst @@ -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: