This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Given a knot sequence p[1<=i<=n], solve for a sequence of cubic | |
-- splines s[1<=i<=n-1] such that the square of acceleration is minimized. | |
local gamma = { | |
0.50000000000000000, 0.28571428571428571, 0.26923076923076923, 0.26804123711340206, | |
0.26795580110497238, 0.26794966691339748, 0.26794922649742166, 0.26794919487697295, | |
0.26794919260672685, 0.26794919244373052, 0.26794919243202791, 0.26794919243118770, | |
0.26794919243112737, 0.26794919243112304, 0.26794919243112273, 0.26794919243112271, | |
} | |
local gammaLimit = gamma[#gamma] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
local fooInterlock = Interlock.new() | |
function foo() | |
local lock = fooInterlock:takeLock() | |
coroutine.yield() | |
if not lock:hasLock() then | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Perform a breadth first traversal of an instance's descendant tree. | |
-- | |
-- > for obj in scanBF(root) do | |
-- > print(obj) | |
-- > end | |
local function scanBF(root) | |
local queue = {} -- Queue containing stacks of children | |
local qIdx0 = 1 -- Queue front index | |
local qIdx1 = 0 -- Queue back index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Connection = {} do | |
Connection.__index = Connection | |
function Connection.new(hook, signal) | |
return setmetatable({ | |
_hook = hook, | |
_signal = signal, | |
_connected = true, | |
}, Connection) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local RunService = game:GetService("RunService") | |
-- compile an oriented bounding box into a scaled CFrame | |
local function compileBBox(cframe: CFrame, size: Vector3) | |
return CFrame.fromMatrix( | |
cframe.Position, | |
cframe.XVector/size.X, | |
cframe.YVector/size.Y, | |
cframe.ZVector/size.Z | |
):Inverse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function bbox(part) | |
local size = part.Size | |
local inv = part.CFrame:inverse() | |
local wx = size*inv.XVector | |
local wy = size*inv.YVector | |
local wz = size*inv.ZVector | |
return Vector3.new( | |
math.abs(wx.x) + math.abs(wx.y) + math.abs(wx.z), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local pi = math.pi | |
local abs = math.abs | |
local atan2 = math.atan2 | |
local cos = math.cos | |
local sqrt = math.sqrt | |
local sign = math.sign | |
local EPS = 1e-9 | |
local function cbrt(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function waitForFirst(...) | |
local shunt = Instance.new("BindableEvent") | |
local slots = {...} | |
local function fire(...) | |
for i = 1, #slots do | |
slots[i]:Disconnect() | |
end | |
return shunt:Fire(...) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local validateRotation do | |
local dot = Vector3.new().Dot | |
local cross = Vector3.new().Cross | |
local abs = math.abs | |
local EPS = 1e-4 | |
local function assertEq(value, expected) | |
assert(abs(value - expected) < EPS) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Various ways of testing a screen point against a GuiBase2d | |
-- Note: Rounded rect corner radius is inferred from SliceCenter.Min.X | |
local cos = math.cos | |
local min = math.min | |
local rad = math.rad | |
local sin = math.sin | |
return { | |
-- Axis-aligned rectangle |
NewerOlder