| 12345678910111213141516171819202122232425262728293031323334 |
- import test from "node:test";
- import assert from "node:assert/strict";
- import {readFile} from "node:fs/promises";
- import {BoardWasmAccelerator} from "../../tools/board-viewer/web/wasm-engine.mjs";
- test("wide body edges remain pickable beyond the WASM center grid", async () => {
- const accelerator = new BoardWasmAccelerator();
- const bytes = await readFile(new URL("../../tools/board-viewer/web/board-accel.wasm", import.meta.url));
- assert.equal(await accelerator.init(bytes), true);
- const connector = {
- reference: "CON_WIDE", category: "CON", side: "both",
- view_bounds: {x: 165, y: 25, width: 70, height: 10}, pins: [],
- };
- const data = {board: {view_box: {width: 430, height: 75}}, touchpoints: [connector], resistors: []};
- accelerator.buildIndex(data);
- // This exact shipped binary omits an interior edge outside its nine cells.
- assert.equal(accelerator.wasm.wasm_hit_test(231, 30, 0, 1, 0, 0.35), -1);
- const pick = (x, y, side = "front", categories = new Set(["CON"]), shield = false) =>
- accelerator.hitTest(x, y, side, categories, shield, 1);
- assert.equal(pick(200, 30)?.touchpoint, connector);
- assert.equal(pick(231, 30)?.touchpoint, connector);
- assert.equal(pick(199, 30, "back")?.touchpoint, connector);
- assert.equal(pick(237, 30), null);
- assert.equal(pick(231, 30, "front", new Set()), null);
- connector.pins.push({number: "1", view_position: {x: 231, y: 30}, size: {width: 1.4, height: 1.4}, shape: "circle", pad_role: "contact"});
- accelerator.buildIndex(data);
- assert.equal(pick(231, 30)?.pin, connector.pins[0]);
- connector.pins[0].number = "SH1";
- accelerator.buildIndex(data);
- assert.equal(pick(231, 30)?.kind, "touchpoint");
- assert.equal(pick(231, 30, "front", new Set(["CON"]), true)?.kind, "pin");
- accelerator.ready = false;
- assert.equal(pick(231, 30)?.touchpoint, connector);
- });
|