-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
32 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {Graph} from "math/Graph"; | ||
import {Circuit} from "./Circuit"; | ||
|
||
/** | ||
* This function converts the provided circuit to a graph where the nodes are components and edges are wires. | ||
* Both are represented by guids rather than object references. | ||
* | ||
* @param circuit The circuit to convert to a graph. | ||
* @returns The provided circuit as a graph. | ||
*/ | ||
export function CreateGraph(circuit: Circuit): Graph<string, string> { | ||
const graph = new Graph<string, string>(); | ||
|
||
const objs = circuit.getComponents(); | ||
for (const obj of objs) { | ||
graph.createNode(obj.id); | ||
} | ||
const wires = circuit.getWires(); | ||
for (const wire of wires) { | ||
graph.createEdge(wire.p1.parent.id, wire.p2.parent.id, wire.id); | ||
} | ||
|
||
return graph; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters