Corrected volume formula

This commit is contained in:
Davide Saccon 2021-10-25 12:00:19 +08:00
parent df4f55bdcd
commit 07335d0817
2 changed files with 8 additions and 3 deletions

View File

@ -52,7 +52,7 @@ end
-- @param node_name Name of node to make torus of.
-- @param hollow Whether the torus should be hollow.
-- @return The number of nodes added.
function worldedit.torus(pos, radius, tr, node_name, hollow)
function worldedit.torus(pos, radius, tr, node_name)
local radius_out=radius+tr
local radius_in=radius-tr
local manip, area = mh.init_radius(pos, radius_out)

View File

@ -698,7 +698,12 @@ local check_torus = function(param)
if not node then
return false, "invalid node name: " .. nodename
end
return true, tonumber(radius), tonumber(tr), node
local n_radius= tonumber(radius)
local tr = tonumber(tr)
if tr>n_radius then
return false, "Thickness cannot be greater than radius"
end
return true, radius, tr, node
end
@ -737,7 +742,7 @@ worldedit.register_command("torus", {
require_pos = 1,
parse = check_torus,
nodes_needed = function(name, radius, tr, node)
return math.ceil((4 * math.pi * (radius ^ 3)) / 3) --volume of sphere
return math.ceil( 2 * math.pi * math.pi * radius *tr *tr)
end,
func = function(name, radius, tr, node)
local count = worldedit.torus(worldedit.pos1[name], radius, tr, node)