Placement
Instead of hard-coding millimeter coordinates, use the placement helpers to position components relative to each other and the board edges. All gaps are measured courtyard edge to courtyard edge.
component.pcb
The position of a component on the board. Assign an object with x, y (mm from the origin) and optional rotation (degrees) — or any of the deferred placement values from pcb.board.
Example first
import { PCB, Component } from '@typecad/pcb';
let pcb = new PCB('typecad_docs');
pcb.outline(0, 0, 60, 45);
let u1 = new Component({ footprint: '...' });
u1.pcb = { x: 10, y: 20, rotation: 90 };pcb.board
The board's physical dimensions, read live from the outlines you've defined. Usable before or after pcb.outline() — values follow the final outline. Placement values are live and order-independent: every deferred expression is re-resolved at create() against final positions.
Example first
let u1 = new Component({ footprint: '...' });
u1.pcb = { x: b.center.x, y: b.center.y }; // center of the boardBoardBounds
| Property | Description |
|---|---|
| center | { x, y } center point (centers the component's origin) |
| centered() | { x, y } placement values that center the component's occupied box — rotation- and origin-aware |
| left, right, top, bottom | Edge coordinates in mm |
| width, height | Board dimensions in mm |
| topLeft, topRight, bottomLeft, bottomRight | Corner coordinates |
| fromLeft(n), fromRight(n), fromTop(n), fromBottom(n) | A fixed distance in from that edge |
Edge-relative placement
import { PCB, Component } from '@typecad/pcb';
let pcb = new PCB('typecad_docs');
pcb.outline(0, 0, 60, 45);
const b = pcb.board;
let u1 = new Component({ footprint: '...' });
u1.pcb = { x: b.center.x, y: b.center.y };Relational verbs
All placement lives on pcb.board — one namespace, no separate imports:
| Verb | Description |
|---|---|
| below(c) / above(c) | Place below/above component c |
| rightOf(c) / leftOf(c) | Place right/left of component c |
| sameAs(c) | Follow component c's position |
| .by(n) | Override the default gap (mm) |
| .plus(n) / .minus(n) | Live arithmetic on deferred values — returns a new deferred value |
r2.pcb = { x: 10, y: pcb.board.below(r1).by(3) }; // 3 mm below r1's courtyard
mh1.pcb = { ...pcb.board.centered() }; // centered on the boardlive arithmetic value.plus(n) / value.minus(n)
Placement values support live arithmetic — .plus(n)/.minus(n) return
new deferred values, so expressions follow their source at create():
let r2 = new Component({ footprint: '...' });
r2.pcb = {
x: pcb.board.sameAs(r1).x.plus(2), // follow r1 at create() time
y: pcb.board.below(r1),
};