in graphLayout/jetbrains.mps.graphLayout.orthogonalLayout/source_gen/jetbrains/mps/graphLayout/flowOrthogonalLayout/ConstraintsGraph.java [95:159]
private void makeShapeComplete(Face face) {
List<Node> segments = ListSequence.fromList(new LinkedList<Node>());
List<Direction2D> directions = ListSequence.fromList(new LinkedList<Direction2D>());
List<Integer> rotations = ListSequence.fromList(new LinkedList<Integer>());
Node prevSeg = null;
for (Dart dart : ListSequence.fromList(face.getDarts())) {
Direction2D dir = MapSequence.fromMap(myDirections).get(dart);
Node source = dart.getSource();
Node seg;
if (dir.isHorizontal()) {
seg = MapSequence.fromMap(myHorNodeMap).get(source);
} else {
seg = MapSequence.fromMap(myVerNodeMap).get(source);
}
if (seg != prevSeg) {
if (prevSeg != null) {
ListSequence.fromList(rotations).addElement(ListSequence.fromList(directions).last().getTurn(dir));
}
ListSequence.fromList(segments).addElement(seg);
ListSequence.fromList(directions).addElement(dir);
}
prevSeg = seg;
}
if (prevSeg != ListSequence.fromList(segments).first()) {
ListSequence.fromList(rotations).addElement(ListSequence.fromList(directions).last().getTurn(ListSequence.fromList(directions).first()));
} else {
ListSequence.fromList(directions).removeLastElement();
ListSequence.fromList(segments).removeLastElement();
}
if (ConstraintsGraph.SHOW_INFO > 0) {
System.out.println(face);
for (int i = 0; i < ListSequence.fromList(segments).count(); i++) {
System.out.println(ListSequence.fromList(segments).getElement(i) + " dir = " + ListSequence.fromList(directions).getElement(i) + " rot = " + ListSequence.fromList(rotations).getElement(i));
}
}
int numShifts = 0;
while (ListSequence.fromList(segments).count() > 4) {
if ((int) ListSequence.fromList(rotations).getElement(0) == -1 && (int) ListSequence.fromList(rotations).getElement(1) == 1 && (int) ListSequence.fromList(rotations).getElement(2) == 1) {
connectPattern(segments, directions);
for (int i = 0; i < 2; i++) {
ListSequence.fromList(segments).removeElementAt(1);
ListSequence.fromList(rotations).removeElementAt(1);
ListSequence.fromList(directions).removeElementAt(1);
}
ListSequence.fromList(rotations).setElement(0, 1);
numShifts = 0;
} else {
ListSequence.fromList(segments).insertElement(0, ListSequence.fromList(segments).removeLastElement());
ListSequence.fromList(rotations).insertElement(0, ListSequence.fromList(rotations).removeLastElement());
ListSequence.fromList(directions).insertElement(0, ListSequence.fromList(directions).removeLastElement());
numShifts++;
if (numShifts > 2 * ListSequence.fromList(segments).count()) {
throw new RuntimeException("error in segments");
}
}
}
if (ConstraintsGraph.DEBUG > 0) {
for (int rotation : rotations) {
if (rotation != 1) {
throw new RuntimeException("bad face completion result!");
}
}
}
connectPattern(segments, directions);
}