src/java.desktop/share/classes/sun/awt/geom/Crossings.java

Print this page




 290         {
 291             if (y0 <= coords[5]) {
 292                 record(Math.max(y0, ylo), Math.min(coords[5], yhi), 1);
 293             } else {
 294                 record(Math.max(coords[5], ylo), Math.min(y0, yhi), -1);
 295             }
 296             return false;
 297         }
 298         Curve.insertCubic(tmp, x0, y0, coords);
 299         Enumeration<Curve> enum_ = tmp.elements();
 300         while (enum_.hasMoreElements()) {
 301             Curve c = enum_.nextElement();
 302             if (c.accumulateCrossings(this)) {
 303                 return true;
 304             }
 305         }
 306         tmp.clear();
 307         return false;
 308     }
 309 
 310     public final static class EvenOdd extends Crossings {
 311         public EvenOdd(double xlo, double ylo, double xhi, double yhi) {
 312             super(xlo, ylo, xhi, yhi);
 313         }
 314 
 315         public boolean covers(double ystart, double yend) {
 316             return (limit == 2 && yranges[0] <= ystart && yranges[1] >= yend);
 317         }
 318 
 319         public void record(double ystart, double yend, int direction) {
 320             if (ystart >= yend) {
 321                 return;
 322             }
 323             int from = 0;
 324             // Quickly jump over all pairs that are completely "above"
 325             while (from < limit && ystart > yranges[from+1]) {
 326                 from += 2;
 327             }
 328             int to = from;
 329             while (from < limit) {
 330                 double yrlo = yranges[from++];


 373                     break;
 374                 }
 375             }
 376             if (to < from && from < limit) {
 377                 System.arraycopy(yranges, from, yranges, to, limit-from);
 378             }
 379             to += (limit-from);
 380             if (ystart < yend) {
 381                 if (to >= yranges.length) {
 382                     double newranges[] = new double[to+10];
 383                     System.arraycopy(yranges, 0, newranges, 0, to);
 384                     yranges = newranges;
 385                 }
 386                 yranges[to++] = ystart;
 387                 yranges[to++] = yend;
 388             }
 389             limit = to;
 390         }
 391     }
 392 
 393     public final static class NonZero extends Crossings {
 394         private int crosscounts[];
 395 
 396         public NonZero(double xlo, double ylo, double xhi, double yhi) {
 397             super(xlo, ylo, xhi, yhi);
 398             crosscounts = new int[yranges.length / 2];
 399         }
 400 
 401         public boolean covers(double ystart, double yend) {
 402             int i = 0;
 403             while (i < limit) {
 404                 double ylo = yranges[i++];
 405                 double yhi = yranges[i++];
 406                 if (ystart >= yhi) {
 407                     continue;
 408                 }
 409                 if (ystart < ylo) {
 410                     return false;
 411                 }
 412                 if (yend <= yhi) {
 413                     return true;




 290         {
 291             if (y0 <= coords[5]) {
 292                 record(Math.max(y0, ylo), Math.min(coords[5], yhi), 1);
 293             } else {
 294                 record(Math.max(coords[5], ylo), Math.min(y0, yhi), -1);
 295             }
 296             return false;
 297         }
 298         Curve.insertCubic(tmp, x0, y0, coords);
 299         Enumeration<Curve> enum_ = tmp.elements();
 300         while (enum_.hasMoreElements()) {
 301             Curve c = enum_.nextElement();
 302             if (c.accumulateCrossings(this)) {
 303                 return true;
 304             }
 305         }
 306         tmp.clear();
 307         return false;
 308     }
 309 
 310     public static final class EvenOdd extends Crossings {
 311         public EvenOdd(double xlo, double ylo, double xhi, double yhi) {
 312             super(xlo, ylo, xhi, yhi);
 313         }
 314 
 315         public boolean covers(double ystart, double yend) {
 316             return (limit == 2 && yranges[0] <= ystart && yranges[1] >= yend);
 317         }
 318 
 319         public void record(double ystart, double yend, int direction) {
 320             if (ystart >= yend) {
 321                 return;
 322             }
 323             int from = 0;
 324             // Quickly jump over all pairs that are completely "above"
 325             while (from < limit && ystart > yranges[from+1]) {
 326                 from += 2;
 327             }
 328             int to = from;
 329             while (from < limit) {
 330                 double yrlo = yranges[from++];


 373                     break;
 374                 }
 375             }
 376             if (to < from && from < limit) {
 377                 System.arraycopy(yranges, from, yranges, to, limit-from);
 378             }
 379             to += (limit-from);
 380             if (ystart < yend) {
 381                 if (to >= yranges.length) {
 382                     double newranges[] = new double[to+10];
 383                     System.arraycopy(yranges, 0, newranges, 0, to);
 384                     yranges = newranges;
 385                 }
 386                 yranges[to++] = ystart;
 387                 yranges[to++] = yend;
 388             }
 389             limit = to;
 390         }
 391     }
 392 
 393     public static final class NonZero extends Crossings {
 394         private int crosscounts[];
 395 
 396         public NonZero(double xlo, double ylo, double xhi, double yhi) {
 397             super(xlo, ylo, xhi, yhi);
 398             crosscounts = new int[yranges.length / 2];
 399         }
 400 
 401         public boolean covers(double ystart, double yend) {
 402             int i = 0;
 403             while (i < limit) {
 404                 double ylo = yranges[i++];
 405                 double yhi = yranges[i++];
 406                 if (ystart >= yhi) {
 407                     continue;
 408                 }
 409                 if (ystart < ylo) {
 410                     return false;
 411                 }
 412                 if (yend <= yhi) {
 413                     return true;