Skip to content

Instantly share code, notes, and snippets.

@tesselode
tesselode / line_segment_and_circle_intersections.rs
Created May 16, 2021 01:55
Returns the entrance and exit intersections of a line segment with a circle
// based on https://stackoverflow.com/a/1084899
// Vec2 is from the vek crate
type Entrance = Vec2<f32>;
type Exit = Vec2<f32>;
fn line_segment_and_circle_intersections(
line_segment_start: Vec2<f32>,
line_segment_end: Vec2<f32>,
circle_center: Vec2<f32>,
local function sign(x)
return x < 0 and -1 or 1
end
local function signedPower(x, n)
return sign(x) * (math.abs(x) ^ n)
end
local regularFont = love.graphics.newFont('font/CourierPrime-Bold.ttf', 48)
@tesselode
tesselode / async.lua
Created March 21, 2020 06:48
the promise implementation i'm currently using in my puzzle game
local function async(f)
local co
local function await(promise)
if promise:isFinished() then return end
promise:after(function()
local success, message = coroutine.resume(co)
if not success then error(message) end
end)
coroutine.yield()
end
@tesselode
tesselode / swept-aabb.lua
Last active March 31, 2023 04:18
swept AABB collision detection implemented in Lua (commentated)
--[[
moves rectangle A by (dx, dy) and checks for a collision
with rectangle B.
if no collision occurs, returns false.
if a collision does occur, returns:
- the time within the movement when the collision occurs (from 0-1)
- the x component of the normal vector
- the y component of the normal vector