Skip to content

Commit 966cb6c

Browse files
authored
Merge pull request #273 from litecanvas/fix
v0.103.7
2 parents c3bff2a + 18a8a72 commit 966cb6c

File tree

7 files changed

+113
-34
lines changed

7 files changed

+113
-34
lines changed

bun.lock

Lines changed: 82 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "litecanvas",
3-
"version": "0.103.6",
3+
"version": "0.103.7",
44
"description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and p5.js/Processing.",
55
"license": "MIT",
66
"author": "Luiz Bills <luizbills@pm.me>",
@@ -36,7 +36,7 @@
3636
"@size-limit/preset-small-lib": "^12.0.1",
3737
"@swc/core": "^1.15.18",
3838
"ava": "^7.0.0",
39-
"esbuild": "^0.27.3",
39+
"esbuild": "^0.27.4",
4040
"genversion": "^3.2.0",
4141
"gzip-size": "^7.0.0",
4242
"prettier": "^3.8.1",

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export default function litecanvas(settings = {}) {
210210
DEV: assert(isNumber(min), loggerPrefix + 'clamp() 2nd param must be a number')
211211
DEV: assert(isNumber(max), loggerPrefix + 'clamp() 3rd param must be a number')
212212
DEV: assert(
213-
max > min,
213+
max >= min,
214214
loggerPrefix + 'clamp() the 2nd param must be less than the 3rd param'
215215
)
216216

@@ -319,7 +319,7 @@ export default function litecanvas(settings = {}) {
319319
DEV: assert(isNumber(min), loggerPrefix + 'rand() 1st param must be a number')
320320
DEV: assert(isNumber(max), loggerPrefix + 'rand() 2nd param must be a number')
321321
DEV: assert(
322-
max > min,
322+
max >= min,
323323
loggerPrefix + 'rand() the 1st param must be less than the 2nd param'
324324
)
325325

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

src/version.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/math.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,21 @@ test('clamp', async (t) => {
5252
t.is(local.clamp(-10, 0, 100), 0)
5353
t.is(local.clamp(50, 0, 100), 50)
5454
t.is(local.clamp(999999, 0, 100), 100)
55+
t.is(local.clamp(0, 33, 33), 33)
56+
57+
t.throws(() => {
58+
local.clamp(1, 1000, 1)
59+
})
5560
})
5661

5762
test('wrap', async (t) => {
5863
t.is(local.wrap(5, 0, 10), 5)
5964
t.is(local.wrap(-1, 0, 10), 9)
6065
t.is(local.wrap(11, 0, 10), 1)
66+
67+
t.throws(() => {
68+
local.wrap(1, 10, 10)
69+
})
6170
})
6271

6372
test('map', async (t) => {

tests/rand.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ test('by default, produces random float numbers between 0 and 1.0', async (t) =>
3232
t.true(randomNumber >= 0 && randomNumber < 1.0)
3333
}
3434
})
35+
36+
test('MIN and MAX with same input', async (t) => {
37+
for (let i = 0; i < N; i++) {
38+
const x = 10
39+
const randomNumber = local.rand(x, x)
40+
t.true(randomNumber === x)
41+
}
42+
})

tests/randi.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ test('by default, produces 0 or 1', async (t) => {
3232
t.true(randomNumber === 0 || randomNumber === 1)
3333
}
3434
})
35+
36+
test('MIN and MAX with same input', async (t) => {
37+
for (let i = 0; i < N; i++) {
38+
const x = 10
39+
const randomNumber = local.randi(x, x)
40+
t.true(randomNumber === x)
41+
}
42+
})

0 commit comments

Comments
 (0)