BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
|
import { compile } from '../app/lib/logic/compile'
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
|
import { faceCandidates, pixelKey, screenLayouts, shapeOf, splitScreens } from '../app/lib/logic/geometry'
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
|
import { matchScore } from '../app/lib/match'
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
|
import { createProject, lookup } from '../app/lib/logic/ops'
|
|
|
|
|
|
import { toProject } from '../app/lib/logic/project'
|
|
|
|
|
|
import { Simulator } from '../app/lib/logic/sim'
|
|
|
|
|
|
import type { ComponentDef } from '../app/lib/logic/types'
|
|
|
|
|
|
|
|
|
|
|
|
function shown(): { p: ReturnType<typeof createProject>; inner: ComponentDef } {
|
|
|
|
|
|
const p = createProject({ examples: false })
|
|
|
|
|
|
const inner: ComponentDef = {
|
|
|
|
|
|
id: 'inner',
|
|
|
|
|
|
name: 'Show',
|
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'a', kind: 'input', x: 0, y: 0, label: 'A' },
|
|
|
|
|
|
{ id: 'b', kind: 'input', x: 0, y: 1, label: 'B' },
|
|
|
|
|
|
{ id: 'l', kind: 'lamp', x: 6, y: 0, label: 'L' },
|
|
|
|
|
|
{ id: 'h', kind: 'hex', x: 6, y: 4 },
|
|
|
|
|
|
{ id: 'q', kind: 'output', x: 12, y: 0, label: 'Q' },
|
|
|
|
|
|
],
|
|
|
|
|
|
wires: [{ id: 'w', from: { node: 'a', pin: 'q' }, to: { node: 'l', pin: 'a' } }],
|
|
|
|
|
|
}
|
|
|
|
|
|
p.components.push(inner)
|
|
|
|
|
|
return { p, inner }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe('hex display', () => {
|
|
|
|
|
|
it('passes its four bits on, so it can sit in the middle of a bus', () => {
|
|
|
|
|
|
const p = createProject({ examples: false })
|
|
|
|
|
|
const def: ComponentDef = {
|
|
|
|
|
|
id: 'root',
|
|
|
|
|
|
name: 'Root',
|
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 's', kind: 'input', x: 0, y: 0 },
|
|
|
|
|
|
{ id: 'h', kind: 'hex', x: 4, y: 0 },
|
|
|
|
|
|
{ id: 'l', kind: 'lamp', x: 10, y: 0 },
|
|
|
|
|
|
],
|
|
|
|
|
|
wires: [
|
|
|
|
|
|
{ id: 'a', from: { node: 's', pin: 'q' }, to: { node: 'h', pin: 'b0' } },
|
|
|
|
|
|
{ id: 'b', from: { node: 'h', pin: 'q0' }, to: { node: 'l', pin: 'a' } },
|
|
|
|
|
|
],
|
|
|
|
|
|
}
|
|
|
|
|
|
p.components.push(def)
|
|
|
|
|
|
expect(shapeOf(def.nodes[1]!, lookup(p)).outputs.map(o => o.key)).toEqual(['q0', 'q1', 'q2', 'q3'])
|
|
|
|
|
|
const sim = new Simulator(compile(lookup(p), 'root'))
|
|
|
|
|
|
sim.setSource('s', true)
|
|
|
|
|
|
sim.run()
|
|
|
|
|
|
expect(sim.pin('l', 'a')).toBe(1)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
describe('a box drawn by hand', () => {
|
|
|
|
|
|
it('takes its size, places things where they were put, leaves hidden ones off, carries drawings', () => {
|
|
|
|
|
|
const { p, inner } = shown()
|
|
|
|
|
|
const chip = { id: 'c', kind: 'chip' as const, chip: 'inner', x: 0, y: 0 }
|
|
|
|
|
|
const auto = shapeOf(chip, lookup(p))
|
|
|
|
|
|
expect(auto.face?.map(f => f.id)).toEqual(['l', 'h'])
|
|
|
|
|
|
inner.design = {
|
|
|
|
|
|
w: 9,
|
|
|
|
|
|
h: 7,
|
|
|
|
|
|
place: { l: { x: 5, y: 1 }, name: { x: 3, y: 5 } },
|
|
|
|
|
|
hide: ['h'],
|
|
|
|
|
|
shapes: [{ id: 's1', kind: 'rect', x: 1, y: 1, w: 2, h: 2, ink: 'red' }],
|
|
|
|
|
|
}
|
|
|
|
|
|
const s = shapeOf(chip, lookup(p))
|
|
|
|
|
|
expect(s.body.w).toBe(9)
|
|
|
|
|
|
expect(s.body.h).toBe(7)
|
|
|
|
|
|
// Outputs move to the new right edge; inputs stay on the left.
|
|
|
|
|
|
expect(s.outputs.every(o => o.dx === 9)).toBe(true)
|
|
|
|
|
|
expect(s.face).toEqual([expect.objectContaining({ id: 'l', x: 5, y: s.body.y + 1 })])
|
|
|
|
|
|
expect(s.nameAt).toEqual({ x: 3, y: s.body.y + 5 })
|
|
|
|
|
|
expect(s.drawing?.[0]).toMatchObject({ id: 's1', y: s.body.y + 1 })
|
|
|
|
|
|
// Never shorter than its pins need.
|
|
|
|
|
|
inner.design.h = 1
|
|
|
|
|
|
expect(shapeOf(chip, lookup(p)).body.h).toBeGreaterThanOrEqual(2)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('a broken design from a file is dropped, a broken drawing too', () => {
|
|
|
|
|
|
const { p, inner } = shown()
|
|
|
|
|
|
inner.design = { w: 6, h: 4, shapes: [{ id: 'x', kind: 'rect', x: 0, y: 0, w: 1, h: 1 }, { id: 'y', kind: 'laser' as 'rect', x: 0, y: 0, w: 1, h: 1 }] }
|
|
|
|
|
|
const back = toProject(JSON.parse(JSON.stringify(p)))
|
|
|
|
|
|
expect(back.components.find(d => d.id === 'inner')!.design!.shapes!.map(s => s.id)).toEqual(['x'])
|
|
|
|
|
|
;(inner as { design: unknown }).design = { w: 'big' }
|
|
|
|
|
|
expect(toProject(JSON.parse(JSON.stringify(p))).components.find(d => d.id === 'inner')!.design).toBeUndefined()
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
|
|
|
|
|
|
|
describe('the box, finer', () => {
|
|
|
|
|
|
it('pixels make one screen per screen name', () => {
|
|
|
|
|
|
const def: ComponentDef = {
|
|
|
|
|
|
id: 'd',
|
|
|
|
|
|
name: 'D',
|
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'p1', kind: 'pixel', x: 0, y: 0 },
|
|
|
|
|
|
{ id: 'p2', kind: 'pixel', x: 1, y: 0 },
|
|
|
|
|
|
{ id: 'q1', kind: 'pixel', x: 0, y: 5, screen: 'Status' },
|
|
|
|
|
|
],
|
|
|
|
|
|
wires: [],
|
|
|
|
|
|
}
|
|
|
|
|
|
expect(screenLayouts(def).map(s => [s.key, s.pixels!.length])).toEqual([
|
|
|
|
|
|
['screen', 2],
|
|
|
|
|
|
['screen:Status', 1],
|
|
|
|
|
|
])
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('shows displays of components inside when asked, with their values, and spaces pins', () => {
|
|
|
|
|
|
const { p, inner } = shown()
|
|
|
|
|
|
const outer: ComponentDef = {
|
|
|
|
|
|
id: 'outer',
|
|
|
|
|
|
name: 'Outer',
|
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'x', kind: 'input', x: 0, y: 0, label: 'X' },
|
|
|
|
|
|
{ id: 'y', kind: 'input', x: 0, y: 1, label: 'Y' },
|
|
|
|
|
|
{ id: 'u', kind: 'chip', chip: 'inner', x: 5, y: 0 },
|
|
|
|
|
|
],
|
|
|
|
|
|
wires: [{ id: 'w', from: { node: 'x', pin: 'q' }, to: { node: 'u', pin: 'a' } }],
|
|
|
|
|
|
}
|
|
|
|
|
|
const root: ComponentDef = {
|
|
|
|
|
|
id: 'root',
|
|
|
|
|
|
name: 'Root',
|
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 's', kind: 'input', x: -4, y: 0 },
|
|
|
|
|
|
{ id: 'o', kind: 'chip', chip: 'outer', x: 0, y: 0 },
|
|
|
|
|
|
],
|
|
|
|
|
|
wires: [{ id: 'v', from: { node: 's', pin: 'q' }, to: { node: 'o', pin: 'x' } }],
|
|
|
|
|
|
}
|
|
|
|
|
|
p.components.push(outer, root)
|
|
|
|
|
|
const get = lookup(p)
|
|
|
|
|
|
const cands = faceCandidates(outer, get)
|
|
|
|
|
|
expect(cands.filter(c => c.nested).map(c => c.key)).toEqual(['u/l', 'u/h'])
|
|
|
|
|
|
const chip = { id: 'o', kind: 'chip' as const, chip: 'outer', x: 0, y: 0 }
|
|
|
|
|
|
expect(shapeOf(chip, get).face ?? []).toEqual([])
|
|
|
|
|
|
outer.design = { w: 8, h: 6, show: ['u/l'], scale: { 'u/l': 2 }, rotate: { 'u/l': 90 }, pinAt: { y: 3 } }
|
|
|
|
|
|
const s = shapeOf(chip, get)
|
|
|
|
|
|
expect(s.face).toEqual([expect.objectContaining({ id: 'u/l', key: 'u/l', scale: 2, rotate: 90 })])
|
|
|
|
|
|
// Y was put three rows down, under X: a gap.
|
|
|
|
|
|
expect(s.inputs.map(i => i.dy)).toEqual([0, 3])
|
|
|
|
|
|
// The lamp deep inside lights on the outer box when its signal is on.
|
|
|
|
|
|
const sim = new Simulator(compile(get, 'root'))
|
|
|
|
|
|
sim.setSource('s', true)
|
|
|
|
|
|
sim.run()
|
|
|
|
|
|
expect(sim.face('o', 'u/l', 'a')).toBe(1)
|
|
|
|
|
|
void inner
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
describe('finding parts', () => {
|
|
|
|
|
|
it('matches names by start, word, inside, and letters in order', () => {
|
|
|
|
|
|
expect(matchScore('Adder 4', 'adder 4')).toBeGreaterThan(matchScore('Adder 4', 'add'))
|
|
|
|
|
|
expect(matchScore('Adder 4', 'add')).toBeGreaterThan(matchScore('Full Adder', 'add'))
|
|
|
|
|
|
expect(matchScore('Full Adder', 'add')).toBeGreaterThan(matchScore('Ladder', 'add'))
|
|
|
|
|
|
expect(matchScore('Adder 4', 'adr4')).toBeGreaterThan(0)
|
|
|
|
|
|
expect(matchScore('Lamp', 'xyz')).toBe(0)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
|
|
|
|
|
|
|
describe('the box designer, more', () => {
|
|
|
|
|
|
/** A 2×2 screen of pixels and two inputs, in a component placed once in another. */
|
|
|
|
|
|
function screened() {
|
|
|
|
|
|
const p = createProject({ examples: false })
|
|
|
|
|
|
const inner: ComponentDef = {
|
|
|
|
|
|
id: 'inner',
|
|
|
|
|
|
name: 'Scr',
|
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'a', kind: 'input', x: 0, y: 0, label: 'A' },
|
|
|
|
|
|
{ id: 'b', kind: 'input', x: 0, y: 1, label: 'B' },
|
|
|
|
|
|
{ id: 'p1', kind: 'pixel', x: 6, y: 0 },
|
|
|
|
|
|
{ id: 'p2', kind: 'pixel', x: 8, y: 0 },
|
|
|
|
|
|
{ id: 'p3', kind: 'pixel', x: 6, y: 2 },
|
|
|
|
|
|
{ id: 'p4', kind: 'pixel', x: 8, y: 2 },
|
|
|
|
|
|
],
|
|
|
|
|
|
wires: [],
|
|
|
|
|
|
}
|
|
|
|
|
|
p.components.push(inner)
|
|
|
|
|
|
return { p, inner, get: lookup(p), node: { id: 'c', kind: 'chip' as const, chip: 'inner', x: 0, y: 0 } }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
it('splitting a screen into pixels moves nothing, also sized and turned', () => {
|
|
|
|
|
|
const [screen] = screenLayouts(screened().inner)
|
|
|
|
|
|
for (const rotate of [undefined, 90, 180, 270]) {
|
|
|
|
|
|
const it = { ...screen!, x: 1, y: 1, scale: 2, ...(rotate ? { rotate } : {}) }
|
|
|
|
|
|
const pixels = splitScreens([it], new Set([it.key]))
|
|
|
|
|
|
expect(pixels).toHaveLength(4)
|
|
|
|
|
|
// The four pixels cover exactly the screen's turned square: 2 × 2 pixels of 1 × 2 = a 4 × 4 square at 1, 1.
|
|
|
|
|
|
const xs = pixels.map(px => px.x).sort((a, b) => a - b)
|
|
|
|
|
|
const ys = pixels.map(px => px.y).sort((a, b) => a - b)
|
|
|
|
|
|
expect([xs[0], xs[3], ys[0], ys[3]]).toEqual([1, 3, 1, 3])
|
|
|
|
|
|
expect(pixels.every(px => px.scale === 2 && px.w === 1 && px.key === pixelKey(px.id) && px.screenOf === it.key)).toBe(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
// Turned a quarter, the top left pixel goes to the top right.
|
|
|
|
|
|
const turned = splitScreens([{ ...screen!, x: 0, y: 0, rotate: 90 }], new Set([screen!.key]))
|
|
|
|
|
|
expect(turned.find(px => px.id === 'p1')).toMatchObject({ x: 1, y: 0 })
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('pins can change order on their edge', () => {
|
|
|
|
|
|
const { inner, get, node } = screened()
|
|
|
|
|
|
const before = shapeOf(node, get).inputs.map(p => [p.key, p.dy])
|
|
|
|
|
|
inner.design = { w: 6, h: 4, pinOrder: ['b', 'a'] }
|
|
|
|
|
|
const after = shapeOf(node, get).inputs
|
|
|
|
|
|
expect(after.find(p => p.key === 'b')!.dy).toBe(before[0]![1])
|
|
|
|
|
|
expect(after.find(p => p.key === 'a')!.dy).toBe(before[1]![1])
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('a fitted box grows and shrinks with what is on it; a set one keeps its size', () => {
|
|
|
|
|
|
const { inner, get, node } = screened()
|
|
|
|
|
|
inner.design = { w: 20, h: 20, fit: true, place: { screen: { x: 1, y: 1 } } }
|
|
|
|
|
|
const small = shapeOf(node, get).body
|
|
|
|
|
|
expect(small.w).toBeLessThan(20)
|
|
|
|
|
|
inner.design.place!.screen = { x: 12, y: 1 }
|
|
|
|
|
|
expect(shapeOf(node, get).body.w).toBeGreaterThan(small.w + 8)
|
|
|
|
|
|
delete inner.design.fit
|
|
|
|
|
|
inner.design.place!.screen = { x: 1, y: 1 }
|
|
|
|
|
|
expect(shapeOf(node, get).body.w).toBe(20)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('a display of a part inside shows in a free spot inside the box, not below it', () => {
|
|
|
|
|
|
const { p } = screened()
|
|
|
|
|
|
const outer: ComponentDef = {
|
|
|
|
|
|
id: 'outer',
|
|
|
|
|
|
name: 'Outer',
|
|
|
|
|
|
symbol: 'box',
|
|
|
|
|
|
nodes: [
|
|
|
|
|
|
{ id: 'x', kind: 'chip', chip: 'inner', x: 0, y: 0 },
|
|
|
|
|
|
...['i0', 'i1', 'i2', 'i3', 'i4', 'i5'].map((id, k) => ({ id, kind: 'input' as const, x: -6, y: k, label: id })),
|
|
|
|
|
|
],
|
|
|
|
|
|
wires: [],
|
|
|
|
|
|
design: { w: 10, h: 7, fit: true, show: ['x/screen'] },
|
|
|
|
|
|
}
|
|
|
|
|
|
p.components.push(outer)
|
|
|
|
|
|
const shape = shapeOf({ id: 'o', kind: 'chip', chip: 'outer', x: 0, y: 0 }, lookup(p))
|
|
|
|
|
|
const scr = shape.face!.find(f => f.key === 'x/screen')!
|
|
|
|
|
|
expect(scr.y + scr.h).toBeLessThanOrEqual(shape.body.y + shape.body.h)
|
|
|
|
|
|
// The six inputs make it six rows high; the screen fits beside their names.
|
|
|
|
|
|
expect(shape.body.h).toBeLessThan(7)
|
|
|
|
|
|
expect(scr.from).toBe('Scr')
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|