Skip to content

Commit fed933e

Browse files
Update code considering memory limits
1 parent ed8de7a commit fed933e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

public/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function pointDansPolygone(px, py, sommets) {
111111
return dedans;
112112
}
113113

114-
function couleurImageKMeans(pixels, larg, haut, maxSamples = 2000) {
114+
function couleurImageKMeans(pixels, larg, haut, maxSamples = 96) {
115115
const total = larg * haut;
116116
const step = Math.max(1, Math.floor(total / maxSamples));
117117
km_init(3);

tests/smoke.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ function buildHarness() {
161161
globalThis.__testExports = {
162162
state,
163163
METHODES,
164+
couleurImageKMeans,
164165
rendreSortie,
165166
lierControles,
166167
basculerOnglet,
@@ -362,11 +363,30 @@ async function testRenderSanitizesTileSizeBeforeWasm() {
362363
assert.strictEqual(api.state.side, 30);
363364
}
364365

366+
function testKMeansSamplingStaysUnderWasmLimit() {
367+
const { api } = buildHarness();
368+
let sampleCount = 0;
369+
370+
api.setWasm({
371+
couleur_moyenne(total, count) { return Math.round(total / count); },
372+
km_init(k) { assert.strictEqual(k, 3); },
373+
km_ajouter() { sampleCount += 1; },
374+
km_calculer(maxIter) { assert.strictEqual(maxIter, 20); },
375+
km_r() { return 0; },
376+
km_g() { return 0; },
377+
km_b() { return 0; },
378+
});
379+
380+
api.couleurImageKMeans(new Uint8ClampedArray(640 * 480 * 4), 640, 480);
381+
assert.ok(sampleCount <= 100, `expected at most 100 k-means samples, got ${sampleCount}`);
382+
}
383+
365384
async function run() {
366385
testHtmlSmoke();
367386
testMethodChangeTriggersRender();
368387
testTabSwitching();
369388
testAllMethodsGenerateTiles();
389+
testKMeansSamplingStaysUnderWasmLimit();
370390
await testFlowerImageProducesTilesInWasm();
371391
await testRenderSanitizesTileSizeBeforeWasm();
372392
console.log("Smoke tests passed.");

0 commit comments

Comments
 (0)