/* Sweep algorithm for rasterization. */ auto int cmpy (int i, int j); /* Compares points {p[i]} and {p[j]} in Y-coordinate, then X: */ int cmpy (int i, int j) { return cmpy(&(p.el[i]), &(p.el[j])); } /* Sort vertices by increasing {y}. */ int ix[np]; int i; for (i = 0; i < np; i++) { ix[i] = i; } isrt_heapsort(ix, np, cmpy, +1); /* List of active edges: */ int ne = 0; /* Num of active edges, indexed {0..ne-1}. */ int v[n]; /* Lower vertex of edge {k} is {p[v[k]]}. */ int u[n]; /* Upper vertex of edge {k} is {p[u[k]]}. */ /* Agenda of future events (a heap sorted by Y): */ int_vec_t ag = int_vect_new(2*np); /* In theory {np^2}, but... */ int na = 0; /* Insert vertex events in agenda: */ /* Sweep with line in {+Y} direction: */ double ymin = p.el[ix[0]].c[1]; /* Minimum Y of polygon. */ double ymax = p.el[ix[np-1]].c[1]; /* Maximum Y of polygon. */ int iy = (int)floor((ymin - yorg)/dy); /* Index of current scan line. */ int ia = 0; /* Vertices {ix[ia..np-1]} haven't been swept over yet. */ int ns = 0; /* next vertex to sweep over is {p[ix[ns]]} */ while (iy < ny) { /* Compute Y-coord of row {iy}: */ double y = s->org.c[1] + iy*dy; /* Process events with ordinate {\leq y}: */ while ((ia < np) && (p.el[ix[ia]].c[1] <= y)) { /* Sweep over vertex {p[ix[ia]]}: */ cpk_update_active_list(u, v, &ne, p, ix[ia]); ia++; } /* Rasterize row: */