Builtin: Add vector.floor helper function
authorrubenwardy <rubenwardy@gmail.com>
Mon, 17 Oct 2016 19:36:38 +0000 (20:36 +0100)
committerNer'zhul <nerzhul@users.noreply.github.com>
Mon, 17 Oct 2016 20:03:49 +0000 (22:03 +0200)
builtin/common/vector.lua
doc/lua_api.txt

index e9ed3aab3daf3c33391fde12bb1397ded6c7f066..90ba3cc8b6a636693b64daa6757c1b61c7bd1ba5 100644 (file)
@@ -31,6 +31,14 @@ function vector.normalize(v)
        end
 end
 
+function vector.floor(v)
+       return {
+               x = math.floor(v.x),
+               y = math.floor(v.y),
+               z = math.floor(v.z)
+       }
+end
+
 function vector.round(v)
        return {
                x = math.floor(v.x + 0.5),
@@ -130,4 +138,3 @@ function vector.divide(a, b)
                        z = a.z / b}
        end
 end
-
index 8cb3f72bd1bc2b830c3113d182e310ba494df1e4..1e50843542d2f89f6ab9f554bd7be9aff6a10208 100644 (file)
@@ -1812,7 +1812,8 @@ Spatial Vectors
 * `vector.distance(p1, p2)`: returns a number
 * `vector.length(v)`: returns a number
 * `vector.normalize(v)`: returns a vector
-* `vector.round(v)`: returns a vector, each dimension rounded to floor
+* `vector.floor(v)`: returns a vector, each dimension rounded down
+* `vector.round(v)`: returns a vector, each dimension rounded to nearest int
 * `vector.apply(v, func)`: returns a vector
 * `vector.equals(v1, v2)`: returns a boolean