+static void mark_crossings(game_state *state)
+{
+ int ok = TRUE;
+ int i, j;
+ edge *e, *e2;
+
+#ifdef SHOW_CROSSINGS
+ for (i = 0; (e = index234(state->graph->edges, i)) != NULL; i++)
+ state->crosses[i] = FALSE;
+#endif
+
+ /*
+ * Check correctness: for every pair of edges, see whether they
+ * cross.
+ */
+ for (i = 0; (e = index234(state->graph->edges, i)) != NULL; i++) {
+ for (j = i+1; (e2 = index234(state->graph->edges, j)) != NULL; j++) {
+ if (e2->a == e->a || e2->a == e->b ||
+ e2->b == e->a || e2->b == e->b)
+ continue;
+ if (cross(state->pts[e2->a], state->pts[e2->b],
+ state->pts[e->a], state->pts[e->b])) {
+ ok = FALSE;
+#ifdef SHOW_CROSSINGS
+ state->crosses[i] = state->crosses[j] = TRUE;
+#else
+ goto done; /* multi-level break - sorry */
+#endif
+ }
+ }
+ }
+
+ /*
+ * e == NULL if we've gone through all the edge pairs
+ * without finding a crossing.
+ */
+#ifndef SHOW_CROSSINGS
+ done:
+#endif
+ if (ok)
+ state->completed = TRUE;
+}
+