Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 82 additions & 28 deletions bun.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "litecanvas",
"version": "0.103.6",
"version": "0.103.7",
"description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and p5.js/Processing.",
"license": "MIT",
"author": "Luiz Bills <luizbills@pm.me>",
Expand Down Expand Up @@ -36,7 +36,7 @@
"@size-limit/preset-small-lib": "^12.0.1",
"@swc/core": "^1.15.18",
"ava": "^7.0.0",
"esbuild": "^0.27.3",
"esbuild": "^0.27.4",
"genversion": "^3.2.0",
"gzip-size": "^7.0.0",
"prettier": "^3.8.1",
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default function litecanvas(settings = {}) {
DEV: assert(isNumber(min), loggerPrefix + 'clamp() 2nd param must be a number')
DEV: assert(isNumber(max), loggerPrefix + 'clamp() 3rd param must be a number')
DEV: assert(
max > min,
max >= min,
loggerPrefix + 'clamp() the 2nd param must be less than the 3rd param'
)

Expand Down Expand Up @@ -319,7 +319,7 @@ export default function litecanvas(settings = {}) {
DEV: assert(isNumber(min), loggerPrefix + 'rand() 1st param must be a number')
DEV: assert(isNumber(max), loggerPrefix + 'rand() 2nd param must be a number')
DEV: assert(
max > min,
max >= min,
loggerPrefix + 'rand() the 1st param must be less than the 2nd param'
)

Expand All @@ -343,7 +343,7 @@ export default function litecanvas(settings = {}) {
DEV: assert(isNumber(min), loggerPrefix + 'randi() 1st param must be a number')
DEV: assert(isNumber(max), loggerPrefix + 'randi() 2nd param must be a number')
DEV: assert(
min <= max,
max >= min,
loggerPrefix + 'randi() the 1st param must be less than the 2nd param'
)

Expand Down
2 changes: 1 addition & 1 deletion src/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,21 @@ test('clamp', async (t) => {
t.is(local.clamp(-10, 0, 100), 0)
t.is(local.clamp(50, 0, 100), 50)
t.is(local.clamp(999999, 0, 100), 100)
t.is(local.clamp(0, 33, 33), 33)

t.throws(() => {
local.clamp(1, 1000, 1)
})
})

test('wrap', async (t) => {
t.is(local.wrap(5, 0, 10), 5)
t.is(local.wrap(-1, 0, 10), 9)
t.is(local.wrap(11, 0, 10), 1)

t.throws(() => {
local.wrap(1, 10, 10)
})
})

test('map', async (t) => {
Expand Down
8 changes: 8 additions & 0 deletions tests/rand.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ test('by default, produces random float numbers between 0 and 1.0', async (t) =>
t.true(randomNumber >= 0 && randomNumber < 1.0)
}
})

test('MIN and MAX with same input', async (t) => {
for (let i = 0; i < N; i++) {
const x = 10
const randomNumber = local.rand(x, x)
t.true(randomNumber === x)
}
})
8 changes: 8 additions & 0 deletions tests/randi.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ test('by default, produces 0 or 1', async (t) => {
t.true(randomNumber === 0 || randomNumber === 1)
}
})

test('MIN and MAX with same input', async (t) => {
for (let i = 0; i < N; i++) {
const x = 10
const randomNumber = local.randi(x, x)
t.true(randomNumber === x)
}
})
Loading