Skip to content

Commit

Permalink
connect should not reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 30, 2023
1 parent 7c03ef9 commit f7afaac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lang/graph/cleanUpWires.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Net } from "./Net"
import { connect } from "./connect"
import { removeEdge } from "./removeEdge"
import { disconnect } from "./disconnect"
import { removeNode } from "./removeNode"

export function cleanUpWires(net: Net): void {
for (const wire of net.wires) {
if (wire.start.connection && wire.end.connection) {
removeEdge(net, wire.start.connection.edge)
removeEdge(net, wire.end.connection.edge)

removeNode(net, wire.start.node)
removeNode(net, wire.end.node)

connect(net, wire.start.connection.port, wire.end.connection.port)
const start = wire.start.connection.port
const end = wire.end.connection.port

disconnect(net, wire.start.connection.edge)
disconnect(net, wire.end.connection.edge)

connect(net, start, end)
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/lang/graph/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { lookupRuleByPorts } from "../mod/lookupRuleByPorts"
export function connect(net: Net, start: Port, end: Port): void {
const rule = lookupRuleByPorts(net.mod, start, end)

if (start.connection !== undefined) {
throw new Error(`[connect] The start port is already connected`)
}

if (end.connection !== undefined) {
throw new Error(`[connect] The end port is already connected`)
}

if (rule !== undefined) {
const edge = { start, end, rule }
start.connection = { edge, port: end }
Expand Down

0 comments on commit f7afaac

Please sign in to comment.