Improve performance of netlist calculations

This commit is contained in:
Branislav Stojkovic
2019-03-14 00:08:39 +01:00
parent 37d5ce18fc
commit f8e24b0937
8 changed files with 21 additions and 23 deletions
@@ -556,7 +556,7 @@ public class DrawingManager {
return areas;
}
private void expandConnections(Set<Connection> connections) {
public void expandConnections(Set<Connection> connections) {
Set<Connection> toAdd = new HashSet<Connection>();
for (Connection c1 : connections)
for (Connection c2 : connections) {
@@ -596,15 +596,19 @@ public class DrawingManager {
continue;
Area a1 = areas.get(i);
Area a2 = areas.get(j);
Area intersection = new Area(a1);
intersection.intersect(a2);
Area intersection = null;
if (a1.getBounds2D().intersects(a2.getBounds())) {
intersection = new Area(a1);
intersection.intersect(a2);
}
// if the two areas intersect, make a union and consume the second area
if (!intersection.isEmpty()) {
if (intersection != null && !intersection.isEmpty()) {
a1.add(a2);
consumed.set(j, true);
} else { // maybe there's a connection between them
for (Connection p : connections) {
if ((a1.contains(p.getP1()) && a2.contains(p.getP2())) || (a1.contains(p.getP2()) && a2.contains(p.getP1()))) {
for (Connection p : connections) { // use getBounds to optimize the computation, don't get into complex math if not needed
if ((a1.getBounds().contains(p.getP1()) && a2.getBounds().contains(p.getP2()) && a1.contains(p.getP1()) && a2.contains(p.getP2())) ||
(a1.getBounds().contains(p.getP2()) && a2.getBounds().contains(p.getP1())) && a1.contains(p.getP2()) && a2.contains(p.getP1())) {
a1.add(a2);
consumed.set(j, true);
break;
@@ -2910,7 +2910,7 @@ public class Presenter implements IPlugInPort {
@SuppressWarnings("unchecked")
private List<Connection> getConnections(Map<ISwitch, Integer> switchPositions) {
List<Connection> connections = new ArrayList<Connection>();
Set<Connection> connections = new HashSet<Connection>();
for (IDIYComponent<?> c : currentProject.getComponents()) {
ComponentType type =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
@@ -2930,9 +2930,11 @@ public class Presenter implements IPlugInPort {
if (s.arePointsConnected(i, j, position))
connections.add(new Connection(c.getControlPoint(i), c.getControlPoint(j)));
}
}
}
return connections;
drawingManager.expandConnections(connections);
return new ArrayList<Connection>(connections);
}
@Override