mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-30 11:04:00 +01:00
Perlin: remove debug functions
This commit is contained in:
parent
b2eb76d280
commit
49bf0f19bc
@ -50,18 +50,6 @@ function Perlin:load()
|
||||
end
|
||||
end
|
||||
|
||||
--- Formats a key-value table of values as a string.
|
||||
-- @param map table The table of key-value pairs to format.
|
||||
-- @returns string The given table of key-value pairs formatted as a string.
|
||||
local function format_map(map)
|
||||
local result = {}
|
||||
for key, value in pairs(map) do
|
||||
table.insert(result, key.."\t"..tostring(value))
|
||||
end
|
||||
return table.concat(result, "\n")
|
||||
end
|
||||
|
||||
|
||||
--- Returns a noise value for a given point in 3D space.
|
||||
-- @param x number The x co-ordinate.
|
||||
-- @param y number The y co-ordinate.
|
||||
|
@ -1,70 +0,0 @@
|
||||
local Perlin = require("perlin")
|
||||
|
||||
--- Pads str to length len with char from left
|
||||
-- Adapted from the above
|
||||
local function str_padstart(str, len, char)
|
||||
if char == nil then char = ' ' end
|
||||
return string.rep(char, len - #str) .. str
|
||||
end
|
||||
local function array_2d(tbl, width)
|
||||
print("==== count: "..(#tbl+1)..", width:"..width.." ====")
|
||||
local display_width = 1
|
||||
for _i,value in pairs(tbl) do
|
||||
display_width = math.max(display_width, #tostring(value))
|
||||
end
|
||||
display_width = display_width + 2
|
||||
local next = {}
|
||||
for i=0, #tbl do
|
||||
table.insert(next, str_padstart(tostring(tbl[i]), display_width))
|
||||
if #next == width then
|
||||
print(table.concat(next, ""))
|
||||
next = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Finds the minimum value in the given list.
|
||||
-- @param list number[] The list (table) of numbers to find the minimum value of.
|
||||
-- @returns number The minimum value in the given list.
|
||||
function min(list)
|
||||
if #list == 0 then return nil end
|
||||
local min = nil
|
||||
for i,value in ipairs(list) do
|
||||
if min == nil or min > value then
|
||||
min = value
|
||||
end
|
||||
end
|
||||
return min
|
||||
end
|
||||
|
||||
--- Finds the maximum value in the given list.
|
||||
-- @param list number[] The list (table) of numbers to find the maximum value of.
|
||||
-- @returns number The maximum value in the given list.
|
||||
function max(list)
|
||||
if #list == 0 then return nil end
|
||||
local max = nil
|
||||
for i,value in ipairs(list) do
|
||||
if max == nil or max < value then
|
||||
max = value
|
||||
end
|
||||
end
|
||||
return max
|
||||
end
|
||||
|
||||
|
||||
local p = Perlin.new()
|
||||
|
||||
local result = {}
|
||||
local size = { x = 10, z = 25 }
|
||||
|
||||
for x = 0, size.x do
|
||||
for y = 0, size.z do
|
||||
result[y*size.x + x] = p:noise(x, y, 0)
|
||||
end
|
||||
end
|
||||
|
||||
print(array_2d(result, size.x))
|
||||
|
||||
print("MAX ", max(result))
|
||||
print("MIN ", min(result))
|
Loading…
Reference in New Issue
Block a user