From ae8ff4b8e2da35265ebbbe7afe99ed29e61efa7d Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sun, 7 Jul 2013 01:44:33 -0400 Subject: Add vector helpers --- doc/lua_api.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'doc/lua_api.txt') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index a9f2d0d46..5a2fdf102 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -988,12 +988,41 @@ Inventory location: - "nodemeta:,,": Any node metadata - "detached:": A detached inventory +Vector helpers +--------------- +vector.new([x[, y, z]]) -> vector + ^ x is a table or the x position. +vector.direction(p1, p2) -> vector +vector.distance(p1, p2) -> number +vector.length(v) -> number +vector.normalize(v) -> vector +vector.round(v) -> vector +vector.equal(v1, v2) -> bool +vector.add(v, x) -> vector + ^ x can be annother vector or a number +vector.subtract(v, x) -> vector +vector.multiply(v, x) -> vector +vector.divide(v, x) -> vector + +You can also use Lua operators on vectors. +For example: + v1 = vector.new() + v1 = v1 + 5 + v2 = vector.new(v1) + v1 = v1 * v2 + if v1 == v2 then + error("Math broke") + end + Helper functions ----------------- dump2(obj, name="_", dumped={}) ^ Return object serialized as a string, handles reference loops dump(obj, dumped={}) ^ Return object serialized as a string +math.hypot(x, y) +^ Get the hypotenuse of a triangle with legs x and y. + Usefull for distance calculation. string:split(separator) ^ eg. string:split("a,b", ",") == {"a","b"} string:trim() -- cgit v1.2.3