4 import java.awt.Rectangle;
10 int BLACK=0xff000000, WHITE=0xffffffff;
47 void allocateArrays(
int n) {
48 if (ex==null || n>ex.length) {
54 eslope =
new double[n];
59 void buildEdgeTable(
int[] x,
int[] y,
int n) {
60 int length, iplus1, x1, x2, y1, y2;
62 for (
int i=0; i<n; i++) {
63 iplus1 = i==n-1?0:i+1;
64 y1 = y[i]; y2 = y[iplus1];
65 x1 = x[i]; x2 = x[iplus1];
74 double slope = (double)(x2-x1)/(y2-y1);
75 ex[edges] = x1 + slope/2.0;
78 eslope[edges] = slope;
81 for (
int i=0; i<edges; i++)
90 void addToSortedTable(
int edge) {
92 while (index<edges && ey1[edges]>ey1[sedge[index]]) {
95 for (
int i=edges-1; i>=index; i--) {
96 sedge[i+1] = sedge[i];
110 buildEdgeTable(x, y, n);
112 int x1, x2, offset, index;
114 byte[] pixels = (byte[])mask.
getPixels();
115 for (
int y=0; y<height; y++) {
116 removeInactiveEdges(y);
119 for (
int i=0; i<activeEdges; i+=2) {
120 x1 = (int)(ex[aedge[i]]+0.5);
122 if (x1>width) x1 = width;
123 x2 = (int)(ex[aedge[i+1]]+0.5);
125 if (x2>width) x2 = width;
127 for (
int x=x1; x<x2; x++)
128 pixels[offset+x] = -1;
130 updateXCoordinates();
136 void updateXCoordinates() {
138 double x1=-Double.MAX_VALUE, x2;
139 boolean sorted =
true;
140 for (
int i=0; i<activeEdges; i++) {
142 x2 = ex[index] + eslope[index];
144 if (x2<x1) sorted =
false;
152 void sortActiveEdges() {
154 for (
int i=0; i<activeEdges; i++) {
156 for (
int j=i; j<activeEdges; j++)
157 if (ex[aedge[j]] <ex[aedge[min]]) min = j;
159 aedge[min] = aedge[i];
165 void removeInactiveEdges(
int y) {
167 while (i<activeEdges) {
168 int index = aedge[i];
169 if (y<ey1[index] || y>=ey2[index]) {
170 for (
int j=i; j<activeEdges-1; j++)
171 aedge[j] = aedge[j+1];
179 void activateEdges(
int y) {
180 for (
int i=0; i<edges; i++) {
184 while (index<activeEdges && ex[edge]>ex[aedge[index]])
186 for (
int j=activeEdges-1; j>=index; j--)
187 aedge[j+1] = aedge[j];
196 for (
int i=0; i<edges; i++) {
197 int index = sedge[i];
198 IJ.log(i+
" "+ex[index]+
" "+ey1[index]+
" "+ey2[index] +
" " + IJ.d2s(eslope[index],2) );
203 void printActiveEdges() {
204 for (
int i=0; i<activeEdges; i++) {
206 IJ.log(i+
" "+ex[index]+
" "+ey1[index]+
" "+ey2[index] );