Packets now travel along the cable, and a drag takes its cables with it (#1228) #1229
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!1229
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/ping-along-the-cable"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Packets now travel along the cable, and a drag takes its cables with it
Fixes #1228.
A ping animated one dot per
frameevent, and the dot went from the centre of the source chassis tothe centre of the destination. The cable is drawn socket-to-socket, so the dot crossed empty canvas
while the cable ran somewhere else. Drag a device first and it got worse: the dot used the new layout
while the cables were still painted at the old positions, so the animation matched neither.
What changed in
web/canvas.jsThe dot follows the cable.
animateEvents()now resolves each event'sfromIface/toIfacethrough a new
socketPoint()— the sameportWorld()coordinates the cable is drawn along. The frameevents have carried the ports all along (
engine/simulator.jsemits{ from, fromIface, to, toIface });the animation just never used them.
A drag moves the cables. The
pointermovehandler translated the device<g>on its own, so thebox slid out from under its own cables until an unrelated redraw. Cables drawn in the last frame are now
tracked (
cableNodes), anddragPreview(deviceId, dx, dy)shifts the endpoints that belong to thedragged device — exact, because the geometry is straight lines. The far ends stay put.
A drag is redrawn on release.
on.move()persisted the layout but nothing re-rendered, so thesocket table (used by hit testing and the animation) kept the pre-drag coordinates.
pointerupnowcalls
render()after the move.ensureGeoCurrent()before animating. If the layout has moved since the last frame was drawn — apersisted drag with no redraw, or a move from another client arriving mid-animation — geometry is
recomputed and the cables redrawn, rather than animating to a stale socket.
No invented positions.
deviceCenter()returned{ x: 100, y: 100 }for a device with no layoutentry, which is a real point in world coordinates: the dot flew to the top-left corner of the grid. The
animation now uses the position the canvas actually drew, and
socketPoint()returnsnullfor adevice it has never heard of, so a bad event is skipped instead of drawn somewhere misleading.
Evidence
New
test/canvas-ping-path.test.js(20 checks) loads the realweb/canvas.jsagainst a recording stubDOM with a controllable animation clock, runs a real ping frame, and reads every position the dot was
given:
Reverting just the two lines of
animateEvents()reproduces the old failure:Also asserted: a device moved in the layout without a redraw is still animated at its new socket (the
ensureGeoCurrent()path),dragPreview()moves the attached end by exactly the drag and leaves the farend alone, the socket table follows the drag, and an unknown device has no position.
docs/ARCHITECTURE.mdgains "One source of position": the socket table, the four rules that keep ittrue, and why the drawing and the animation must read the same coordinates.
Suite: 131 suites, 5,735 assertions, 0 failed.