Skip to content

Commit 4a00358

Browse files
authored
Add repro15 for DSN coordinate scaling bug (#129)
1 parent 02b252f commit 4a00358

3 files changed

Lines changed: 149 additions & 2 deletions

File tree

bun.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
(pcb ./converted_dsn.dsn
2+
(parser
3+
(string_quote ")
4+
(space_in_quoted_tokens on)
5+
(host_cad "KiCad's Pcbnew")
6+
(host_version "")
7+
)
8+
(resolution um 10)
9+
(unit um)
10+
(structure
11+
(layer F.Cu
12+
(type signal)
13+
(property
14+
(index 0)
15+
)
16+
)
17+
(layer In1.Cu
18+
(type signal)
19+
(property
20+
(index 1)
21+
)
22+
)
23+
(layer In2.Cu
24+
(type signal)
25+
(property
26+
(index 2)
27+
)
28+
)
29+
(layer B.Cu
30+
(type signal)
31+
(property
32+
(index 3)
33+
)
34+
)
35+
(boundary
36+
(path pcb 0 -10000 -10000 10000 -10000 10000 10000 -10000 10000 -10000 -10000)
37+
)
38+
(via "Via[0-3]_600:300_um")
39+
(rule
40+
(width 200)
41+
(clearance 150)
42+
(clearance 50 (type smd_smd))
43+
)
44+
)
45+
(placement
46+
(component "simple_resistor:1.5600x0.6400_mm"
47+
(place R1_source_component_0 -4000 0 front 0 (PN "10k"))
48+
(place R2_source_component_1 4000 0 front 0 (PN "10k"))
49+
)
50+
)
51+
(library
52+
(image "simple_resistor:1.5600x0.6400_mm"
53+
(pin RoundRect[T]Pad_540x640_um 1 -509.9999999999998 0)
54+
(pin RoundRect[T]Pad_540x640_um 2 509.9999999999998 0)
55+
)
56+
(padstack "Via[0-3]_600:300_um"
57+
(shape (circle F.Cu 600))
58+
(shape (circle In1.Cu 600))
59+
(shape (circle In2.Cu 600))
60+
(shape (circle B.Cu 600))
61+
(attach off)
62+
)
63+
(padstack "RoundRect[T]Pad_540x640_um"
64+
(shape (polygon F.Cu 0 -270 320 270 320 270 -320 -270 -320 -270 320))
65+
(attach off)
66+
)
67+
)
68+
(network
69+
(net "Net-(R1_source_component_0-Pad2)"
70+
(pins R1_source_component_0-2 R2_source_component_1-1)
71+
)
72+
(net "unconnected-(R1_source_component_0-Pad1)"
73+
(pins R1_source_component_0-1)
74+
)
75+
(net "unconnected-(R2_source_component_1-Pad2)"
76+
(pins R2_source_component_1-2)
77+
)
78+
(class "kicad_default" "" "Net-(R1_source_component_0-Pad2)" "unconnected-(R1_source_component_0-Pad1)" "unconnected-(R2_source_component_1-Pad2)"
79+
(circuit
80+
(use_via "Via[0-3]_600:300_um")
81+
)
82+
(rule
83+
(width 150)
84+
(clearance 150)
85+
)
86+
)
87+
)
88+
(wiring
89+
)
90+
)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { expect, test } from "bun:test"
2+
import { Circuit } from "@tscircuit/core"
3+
import { convertCircuitJsonToDsnString } from "lib"
4+
5+
test("repro-coordinates-10x-too-large-with-circuit", async () => {
6+
const circuit = new Circuit()
7+
8+
circuit.add(
9+
<board width="20mm" height="20mm">
10+
<resistor
11+
name="R1"
12+
resistance="10k"
13+
footprint="0402"
14+
pcbX={-4}
15+
pcbY={0}
16+
supplierPartNumbers={{ jlcpcb: ["C25744"] }}
17+
/>
18+
<resistor
19+
name="R2"
20+
resistance="10k"
21+
footprint="0402"
22+
pcbX={4}
23+
pcbY={0}
24+
supplierPartNumbers={{ jlcpcb: ["C25744"] }}
25+
/>
26+
<trace from=".R1 > .pin2" to=".R2 > .pin1" />
27+
</board>,
28+
)
29+
30+
await circuit.render()
31+
const circuitJson = circuit.getCircuitJson()
32+
33+
const dsnString = convertCircuitJsonToDsnString(circuitJson as any)
34+
35+
// EXPLANATION OF THE BUG:
36+
// The DSN file declares a resolution of 10 units per micrometer (um).
37+
// This means that for a physical coordinate of 4mm (4000um), the DSN coordinate
38+
// should be 40,000 (4000um * 10 units/um).
39+
//
40+
// CURRENT (BUGGY) RESULT:
41+
// The converter currently only scales by 1000 (mm to um), but fails to multiply by the resolution.
42+
// Result: (place pcb_component_1 4000 0 front 0 )
43+
// When interpreted with resolution 10, this is 400um = 0.4mm, which is 10x too small.
44+
//
45+
// EXPECTED RESULT:
46+
// The coordinate should be 40000.
47+
// Expected: (place pcb_component_1 40000 0 front 0 )
48+
49+
// Verify resolution is 10
50+
expect(dsnString).toContain("(resolution um 10)")
51+
52+
// Verify faulty coordinates (confirming the bug exists)
53+
expect(dsnString).toContain("(place R1_source_component_0 -4000 0 front 0")
54+
expect(dsnString).toContain("(place R2_source_component_1 4000 0 front 0")
55+
})

0 commit comments

Comments
 (0)