Skip to content

Commit

Permalink
more safety checks
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Sep 27, 2023
1 parent a6b8be2 commit 9c80c45
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/com/marginallyclever/nodegraphcore/Subgraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class Subgraph extends Node implements SupergraphInput, SupergraphOutput, PrintWithGraphics {
private final Graph graph = new Graph();

private class VariablePair {
static class VariablePair {
public Dock<?> superVariable;
public Dock<?> subVariable;

Expand Down Expand Up @@ -43,11 +43,14 @@ public Subgraph(Graph graph) {
/**
* Stores a deep copy of the given graph and exposes the {@link SupergraphInput}s and {@link SupergraphOutput}s to
* the supergraph.
* @param graph the {@link Graph} to store.
* @param graph the {@link Graph} to store. A deep copy is made.
*/
public void setGraph(Graph graph) {
this.graph.clear();
this.graph.add(graph.deepCopy());

if(graph!=null) {
this.graph.add(graph.deepCopy());
}

for(Node n : this.graph.getNodes()) {
extractSupergraphInputs(n);
Expand Down Expand Up @@ -106,7 +109,7 @@ private void extractSupergraphInputs(Node n) {
private int sortVariables(VariablePair a, VariablePair b) {
// all input first
int aIn = (a.subVariable instanceof DockReceiving)?1:0;
int bIn = (a.subVariable instanceof DockReceiving)?1:0;
int bIn = (b.subVariable instanceof DockReceiving)?1:0;
if(aIn != bIn) return aIn-bIn;
// then sort by name alphabetically
return a.subVariable.getName().compareTo(b.subVariable.getName());
Expand Down

0 comments on commit 9c80c45

Please sign in to comment.