pixalynx/pixal-nfc-card
This code defines React components representing specific electronic hardware components—namely, a 100-ohm SMD resistor, a surface-mount LED, and a chip with labeled pins—each modeled with detailed footprints, 3D CAD models, and manufacturer part information for PCB design.
- Version
- 1.1.0
- License
- unset
- Stars
- 0
lib/artwork.ts
import type { Pt } from "./coil"
const r4 = (p: Pt): Pt => ({ x: Math.round(p.x * 1e4) / 1e4, y: Math.round(p.y * 1e4) / 1e4 })
/** Closed polyline of a rounded rectangle centred on (cx, cy). */
export function roundedRectPolyline(cx: number, cy: number, w: number, h: number, r: number, cornerSegments = 12): Pt[] {
const hw = w / 2 - r
const hh = h / 2 - r
const corners = [
{ x: cx + hw, y: cy + hh, a0: 0 },
{ x: cx - hw, y: cy + hh, a0: 90 },
{ x: cx - hw, y: cy - hh, a0: 180 },
{ x: cx + hw, y: cy - hh, a0: 270 },
]
const pts: Pt[] = []
for (const c of corners) {
for (let i = 0; i <= cornerSegments; i++) {
const a = ((c.a0 + (90 * i) / cornerSegments) * Math.PI) / 180
pts.push({ x: c.x + r * Math.cos(a), y: c.y + r * Math.sin(a) })
}
}
pts.push(pts[0])
return pts
}
/** Cut a polyline into dashes of `dash` mm separated by `gap` mm. */
export function dashPolyline(poly: Pt[], dash: number, gap: number): Pt[][] {
const dashes: Pt[][] = []
let cur: Pt[] = []
let drawing = true
let remaining = dash
for (let i = 0; i < poly.length - 1; i++) {
let a = poly[i]
const b = poly[i + 1]
let segLen = Math.hypot(b.x - a.x, b.y - a.y)
while (segLen > 1e-9) {
const step = Math.min(remaining, segLen)
const t = step / segLen
const p = { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t }
if (drawing) {
if (cur.length === 0) cur.push(a)
cur.push(p)
}
remaining -= step
segLen -= step
a = p
if (remaining <= 1e-9) {
if (drawing && cur.length > 1) dashes.push(cur)
cur = []
drawing = !drawing
remaining = drawing ? dash : gap
}
}
}
if (drawing && cur.length > 1) dashes.push(cur)
return dashes.map((d) => d.map(r4))
}
/** Arc polyline around (cx, cy), angles in degrees counter-clockwise from +x. */
export function arc(cx: number, cy: number, r: number, startDeg: number, endDeg: number, segments = 16): Pt[] {
const pts: Pt[] = []
for (let i = 0; i <= segments; i++) {
const a = ((startDeg + ((endDeg - startDeg) * i) / segments) * Math.PI) / 180
pts.push(r4({ x: cx + r * Math.cos(a), y: cy + r * Math.sin(a) }))
}
return pts
}