Linear math for JS