mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-23 03:55:01 +00:00
axes + safeguards
This commit is contained in:
parent
57ff577694
commit
63d284b35b
1 changed files with 6 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
--- Overlap command. Places a specified node on top of
|
--- Overlap command. Places a specified node on top of
|
||||||
-- @module worldeditadditions.overlay
|
-- @module worldeditadditions.overlay
|
||||||
|
|
||||||
--- Generates a torus shape at the given position with the given parameters.
|
--- Generates a torus shape at the given position with the given parameters.
|
||||||
|
@ -9,7 +9,10 @@
|
||||||
-- @param axes=xz string|nil The axes upon which the torus should lay flat.
|
-- @param axes=xz string|nil The axes upon which the torus should lay flat.
|
||||||
-- @param hollow=false boolean Whether the generated torus should be hollow or not.
|
-- @param hollow=false boolean Whether the generated torus should be hollow or not.
|
||||||
function worldeditadditions.torus(position, major_radius, minor_radius, target_node, axes, hollow)
|
function worldeditadditions.torus(position, major_radius, minor_radius, target_node, axes, hollow)
|
||||||
if type(axes) ~= "string" then axes = "xz" end
|
local matrix = {x='yz', y='xz', z='xy'}
|
||||||
|
if type(axes) ~= "string" then axes = "xz"
|
||||||
|
elseif #axes == 1 and axes.match('[xyz]') then axes = matrix[axes]
|
||||||
|
else axes = ((axes:match('x') or '')..(axes:match('y') or '')..(axes:match('z') or '')):sub(1,2) end
|
||||||
|
|
||||||
-- position = { x, y, z }
|
-- position = { x, y, z }
|
||||||
local total_radius = major_radius + minor_radius
|
local total_radius = major_radius + minor_radius
|
||||||
|
@ -56,7 +59,7 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n
|
||||||
-- Where:
|
-- Where:
|
||||||
-- (x, y, z) is the point
|
-- (x, y, z) is the point
|
||||||
-- a is the major radius (centre to centre of circle)
|
-- a is the major radius (centre to centre of circle)
|
||||||
-- b is the minor radius (radius of circle
|
-- b is the minor radius (radius of circle)
|
||||||
local comp_a = (sq.x+sq.y+sq.z - (major_radius_sq+minor_radius_sq))
|
local comp_a = (sq.x+sq.y+sq.z - (major_radius_sq+minor_radius_sq))
|
||||||
local test_value = comp_a*comp_a - 4*major_radius*minor_radius*(minor_radius_sq-sq.z)
|
local test_value = comp_a*comp_a - 4*major_radius*minor_radius*(minor_radius_sq-sq.z)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue