From 63d284b35bd62eb690227df51b7a2d51b9fa366a Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 17 May 2021 10:41:52 -0700 Subject: [PATCH 1/9] axes + safeguards --- worldeditadditions/lib/torus.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/worldeditadditions/lib/torus.lua b/worldeditadditions/lib/torus.lua index 0ba621d..c84aedb 100644 --- a/worldeditadditions/lib/torus.lua +++ b/worldeditadditions/lib/torus.lua @@ -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 --- 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 hollow=false boolean Whether the generated torus should be hollow or not. 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 } local total_radius = major_radius + minor_radius @@ -56,7 +59,7 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n -- Where: -- (x, y, z) is the point -- 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 test_value = comp_a*comp_a - 4*major_radius*minor_radius*(minor_radius_sq-sq.z) From 2b02f9ff2e9c49318604aaf8271a9317e5bacd3d Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 17 May 2021 11:18:09 -0700 Subject: [PATCH 2/9] Fix typos in comments --- worldeditadditions/lib/torus.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/worldeditadditions/lib/torus.lua b/worldeditadditions/lib/torus.lua index c84aedb..5c4b3ac 100644 --- a/worldeditadditions/lib/torus.lua +++ b/worldeditadditions/lib/torus.lua @@ -10,9 +10,8 @@ -- @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) 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 + if type(axes) ~= "string" then axes = "xz" end + if #axes == 1 and axes.match('[xyz]') then axes = matrix[axes] end -- position = { x, y, z } local total_radius = major_radius + minor_radius From 0a4499267669a9c50b3ba1542155d9f8b2a33fdf Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 17 May 2021 17:16:04 -0700 Subject: [PATCH 3/9] reference: add hollow example to torus --- worldeditadditions/lib/torus.lua | 2 +- worldeditadditions_commands/commands/torus.lua | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/worldeditadditions/lib/torus.lua b/worldeditadditions/lib/torus.lua index 5c4b3ac..66d5c99 100644 --- a/worldeditadditions/lib/torus.lua +++ b/worldeditadditions/lib/torus.lua @@ -11,7 +11,7 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_node, axes, hollow) local matrix = {x='yz', y='xz', z='xy'} if type(axes) ~= "string" then axes = "xz" end - if #axes == 1 and axes.match('[xyz]') then axes = matrix[axes] end + if #axes == 1 and axes:match('[xyz]') then axes = matrix[axes] end -- position = { x, y, z } local total_radius = major_radius + minor_radius diff --git a/worldeditadditions_commands/commands/torus.lua b/worldeditadditions_commands/commands/torus.lua index e9bf88c..cbaf93f 100644 --- a/worldeditadditions_commands/commands/torus.lua +++ b/worldeditadditions_commands/commands/torus.lua @@ -35,21 +35,23 @@ local function parse_params_torus(params_text) if axes:find("[^xyz]") then return false, "Error: The axes may only contain the letters x, y, and z." end - if #axes ~= 2 then - return false, "Error: Exactly 2 axes must be specified. For example, 'xy' is valid, but 'xyy' is not (both of course without quotes)." + if #axes > 2 then + return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not." end + local hollow = parts[5] + if hollow == "false" then hollow = false end -- Sort the axis names (this is important to ensure we can identify the direction properly) if axes == "yx" then axes = "xy" end if axes == "zx" then axes = "xz" end if axes == "zy" then axes = "yz" end - return true, replace_node, major_radius, minor_radius, axes + return true, replace_node, major_radius, minor_radius, axes, hollow end worldedit.register_command("torus", { - params = " []", + params = " [] [h[ollow]]", description = "Creates a 3D torus with a major radius of and a minor radius of at pos1, filled with , on axes (i.e. 2 axis names: xz, zy, etc).", privs = { worldedit = true }, require_pos = 1, @@ -60,9 +62,9 @@ worldedit.register_command("torus", { nodes_needed = function(name, target_node, major_radius, minor_radius) return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius) end, - func = function(name, target_node, major_radius, minor_radius, axes) + func = function(name, target_node, major_radius, minor_radius, axes, hollow) local start_time = worldeditadditions.get_ms_time() - local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, false) + local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, hollow) local time_taken = worldeditadditions.get_ms_time() - start_time minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s") From 313ab6e62aab134590bbf09b64c17ee70068521f Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 17 May 2021 17:24:04 -0700 Subject: [PATCH 4/9] torus update --- Chat-Command-Reference.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 5dfe97f..0fba6bd 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -131,8 +131,9 @@ The optional axes sets the axes upon which the torus will lay flat. Possible val ``` //torus 15 5 stone -//torus 5 3 meselamp -//hollowtorus 10 6 sandstone xz +//torus 5 3 meselamp x +//torus 10 6 sandstone xz hollow +//torus 10 6 wool:red y h ``` ## `//hollowtorus ` @@ -303,7 +304,7 @@ If you want to specify different scale factors for difference axes, then `//scal This will scale the defined region by 2x in the positive x, 3x in the positive y, and 4x in the positive z. As these are all scale factors, we can also use the syntax described above to scale up and down in the same operation: ``` -//scale 50% 2 1/4 +//scale 50% 2 1/4 ``` This will first scale in the positive y by 2x. Once that operation is completed, it will scale down to 50% size in the positive x and down to 25% size in the positive z. Note that if you want to scale down first and then scale up, you'll need to execute 2 separate commands. @@ -361,7 +362,7 @@ The above replaces 1 in 3 `dirt` nodes with a mix of `sandstone`, `dry_dirt`, an Since WorldEditAdditions v1.12, you can also use percentages: ``` -//replacemix dirt 33% sandstone 75% dry_dirt 10% cobble 15% +//replacemix dirt 33% sandstone 75% dry_dirt 10% cobble 15% ``` Note though that the percentages are internally converted to a 1-in-N chance and rounded down. @@ -379,7 +380,7 @@ Here are all the above examples together: ## `//convolve [[,]] []` Advanced version of `//smooth` from we_env, and one of the few WorldEditAdditions commands to have any aliases (`//smoothadv` and `//conv`). -Extracts a heightmap from the defined region and then proceeds to [convolve](https://en.wikipedia.org/wiki/Kernel_(image_processing)) over it with the specified kernel. The kernel can be thought of as the filter that will be applied to the heightmap. Once done, the newly convolved heightmap is applied to the terrain. +Extracts a heightmap from the defined region and then proceeds to [convolve](https://en.wikipedia.org/wiki/Kernel_(image_processing)) over it with the specified kernel. The kernel can be thought of as the filter that will be applied to the heightmap. Once done, the newly convolved heightmap is applied to the terrain. Possible kernels: @@ -451,7 +452,7 @@ Counts all the nodes in the defined region and returns the result along with cal ``` ## `//subdivide ` -Splits the current WorldEdit region into `(, , )` sized chunks, and run `// ` over each chunk. +Splits the current WorldEdit region into `(, , )` sized chunks, and run `// ` over each chunk. Sometimes, we want to run a single command on a truly vast area. Usually, this results in running out of memory. If this was you, then this command is just what you need! It should be able to handle any sized region - the only limit is your patience for command to complete..... From d0fdc62d3d5c0027e03398c6dae53b5faf0677d5 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 17 May 2021 17:26:24 -0700 Subject: [PATCH 5/9] Reference: Add hollow keyword --- Chat-Command-Reference.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 0fba6bd..3d3e862 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -124,7 +124,7 @@ Creates a hollow ellipsoid at position 1 with the radius `(rx, ry, rz)`. Works t //hollowellipsoid 21 11 41 stone ``` -## `//torus []` +## `//torus [ [h[ollow]]]` Creates a solid torus at position 1 with the specified major and minor radii. The major radius is the distance from the centre of the torus to the centre of the circle bit, and the minor radius is the radius of the circle bit. The optional axes sets the axes upon which the torus will lay flat. Possible values: `xy` (the default), `xz`, `yz`. @@ -136,7 +136,7 @@ The optional axes sets the axes upon which the torus will lay flat. Possible val //torus 10 6 wool:red y h ``` -## `//hollowtorus ` +## `//hollowtorus []` Creates a hollow torus at position 1 with the radius major and minor radii. Works the same way as `//torus` does. ``` From 45d5f74d0a0c5e22d313b4182c2efd9bb6e1959a Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 17 May 2021 17:38:42 -0700 Subject: [PATCH 6/9] Changelog: add note about hollow keyword --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09b4d8d..ff85ef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ Note to self: See the bottom of this file for the release template text. - Add new universal chance parsing - Any `` can now either be a 1-in-N number (e.g. `4`, `10`), or a percentage chance (e.g. `50%`, `10%`). - Caveat: Percentages are converted to a 1-in-N chance, but additionally that number is rounded down in some places - - `//torus`, `//hollowtorus`: Add optional new axes argument + - `//torus`, `//hollowtorus`: Add optional new axes and hollow (for `//torus`) argument ## v1.11: The big data update (25th January 2021) From 639c2061efa28d288c333262d646bb903f9cc091 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 17 May 2021 09:13:43 -0700 Subject: [PATCH 7/9] Bugfix/torus: fix hollow implementation; improve clarity --- worldeditadditions/lib/torus.lua | 8 +++--- .../commands/torus.lua | 26 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/worldeditadditions/lib/torus.lua b/worldeditadditions/lib/torus.lua index 66d5c99..fcf57d7 100644 --- a/worldeditadditions/lib/torus.lua +++ b/worldeditadditions/lib/torus.lua @@ -1,5 +1,5 @@ ---- Overlap command. Places a specified node on top of --- @module worldeditadditions.overlay +--- Generates torus shapes. +-- @module worldeditadditions.torus --- Generates a torus shape at the given position with the given parameters. -- @param position Vector The position at which to generate the torus. @@ -57,8 +57,8 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n -- (x^2+y^2+z^2-(a^2+b^2))^2-4 a b (b^2-z^2) -- Where: -- (x, y, z) is the point - -- a is the major radius (centre to centre of circle) - -- b is the minor radius (radius of circle) + -- a is the major radius (centre of the ring to the centre of the torus) + -- b is the minor radius (radius of the ring) 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) diff --git a/worldeditadditions_commands/commands/torus.lua b/worldeditadditions_commands/commands/torus.lua index cbaf93f..1593b2d 100644 --- a/worldeditadditions_commands/commands/torus.lua +++ b/worldeditadditions_commands/commands/torus.lua @@ -39,8 +39,10 @@ local function parse_params_torus(params_text) return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not." end - local hollow = parts[5] - if hollow == "false" then hollow = false end + local hollow = false + if parts[5] == "hollow" or parts[5] == "h" then + hollow = true + end -- Sort the axis names (this is important to ensure we can identify the direction properly) if axes == "yx" then axes = "xy" end @@ -51,7 +53,7 @@ local function parse_params_torus(params_text) end worldedit.register_command("torus", { - params = " [] [h[ollow]]", + params = " [ [h[ollow]]]", description = "Creates a 3D torus with a major radius of and a minor radius of at pos1, filled with , on axes (i.e. 2 axis names: xz, zy, etc).", privs = { worldedit = true }, require_pos = 1, @@ -64,7 +66,13 @@ worldedit.register_command("torus", { end, func = function(name, target_node, major_radius, minor_radius, axes, hollow) local start_time = worldeditadditions.get_ms_time() - local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, hollow) + local replaced = worldeditadditions.torus( + worldedit.pos1[name], + major_radius, minor_radius, + target_node, + axes, + hollow + ) local time_taken = worldeditadditions.get_ms_time() - start_time minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s") @@ -85,9 +93,15 @@ worldedit.register_command("hollowtorus", { nodes_needed = function(name, target_node, major_radius, minor_radius, axes) return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius) end, - func = function(name, target_node, major_radius, minor_radius) + func = function(name, target_node, major_radius, minor_radius, axes) local start_time = worldeditadditions.get_ms_time() - local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, true) + local replaced = worldeditadditions.torus( + worldedit.pos1[name], + major_radius, minor_radius, + target_node, + axes, + true -- hollow + ) local time_taken = worldeditadditions.get_ms_time() - start_time minetest.log("action", name .. " used //hollowtorus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s") From 5d2df22c0aebf866643b745c648664bd9cd36a31 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 18 May 2021 14:46:27 +0100 Subject: [PATCH 8/9] CHANGELOG: Small tweaks --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff85ef2..3c5891d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ Note to self: See the bottom of this file for the release template text. - Add new universal chance parsing - Any `` can now either be a 1-in-N number (e.g. `4`, `10`), or a percentage chance (e.g. `50%`, `10%`). - Caveat: Percentages are converted to a 1-in-N chance, but additionally that number is rounded down in some places - - `//torus`, `//hollowtorus`: Add optional new axes and hollow (for `//torus`) argument + - `//torus`, `//hollowtorus`: Add optional new axes + - `//torus`: Add optional hollow keyword ## v1.11: The big data update (25th January 2021) From 6d6252b2c3829fbef804b214990e3d1ed492f887 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 18 May 2021 14:48:48 +0100 Subject: [PATCH 9/9] Chat comment reference: elaborate on new //torus changes --- Chat-Command-Reference.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 3d3e862..ca17307 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -127,13 +127,14 @@ Creates a hollow ellipsoid at position 1 with the radius `(rx, ry, rz)`. Works t ## `//torus [ [h[ollow]]]` Creates a solid torus at position 1 with the specified major and minor radii. The major radius is the distance from the centre of the torus to the centre of the circle bit, and the minor radius is the radius of the circle bit. -The optional axes sets the axes upon which the torus will lay flat. Possible values: `xy` (the default), `xz`, `yz`. +The optional axes sets the axes upon which the torus will lay flat. Possible values: `xy` (the default), `xz`, `yz`. A single axis may also be specified (i.e. `x`, `y`, or `z`) - this will be interpreted as the axis that runs through the hole in the middle of the torus. ``` //torus 15 5 stone -//torus 5 3 meselamp x -//torus 10 6 sandstone xz hollow -//torus 10 6 wool:red y h +//torus 5 3 meselamp +//torus 10 6 sandstone xz +//torus 10 6 wool:red y +//torus 25 10 dirt xz hollow ``` ## `//hollowtorus []`