From df4f55bdcdf0736dddc5a6c6259a432998b5985d Mon Sep 17 00:00:00 2001 From: Davide Saccon Date: Sat, 23 Oct 2021 16:38:14 +0800 Subject: [PATCH] Torus working --- worldedit/primitives.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/worldedit/primitives.lua b/worldedit/primitives.lua index 75ab88d..e056c73 100644 --- a/worldedit/primitives.lua +++ b/worldedit/primitives.lua @@ -71,11 +71,23 @@ function worldedit.torus(pos, radius, tr, node_name, hollow) for y = -tr, tr do local new_y = new_z + (y + offset_y) * stride_y for x = -radius_out, radius_out do - local check_1= x * x + z * z - if check_1 <= max_hor_radius and check_1 >= min_hor_radius then - local i = new_y + (x + offset_x) - data[i] = node_id - count = count + 1 + local dxz2= x * x + z * z + if dxz2 <= max_hor_radius and dxz2 >= min_hor_radius then + local dxz=math.sqrt(dxz2) + local rx=x/dxz + local rz=z/dxz + local xc=radius*rx + local zc=radius*rz + local yc=0 + local dx=xc-x + local dy=yc-y + local dz=zc-z + local dist_from_tube_center = math.sqrt(dx*dx+dy*dy+dz*dz) + if( dist_from_tube_center <= tr ) then + local i = new_y + (x + offset_x) + data[i] = node_id + count = count + 1 + end end end end