@@ -22,6 +22,24 @@ export class AddTracesStage extends ConverterStage<CircuitJson, KicadPcb> {
2222 this . pcbTraces = this . ctx . db . pcb_trace . list ( )
2323 }
2424
25+ private getRoutePointPosition ( point : any , edge : "start" | "end" ) {
26+ const position =
27+ typeof point . x === "number" && typeof point . y === "number"
28+ ? { x : point . x , y : point . y }
29+ : point [ edge ]
30+
31+ if (
32+ typeof position ?. x !== "number" ||
33+ typeof position ?. y !== "number" ||
34+ ! Number . isFinite ( position . x ) ||
35+ ! Number . isFinite ( position . y )
36+ ) {
37+ return null
38+ }
39+
40+ return position
41+ }
42+
2543 override _step ( ) : void {
2644 const { kicadPcb, c2kMatPcb, pcbNetMap } = this . ctx
2745
@@ -52,17 +70,28 @@ export class AddTracesStage extends ConverterStage<CircuitJson, KicadPcb> {
5270 for ( let i = 0 ; i < trace . route . length - 1 ; i ++ ) {
5371 const startPoint = trace . route [ i ]
5472 const endPoint = trace . route [ i + 1 ]
73+ const startPosition = this . getRoutePointPosition ( startPoint , "end" )
74+ const endPosition = this . getRoutePointPosition ( endPoint , "start" )
75+
76+ if ( ! startPosition || ! endPosition ) continue
5577
5678 // Transform points to KiCad coordinates
5779 const transformedStart = applyToPoint ( c2kMatPcb , {
58- x : startPoint . x ,
59- y : startPoint . y ,
80+ x : startPosition . x ,
81+ y : startPosition . y ,
6082 } )
6183 const transformedEnd = applyToPoint ( c2kMatPcb , {
62- x : endPoint . x ,
63- y : endPoint . y ,
84+ x : endPosition . x ,
85+ y : endPosition . y ,
6486 } )
6587
88+ if (
89+ transformedStart . x === transformedEnd . x &&
90+ transformedStart . y === transformedEnd . y
91+ ) {
92+ continue
93+ }
94+
6695 let netInfo : PcbNetInfo | undefined
6796 if ( pcbNetMap ) {
6897 let connectivityKey : string | undefined =
0 commit comments