From cc62ddeed821b99e5bef17e4175f403dde76963a Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sun, 9 Feb 2014 12:43:46 +0100 Subject: [PATCH] update --- README.txt | 3 +-- init.lua | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index 6ca8b85..6a1dfa5 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,2 @@ TODO: -— add fine_line -— a function to stop calculating the path +— add a function to stop calculating the path diff --git a/init.lua b/init.lua index 96a53ac..eba6ab1 100644 --- a/init.lua +++ b/init.lua @@ -89,10 +89,34 @@ local function return_line(pos, dir, range) --range ~= length return tab end +local function return_fine_line(pos, dir, range, scale) + local ps1 = return_line(vector.round(vector.multiply(pos, scale)), dir, range*scale) + local ps2 = {vector.round(vector.divide(ps1[1], scale))} + local ps2_num = 2 + for _,p1 in ipairs(ps1) do + local p2 = vector.round(vector.divide(p1, scale)) + if p2 ~= ps2[ps2_num-1] then + ps2[ps2_num] = p2 + ps2_num = ps2_num+1 + end + end + return ps2 +end + +function vector.fine_line(pos, dir, range, scale) + --assert_vector(pos) + if not range then --dir = pos2 + dir = vector.direction(pos, dir) + range = vector.distance(pos, dir) + end + return return_fine_line(pos, dir, range, scale) +end + function vector.line(pos, dir, range) --assert_vector(pos) if not range then --dir = pos2 - return return_line(pos, vector.direction(pos, dir), vector.distance(pos, dir)) + dir = vector.direction(pos, dir) + range = vector.distance(pos, dir) end return return_line(pos, dir, range) end