From c48c2b92851985530b64bf8e4e6f8bf2229d8115 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Mon, 24 Feb 2014 19:44:02 +0100 Subject: [PATCH] update --- README.txt | 2 +- init.lua | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.txt b/README.txt index 6a1dfa5..aadf762 100644 --- a/README.txt +++ b/README.txt @@ -1,2 +1,2 @@ TODO: -— add a function to stop calculating the path +— add a function to stop calculating the path (vector.line) diff --git a/init.lua b/init.lua index d402a31..491222c 100644 --- a/init.lua +++ b/init.lua @@ -151,3 +151,39 @@ function vector.sun_dir(t) end return vector.direction({x=0,y=0,z=0}, p2) end + +function vector.inside(pos, minp, maxp) + for _,i in ipairs({"x", "y", "z"}) do + if pos[i] < minp[i] + or pos[i] > maxp[i] then + return false + end + end + return true +end + +function vector.minmax(p1, p2) + local p1 = vector.new(p1) --Are these 2 redefinitions necessary? + local p2 = vector.new(p2) + for _,i in ipairs({"x", "y", "z"}) do + if p1[i] > p2[i] then + p1[i], p2[i] = p2[i], p1[i] + end + end + return p1, p2 +end + +function vector.move(p1, p2, s) + return vector.round( + vector.add( + vector.multiply( + vector.direction( + p1, + p2 + ), + s + ), + p1 + ) + ) +end