import java.awt.*; public class ScanLine extends poly { IEL iel; AEL ael; int y; int i; int xstart, xend; public String showState() { /* highlight active edges */ return "y = " + y + " i = " + i + " start " + xstart + " end " + xend + "\nActive Edge List =\n" + ael + "\nInactive Edge List =\n" + iel; } void drawPolygon(Polygon p){ iel = new IEL(); ael = new AEL(); if (p.npoints <= 2) return; /* build IEL */ for (int i = 1; i < p.npoints; i++) { Edge e = new Edge(p.xpoints[i-1],p.ypoints[i-1],p.xpoints[i],p.ypoints[i]); iel.add(e); } iel.add(new Edge(p.xpoints[p.npoints-1],p.ypoints[p.npoints-1],p.xpoints[0],p.ypoints[0])); /* loop over each scan line */ for (y = iel.miny(); y <= iel.maxy(); y++){ Edge e; while ((e=iel.next(y))!=null) { ael.add(e,y); } ael.deleteEdges(y); for (i = 0; i < ael.size(); i += 2) { xstart = ael.elementAt(i).xofi(y); xend = ael.elementAt(i+1).xofi(y); fillSpan(xstart, xend, y); if (step()) return; } } if (step()) return; } }