Skip to content
Closed
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions tests/solderjumper-fp-precision.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { test, expect } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import type { PcbSmtPad, PcbTrace } from "circuit-json"
import { solderjumper } from "../src/fn/solderjumper"

// These values (p=1.0414, pw=0.6604) are from the SparkFun Qwiic ToF Imager
// VL53L5CX board. They are NOT exactly representable in IEEE 754 binary FP,
// which triggers the compound error in the bridge trace endpoint calculation.
test.failing(
"solderjumper bridge trace endpoint lands inside pad (FP precision)",
() => {
const result = solderjumper({
num_pins: 3,
bridged: "123",
p: 1.0414,
pw: 0.6604,
ph: 1.27,
})

const pads = result.circuitJson.filter(
(e): e is PcbSmtPad => e.type === "pcb_smtpad",
)
const traces = result.circuitJson.filter(
(e): e is PcbTrace => e.type === "pcb_trace",
)

const trace = traces[0]
const pad2 = pads.find((p) => p.port_hints?.includes("2"))!
const halfWidth = 0.6604 / 2

const svg = convertCircuitJsonToPcbSvg(result.circuitJson)
expect(svg).toMatchSvgSnapshot(
import.meta.path,
"solderjumper3_bridged123_p1.0414_pw0.6604_ph1.27",
)

// The endpoint at the pad edge should be within the pad boundary
// This fails because 1.0414 - 0.3302 = 0.7112 has a compound FP error
// making |0.7112 - 1.0414| = 0.33020000000000005 > 0.3302
expect(Math.abs(trace!.route[1].x - pad2!.x)).toBeLessThanOrEqual(halfWidth)
},
)
Loading