mirror of
https://github.com/TangentFoxy/lume.git
synced 2025-07-28 11:02:20 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
e6d47627cd | ||
|
05828bd840 | ||
|
83a051aadb | ||
|
2699094218 | ||
|
a08436445d |
11
lume.lua
11
lume.lua
@@ -7,11 +7,11 @@
|
||||
-- under the terms of the MIT license. See LICENSE for details.
|
||||
--
|
||||
|
||||
local lume = { _version = "1.1.0" }
|
||||
local lume = { _version = "1.1.1" }
|
||||
|
||||
|
||||
function lume.clamp(x, min, max)
|
||||
return math.max(math.min(x, max), min)
|
||||
return x < min and min or (x > max and max or x)
|
||||
end
|
||||
|
||||
|
||||
@@ -43,7 +43,9 @@ end
|
||||
|
||||
|
||||
function lume.distance(x1, y1, x2, y2, squared)
|
||||
local s = (x1 - x2) ^ 2 + (y1 - y2) ^ 2
|
||||
local dx = x1 - x2
|
||||
local dy = y1 - y2
|
||||
local s = dx * dx + dy * dy
|
||||
return squared and s or math.sqrt(s)
|
||||
end
|
||||
|
||||
@@ -264,12 +266,13 @@ function lume.hotswap(modname)
|
||||
if type(v) == "table" then update(old[k], v) else old[k] = v end
|
||||
end
|
||||
end
|
||||
local oldmod = pcall(require, modname) or nil
|
||||
local err = nil
|
||||
local function onerror(e)
|
||||
for k, v in pairs(_G) do _G[k] = oldglobal[k] end
|
||||
err = lume.trim(e)
|
||||
end
|
||||
local ok, oldmod = pcall(require, modname)
|
||||
oldmod = ok and oldmod or nil
|
||||
xpcall(function()
|
||||
package.loaded[modname] = nil
|
||||
local newmod = require(modname)
|
||||
|
@@ -64,11 +64,11 @@ end
|
||||
|
||||
-- lume.distance
|
||||
tests["lume.distance"] = function()
|
||||
testeq( lume.distance(10, 20, 10, 20), 0 )
|
||||
testeq( lume.distance(10, 20, 20, 20), 10 )
|
||||
local x = lume.distance(1, 2, 5, 7)
|
||||
testeq( lume.distance(1, 2, 5, 7, true), x * x )
|
||||
testeq( lume.distance(10, 10, 10, 20, true), 10 * 10 )
|
||||
testeq( lume.distance(15, 20, 15, 20), 0 )
|
||||
testeq( lume.distance(13, 44, 156, 232), 236.205419074 )
|
||||
testeq( lume.distance(-23, 66, -232, 123), 216.633330769 )
|
||||
local x = lume.distance(13, 15, -2, 81)
|
||||
testeq( lume.distance(13, 15, -2, 81, true), x * x )
|
||||
end
|
||||
|
||||
-- lume.angle
|
||||
@@ -103,7 +103,6 @@ tests["lume.shuffle"] = function()
|
||||
testeq( lume.shuffle({}), {} )
|
||||
end
|
||||
|
||||
|
||||
-- lume.array
|
||||
tests["lume.array"] = function()
|
||||
local t = lume.array(pairs({a=0, b=0, c=0}))
|
||||
|
Reference in New Issue
Block a user