diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ccacd7..09b4d8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +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 ## v1.11: The big data update (25th January 2021) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 7f0d3aa..5dfe97f 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -124,12 +124,15 @@ Creates a hollow ellipsoid at position 1 with the radius `(rx, ry, rz)`. Works t //hollowellipsoid 21 11 41 stone ``` -## `//torus ` +## `//torus []` 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`. + ``` //torus 15 5 stone //torus 5 3 meselamp +//hollowtorus 10 6 sandstone xz ``` ## `//hollowtorus ` @@ -138,6 +141,7 @@ Creates a hollow torus at position 1 with the radius major and minor radii. Work ``` //hollowtorus 10 5 glass //hollowtorus 21 11 stone +//hollowtorus 18 6 dirt xz ``` ## `//line [ []]` diff --git a/worldeditadditions/lib/torus.lua b/worldeditadditions/lib/torus.lua index 22e23f4..74f38d4 100644 --- a/worldeditadditions/lib/torus.lua +++ b/worldeditadditions/lib/torus.lua @@ -42,8 +42,13 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n for x = -total_radius, total_radius do local x_sq = x*x + local sq = vector.new(x_sq, y_sq, z_sq) + + -- Default: xy if axes == "xz" then - -- TODO: Figure out which 2 axes we need to fiddle here + sq.x, sq.y, sq.z = sq.x, sq.z, sq.y + elseif axes == "yz" then + sq.x, sq.y, sq.z = sq.y, sq.z, sq.x end -- (x^2+y^2+z^2-(a^2+b^2))^2-4 a b (b^2-z^2) @@ -51,8 +56,8 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n -- (x, y, z) is the point -- a is the major radius (centre to centre of circle) -- b is the minor radius (radius of circle - local comp_a = (x_sq+y_sq+z_sq - (major_radius_sq+minor_radius_sq)) - local test_value = comp_a*comp_a - 4*major_radius*minor_radius*(minor_radius_sq-z_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) -- If we're inside the torus, then fill it in if test_value <= 1 then @@ -60,8 +65,8 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n if not place_ok then -- It must be hollow! Do some additional calculations. - local inner_comp_a = (x_sq+y_sq+z_sq - (major_radius_sq+inner_minor_radius_sq)) - local inner_test_value = inner_comp_a*inner_comp_a - 4*major_radius*inner_minor_radius*(inner_minor_radius_sq-z_sq) + local inner_comp_a = (sq.x+sq.y+sq.z - (major_radius_sq+inner_minor_radius_sq)) + local inner_test_value = inner_comp_a*inner_comp_a - 4*major_radius*inner_minor_radius*(inner_minor_radius_sq-sq.z) -- It's only ok to place it if it's outside our inner torus place_ok = inner_test_value >= 0