imrishabh18/corne-keyboard

The code defines and renders two surface-mount chip components with SMT pads, silkscreen outlines, and 3D CAD models (OBJ and STEP) for PCB assembly.

Version
2.0.21
License
unset
Stars
1

scripts/normalize-via-transitions.mjs

/** Normalize sub-micron drift to the existing via center before regional repair. */
export function normalizeViaTransitions(routes) {
  const tolerance = 0.0001 // mm: 0.1 micrometre, never a routable distance
  let output = routes
  routes.forEach((route, routeIndex) => {
    for (let i = 1; i < route.route.length; i++) {
      const a = route.route[i - 1]
      const b = route.route[i]
      if (a.z === b.z || a.toNextSegmentType === 'through_obstacle') continue
      const separation = Math.hypot(a.x - b.x, a.y - b.y)
      if (separation <= 1e-8 || separation > tolerance) continue
      const via = route.vias?.find(v =>
        Math.hypot(a.x - v.x, a.y - v.y) <= tolerance &&
        Math.hypot(b.x - v.x, b.y - v.y) <= tolerance)
      if (!via) continue
      if (output === routes) output = structuredClone(routes)
      Object.assign(output[routeIndex].route[i - 1], { x: via.x, y: via.y })
      Object.assign(output[routeIndex].route[i], { x: via.x, y: via.y })
    }
  })
  return output
}