mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 06:04:35 +00:00
commit
63a1cf5438
3
init.lua
3
init.lua
@ -78,6 +78,9 @@ function _batteries:export()
|
||||
--overwrite assert wholesale (it's compatible)
|
||||
assert = self.assert
|
||||
|
||||
--like ipairs, but in reverse
|
||||
ripairs = self.tablex.ripairs
|
||||
|
||||
--export the whole library to global `batteries`
|
||||
batteries = self
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
local path = (...):gsub("intersect", "")
|
||||
local vec2 = require(path .. "vec2")
|
||||
local mathx = require(path .. "mathx")
|
||||
|
||||
--module storage
|
||||
local intersect = {}
|
||||
@ -337,10 +338,10 @@ function intersect.aabb_aabb_collide(a_pos, a_hs, b_pos, b_hs, into)
|
||||
--actually collided
|
||||
if abs_amount.x <= abs_amount.y then
|
||||
--x min
|
||||
res = into:scalar_set(abs_amount.x * math.sign(delta.x), 0)
|
||||
res = into:scalar_set(abs_amount.x * mathx.sign(delta.x), 0)
|
||||
else
|
||||
--y min
|
||||
res = into:scalar_set(0, abs_amount.y * math.sign(delta.y))
|
||||
res = into:scalar_set(0, abs_amount.y * mathx.sign(delta.y))
|
||||
end
|
||||
end
|
||||
return res
|
||||
|
15
tablex.lua
15
tablex.lua
@ -417,4 +417,19 @@ function tablex.unpack8(t)
|
||||
return t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8]
|
||||
end
|
||||
|
||||
--internal: reverse iterator function
|
||||
local function _ripairs_iter(t, i)
|
||||
i = i - 1
|
||||
local v = t[i]
|
||||
if v then
|
||||
return i, v
|
||||
end
|
||||
end
|
||||
|
||||
--iterator that works like ipairs, but in reverse order, with indices from #t to 1
|
||||
--similar to ipairs, it will only consider sequential until the first nil value in the table.
|
||||
function tablex.ripairs(t)
|
||||
return _ripairs_iter, t, #t + 1
|
||||
end
|
||||
|
||||
return tablex
|
||||
|
Loading…
Reference in New Issue
Block a user