Fix lever switch rotation issue

Render pickup name instead of model

Netlist algorithm would sometimes create overlapping groups of nodes
which are supposed to be merged
This commit is contained in:
Branislav Stojkovic
2019-03-02 09:11:00 +01:00
parent cc0f698c8b
commit b3497cdca8
9 changed files with 99 additions and 12 deletions
@@ -227,6 +227,11 @@ public class Tree {
}
public Tree findCommonParent(Tree t1, Tree t2) {
if (t1 == null)
return t2;
if (t2 == null)
return t1;
if (children == null)
return null;
@@ -248,6 +253,25 @@ public class Tree {
return p1.findCommonParent(t1, t2);
}
public Tree findCommonParent(List<Tree> t) {
if (t.contains(null))
{
while(t.contains(null))
t.remove(null);
return findCommonParent(t);
}
if (t.size() == 0)
return null;
if (t.size() == 1)
return t.get(0);
if (t.size() == 2)
return findCommonParent(t.get(0), t.get(1));
List<Tree> remainder = t.subList(1, t.size());
return findCommonParent(t.get(0), findCommonParent(remainder));
}
public boolean contains(Tree t) {
if (this == t)
return true;
@@ -2755,7 +2755,7 @@ public class Presenter implements IPlugInPort {
List<Line2D> connections = getConnections(switchPositions);
Netlist graph = constructNetlist(nodes, connections, continuity);
// merge graphs that are effectivelly the same
// merge graphs that are effectively the same
if (result.containsKey(graph)) {
result.get(graph).getSwitchSetup().add(new SwitchSetup(posList));
} else {
@@ -2827,6 +2827,29 @@ public class Presenter implements IPlugInPort {
}
}
// merge overlapping groups if needed
boolean reduce = true;
while (reduce) {
reduce = false;
List<Group> groups = netlist.getSortedGroups();
Iterator<Group> i = groups.iterator();
while (i.hasNext()) {
Group g1 = i.next();
for (Group g2 : groups) {
if (g1 != g2 && !Collections.disjoint(g1.getNodes(), g2.getNodes())) {
i.remove();
g2.getNodes().addAll(g1.getNodes());
reduce = true;
break;
}
}
}
if (reduce) {
netlist.getGroups().clear();
netlist.getGroups().addAll(groups);
}
}
Collections.sort(netlist.getSwitchSetup());
return netlist;