Skip to content

Schematic wires disconnected from component pins due to floating-point precision issues #292

@tommyhzx

Description

@tommyhzx

Problem Description

When converting Circuit JSON to KiCad schematic, wires may appear disconnected from component pins (particularly inductors and other components using predefined symbols) due to floating-point precision issues in coordinate calculations.

Specific Symptoms
Wires connect correctly to chip pins
Wires fail to connect to inductor/predefined symbol pins (coordinates appear misaligned)
Generated .kicad_sch file contains long floating-point numbers (e.g., 10.1599999 instead of 10.16)

Root Cause Analysis

Schematic relies on coordinate matching for connectivity
Unlike PCB, schematic conversion does not use a net system and relies on exact coordinate matching to determine electrical connections:

// lib/schematic/stages/AddSchematicTracesStage.ts:78-81
const x1 = from.x // Direct use of floating point, no precision control
const y1= from.y
const x2 = to.x
const y2 = to.y

Coordinate source differences
Chips: Pin positions dynamically calculated, continuous coordinates
Inductors/passive components: Use predefined symbols from schematic-symbols, fixed coordinates
After c2kMatSch matrix transformation, minute differences can accumulate

Suggested Solution

Add coordinate precision control in lib/schematic/stages/AddSchematicTracesStage.ts:

Option 1: Fixed decimal precision
const PRECISION = 6 // 6 decimal places (micron-level precision)
const x1 = Number(from.x.toFixed(PRECISION))
const y1 = Number(from.y.toFixed(PRECISION))
const x2 = Number(to.x.toFixed(PRECISION))
const y2 = Number(to.y.toFixed(PRECISION))
Option 2: Grid snapping (KiCad default grid is 1.27mm)

const snapToGrid = (coord: number) =>
Math.round(coord / 1.27) * 1.27
const x1 = snapToGrid(from.x)
// ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions