1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/maps/pirates/math.lua

103 lines
19 KiB
Lua
Raw Normal View History

-- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/danielmartin0/ComfyFactorio-Pirates.
2021-10-13 10:21:53 +02:00
local Public = {}
Public.random = math.random
Public.randomseed = math.randomseed
Public.sqrt = math.sqrt
Public.min = math.min
Public.max = math.max
Public.rad = math.rad
Public.floor = math.floor
Public.abs = math.abs
Public.ceil = math.ceil
Public.log = math.log
Public.atan = math.atan
Public.sin = math.sin
Public.cos = math.cos
Public.pi = math.pi
Public.deg = math.deg
Public.round = math.round
--- SCALING CURVES ---
function Public.sloped(x, slope)
return 1 + ((x - 1) * slope)
end
-- SLOPE GUIDE
-- slope 1 -> {0.25, 0.50, 0.75, 1.00, 1.50, 3.00, 5.00}
-- slope 4/5 -> {0.40, 0.60, 0.80, 1.00, 1.40, 2.60, 4.20}
-- slope 3/5 -> {0.55, 0.70, 0.85, 1.00, 1.30, 2.20, 3.40}
-- slope 2/5 -> {0.70, 0.80, 0.90, 1.00, 1.20, 1.80, 2.40}
-- EXPONENT GUIDE
-- exponent 1 -> {0.25, 0.50, 0.75, 1.00, 1.50, 3.00, 5.00}
-- exponent 1.5 -> {0.13, 0.35, 0.65, 1.00, 1.84, 5.20, 11.18}
-- exponent 2 -> {0.06, 0.25, 0.56, 1.00, 2.25, 9.00, 25.00}
-- exponent -1.2 -> {5.28, 2.30, 1.41, 1.00, 0.61, 0.27, 0.14}
function Public.clamp(min, max, number)
return Public.min(max, Public.max(min, number))
end
2021-10-13 10:21:53 +02:00
function Public.sgn(number)
return number > 0 and 1 or (number == 0 and 0 or -1)
end
function Public.length(vec)
return Public.sqrt(vec.x * vec.x + vec.y * vec.y)
end
function Public.slopefromto(x, from, to)
return Public.clamp(0, 1,
(x - from) / (to - from)
)
2021-10-13 10:21:53 +02:00
end
function Public.distance(vec1, vec2)
local vecx = vec2.x - vec1.x
local vecy = vec2.y - vec1.y
return Public.sqrt(vecx * vecx + vecy * vecy)
end
function Public.vector_sum(vec1, vec2)
return {x = vec1.x + vec2.x, y = vec1.y + vec2.y}
end
function Public.snap_to_grid(point)
return {x = Public.ceil(point.x), y = Public.ceil(point.x)}
end
2021-10-13 10:21:53 +02:00
function Public.shuffle(tbl)
local size = #tbl
for i = size, 2, -1 do
local rand = Public.random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
local function is_closer(pos1, pos2, pos)
return ((pos1.x - pos.x) ^ 2 + (pos1.y - pos.y) ^ 2) < ((pos2.x - pos.x) ^ 2 + (pos2.y - pos.y) ^ 2)
end
function Public.shuffle_distancebiased(tbl, position)
local size = #tbl
for i = size, 1, -1 do
local rand = Public.random(i)
if is_closer(tbl[i].position, tbl[rand].position, position) and i > rand then
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
end
return tbl
end
2022-02-27 18:42:25 +02:00
Public.points_in_m20t20_squared_sorted_by_distance_to_origin = {{0, 0}, {1, 0}, {0, 1}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}, {2, 0}, {0, 2}, {0, -2}, {-2, 0}, {2, 1}, {2, -1}, {1, 2}, {1, -2}, {-1, 2}, {-1, -2}, {-2, 1}, {-2, -1}, {2, 2}, {2, -2}, {-2, 2}, {-2, -2}, {3, 0}, {0, 3}, {0, -3}, {-3, 0}, {3, 1}, {3, -1}, {1, 3}, {1, -3}, {-1, 3}, {-1, -3}, {-3, 1}, {-3, -1}, {3, 2}, {3, -2}, {2, 3}, {2, -3}, {-2, 3}, {-2, -3}, {-3, 2}, {-3, -2}, {4, 0}, {0, 4}, {0, -4}, {-4, 0}, {4, 1}, {4, -1}, {1, 4}, {1, -4}, {-1, 4}, {-1, -4}, {-4, 1}, {-4, -1}, {3, 3}, {3, -3}, {-3, 3}, {-3, -3}, {4, 2}, {4, -2}, {2, 4}, {2, -4}, {-2, 4}, {-2, -4}, {-4, 2}, {-4, -2}, {5, 0}, {4, 3}, {4, -3}, {3, 4}, {3, -4}, {0, 5}, {0, -5}, {-3, 4}, {-3, -4}, {-4, 3}, {-4, -3}, {-5, 0}, {5, 1}, {5, -1}, {1, 5}, {1, -5}, {-1, 5}, {-1, -5}, {-5, 1}, {-5, -1}, {5, 2}, {5, -2}, {2, 5}, {2, -5}, {-2, 5}, {-2, -5}, {-5, 2}, {-5, -2}, {4, 4}, {4, -4}, {-4, 4}, {-4, -4}, {5, 3}, {5, -3}, {3, 5}, {3, -5}, {-3, 5}, {-3, -5}, {-5, 3}, {-5, -3}, {6, 0}, {0, 6}, {0, -6}, {-6, 0}, {6, 1}, {6, -1}, {1, 6}, {1, -6}, {-1, 6}, {-1, -6}, {-6, 1}, {-6, -1}, {6, 2}, {6, -2}, {2, 6}, {2, -6}, {-2, 6}, {-2, -6}, {-6, 2}, {-6, -2}, {5, 4}, {5, -4}, {4, 5}, {4, -5}, {-4, 5}, {-4, -5}, {-5, 4}, {-5, -4}, {6, 3}, {6, -3}, {3, 6}, {3, -6}, {-3, 6}, {-3, -6}, {-6, 3}, {-6, -3}, {7, 0}, {0, 7}, {0, -7}, {-7, 0}, {7, 1}, {7, -1}, {5, 5}, {5, -5}, {1, 7}, {1, -7}, {-1, 7}, {-1, -7}, {-5, 5}, {-5, -5}, {-7, 1}, {-7, -1}, {6, 4}, {6, -4}, {4, 6}, {4, -6}, {-4, 6}, {-4, -6}, {-6, 4}, {-6, -4}, {7, 2}, {7, -2}, {2, 7}, {2, -7}, {-2, 7}, {-2, -7}, {-7, 2}, {-7, -2}, {7, 3}, {7, -3}, {3, 7}, {3, -7}, {-3, 7}, {-3, -7}, {-7, 3}, {-7, -3}, {6, 5}, {6, -5}, {5, 6}, {5, -6}, {-5, 6}, {-5, -6}, {-6, 5}, {-6, -5}, {8, 0}, {0, 8}, {0, -8}, {-8, 0}, {8, 1}, {8, -1}, {7, 4}, {7, -4}, {4, 7}, {4, -7}, {1, 8}, {1, -8}, {-1, 8}, {-1, -8}, {-4, 7}, {-4, -7}, {-7, 4}, {-7, -4}, {-8, 1}, {-8, -1}, {8, 2}, {8, -2}, {2, 8}, {2, -8}, {-2, 8}, {-2, -8}, {-8, 2}, {-8, -2}, {6, 6}, {6, -6}, {-6, 6}, {-6, -6}, {8, 3}, {8, -3}, {3, 8}, {3, -8}, {-3, 8}, {-3, -8}, {-8, 3}, {-8, -3}, {7, 5}, {7, -5}, {5, 7}, {5, -7}, {-5, 7}, {-5, -7}, {-7, 5}, {-7, -5}, {8, 4}, {8, -4}, {4, 8}, {4, -8}, {-4, 8}, {-4, -8}, {-8, 4}, {-8, -4}, {9, 0}, {0, 9}, {0, -9}, {-9, 0}, {9, 1}, {9, -1}, {1, 9}, {1, -9}, {-1, 9}, {-1, -9}, {-9, 1}, {-9, -1}, {9, 2}, {9, -2}, {7, 6}, {7, -6}, {6, 7}, {6, -7}, {2, 9}, {2, -9}, {-2, 9}, {-2, -9}, {-6, 7}, {-6, -7}, {-7, 6}, {-7, -6}, {-9, 2}, {-9, -2}, {8, 5}, {8, -5}, {5, 8}, {5, -8}, {-5, 8}, {-5, -8}, {-8, 5}, {-8, -5}, {9, 3}, {9, -3}, {3, 9}, {3, -9}, {-3, 9}, {-3, -9}, {-9, 3}, {-9, -3}, {9, 4}, {9, -4}, {4, 9}, {4, -9}, {-4, 9}, {-4, -9}, {-9, 4}, {-9, -4}, {7, 7}, {7, -7}, {-7, 7}, {-7, -7}, {10, 0}, {8, 6}, {8, -6}, {6, 8}, {6, -8}, {0, 10}, {0, -10}, {-6, 8}, {-6, -8}, {-8, 6}, {-8, -6}, {-10, 0}, {10, 1}, {10, -1}, {1, 10}, {1, -10}, {-1, 10}, {-1, -10}, {-10, 1}, {-10, -1}, {10, 2}, {10, -2}, {2, 10}, {2, -10}, {-2, 10}, {-2, -10}, {-10, 2}, {-10, -2}, {9, 5}, {9, -5}, {5, 9}, {5, -9}, {-5, 9}, {-5, -9}, {-9, 5}, {-9, -5}, {10, 3}, {10, -3}, {3, 10}, {3, -10}, {-3, 10}, {-3, -10}, {-10, 3}, {-10, -3}, {8, 7}, {8, -7}, {7, 8}, {7, -8}, {-7, 8}, {-7, -8}, {-8, 7}, {-8, -7}, {10, 4}, {10, -4}, {4, 10}, {4, -10}, {-4, 10}, {-4, -10}, {-10, 4}, {-10, -4}, {9, 6}, {9, -6}, {6, 9}, {6, -9}, {-6, 9}, {-6, -9}, {-9, 6}, {-9, -6}, {11, 0}, {0, 11}, {0, -11}, {-11, 0}, {11, 1}, {11, -1}, {1, 11}, {1, -11}, {-1, 11}, {-1, -11}, {-11, 1}, {-11, -1}, {11, 2}, {11, -2}, {10, 5}, {10, -5}, {5, 10}, {5, -10}, {2, 11}, {2, -11}, {-2, 11}, {-2, -11}, {-5, 10}, {-5, -10}, {-10, 5}, {-10, -5}, {-11, 2}, {-11, -2}, {8, 8}, {8, -8}, {-8, 8}, {-8, -8}, {11, 3}, {11, -3}, {9, 7}, {9, -7}, {7, 9}, {7, -9}, {3, 11}, {3, -11}, {-3, 11}, {-3, -11}, {-7, 9}, {-7, -9}, {-9, 7}, {-9, -7}, {-11, 3}, {-11, -3}, {10, 6}, {10, -6}, {6, 10}, {6, -10}, {-6, 10}, {-6, -10}, {-10, 6}, {-10, -6}, {11, 4}, {11, -4}, {4, 11}, {4, -11}, {-4, 11}, {-4, -11}, {-11, 4}, {-11, -4}, {12, 0}, {0, 12}, {0, -12}, {-12,
2021-10-13 10:21:53 +02:00
return Public