pixalynx/pixal-gps

These files define two separate printed circuit boards: a small, two-layer battery cartridge with protection circuitry and contact pads for a pouch cell, and a larger, two-layer wireless charging dock featuring USB-C input, a resonant coil, and wireless power transmission components.

Version
0.1.2
License
unset
Stars
0

review/source-build/lib/geometry.ts

/** Small PCB geometry helpers shared by the three boards.
 *
 * tscircuit `<trace pcbPath>` points are interpreted as offsets from the centre
 * of the component that owns the trace's anchor pad (the `from` pad unless
 * `pcbPathRelativeTo` names another port), rotated by that component's
 * `pcbRotation`. Board-frame coordinates therefore have to be converted before
 * they are handed to a trace. `toLocal` does that conversion.
 */
export type Pt = { x: number; y: number }

export function toLocal(p: Pt, centre: Pt, rotationDeg = 0): Pt {
  const dx = p.x - centre.x, dy = p.y - centre.y
  const a = (-rotationDeg * Math.PI) / 180
  const c = Math.cos(a), s = Math.sin(a)
  return { x: +(dx * c - dy * s).toFixed(4), y: +(dx * s + dy * c).toFixed(4) }
}

/** Convert a board-frame polyline (optionally with layer changes) into pcbPath entries. */
export function localPath(
  points: (Pt & { via?: boolean; toLayer?: "top" | "bottom" | "inner1" | "inner2" })[],
  centre: Pt,
  rotationDeg = 0,
) {
  return points.map((p) => ({ ...toLocal(p, centre, rotationDeg), ...(p.via ? { via: true, toLayer: p.toLayer } : {}) }))
}

export const round = (v: number, d = 3) => +v.toFixed(d)