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

Print this page




  60         return yhi;
  61     }
  62 
  63     public abstract void record(double ystart, double yend, int direction);
  64 
  65     public void print() {
  66         System.out.println("Crossings [");
  67         System.out.println("  bounds = ["+ylo+", "+yhi+"]");
  68         for (int i = 0; i < limit; i += 2) {
  69             System.out.println("  ["+yranges[i]+", "+yranges[i+1]+"]");
  70         }
  71         System.out.println("]");
  72     }
  73 
  74     public final boolean isEmpty() {
  75         return (limit == 0);
  76     }
  77 
  78     public abstract boolean covers(double ystart, double yend);
  79 
  80     public static Crossings findCrossings(Vector curves,
  81                                           double xlo, double ylo,
  82                                           double xhi, double yhi)
  83     {
  84         Crossings cross = new EvenOdd(xlo, ylo, xhi, yhi);
  85         Enumeration enum_ = curves.elements();
  86         while (enum_.hasMoreElements()) {
  87             Curve c = (Curve) enum_.nextElement();
  88             if (c.accumulateCrossings(cross)) {
  89                 return null;
  90             }
  91         }
  92         if (debug) {
  93             cross.print();
  94         }
  95         return cross;
  96     }
  97 
  98     public static Crossings findCrossings(PathIterator pi,
  99                                           double xlo, double ylo,
 100                                           double xhi, double yhi)
 101     {
 102         Crossings cross;
 103         if (pi.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
 104             cross = new EvenOdd(xlo, ylo, xhi, yhi);
 105         } else {
 106             cross = new NonZero(xlo, ylo, xhi, yhi);
 107         }


 220             xstart = x0;
 221             ystart = y0;
 222         }
 223         if (yhi < y1) {
 224             xend = x0 + (yhi - y0) * dx / dy;
 225             yend = yhi;
 226         } else {
 227             xend = x1;
 228             yend = y1;
 229         }
 230         if (xstart >= xhi && xend >= xhi) {
 231             return false;
 232         }
 233         if (xstart > xlo || xend > xlo) {
 234             return true;
 235         }
 236         record(ystart, yend, direction);
 237         return false;
 238     }
 239 
 240     private Vector tmp = new Vector();
 241 
 242     public boolean accumulateQuad(double x0, double y0, double coords[]) {
 243         if (y0 < ylo && coords[1] < ylo && coords[3] < ylo) {
 244             return false;
 245         }
 246         if (y0 > yhi && coords[1] > yhi && coords[3] > yhi) {
 247             return false;
 248         }
 249         if (x0 > xhi && coords[0] > xhi && coords[2] > xhi) {
 250             return false;
 251         }
 252         if (x0 < xlo && coords[0] < xlo && coords[2] < xlo) {
 253             if (y0 < coords[3]) {
 254                 record(Math.max(y0, ylo), Math.min(coords[3], yhi), 1);
 255             } else if (y0 > coords[3]) {
 256                 record(Math.max(coords[3], ylo), Math.min(y0, yhi), -1);
 257             }
 258             return false;
 259         }
 260         Curve.insertQuad(tmp, x0, y0, coords);
 261         Enumeration enum_ = tmp.elements();
 262         while (enum_.hasMoreElements()) {
 263             Curve c = (Curve) enum_.nextElement();
 264             if (c.accumulateCrossings(this)) {
 265                 return true;
 266             }
 267         }
 268         tmp.clear();
 269         return false;
 270     }
 271 
 272     public boolean accumulateCubic(double x0, double y0, double coords[]) {
 273         if (y0 < ylo && coords[1] < ylo &&
 274             coords[3] < ylo && coords[5] < ylo)
 275         {
 276             return false;
 277         }
 278         if (y0 > yhi && coords[1] > yhi &&
 279             coords[3] > yhi && coords[5] > yhi)
 280         {
 281             return false;
 282         }
 283         if (x0 > xhi && coords[0] > xhi &&
 284             coords[2] > xhi && coords[4] > xhi)
 285         {
 286             return false;
 287         }
 288         if (x0 < xlo && coords[0] < xlo &&
 289             coords[2] < xlo && coords[4] < xlo)
 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 enum_ = tmp.elements();
 300         while (enum_.hasMoreElements()) {
 301             Curve c = (Curve) 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 final 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;




  60         return yhi;
  61     }
  62 
  63     public abstract void record(double ystart, double yend, int direction);
  64 
  65     public void print() {
  66         System.out.println("Crossings [");
  67         System.out.println("  bounds = ["+ylo+", "+yhi+"]");
  68         for (int i = 0; i < limit; i += 2) {
  69             System.out.println("  ["+yranges[i]+", "+yranges[i+1]+"]");
  70         }
  71         System.out.println("]");
  72     }
  73 
  74     public final boolean isEmpty() {
  75         return (limit == 0);
  76     }
  77 
  78     public abstract boolean covers(double ystart, double yend);
  79 
  80     public static Crossings findCrossings(Vector<Curve> curves,
  81                                           double xlo, double ylo,
  82                                           double xhi, double yhi)
  83     {
  84         Crossings cross = new EvenOdd(xlo, ylo, xhi, yhi);
  85         Enumeration<Curve> enum_ = curves.elements();
  86         while (enum_.hasMoreElements()) {
  87             Curve c = enum_.nextElement();
  88             if (c.accumulateCrossings(cross)) {
  89                 return null;
  90             }
  91         }
  92         if (debug) {
  93             cross.print();
  94         }
  95         return cross;
  96     }
  97 
  98     public static Crossings findCrossings(PathIterator pi,
  99                                           double xlo, double ylo,
 100                                           double xhi, double yhi)
 101     {
 102         Crossings cross;
 103         if (pi.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
 104             cross = new EvenOdd(xlo, ylo, xhi, yhi);
 105         } else {
 106             cross = new NonZero(xlo, ylo, xhi, yhi);
 107         }


 220             xstart = x0;
 221             ystart = y0;
 222         }
 223         if (yhi < y1) {
 224             xend = x0 + (yhi - y0) * dx / dy;
 225             yend = yhi;
 226         } else {
 227             xend = x1;
 228             yend = y1;
 229         }
 230         if (xstart >= xhi && xend >= xhi) {
 231             return false;
 232         }
 233         if (xstart > xlo || xend > xlo) {
 234             return true;
 235         }
 236         record(ystart, yend, direction);
 237         return false;
 238     }
 239 
 240     private Vector<Curve> tmp = new Vector<>();
 241 
 242     public boolean accumulateQuad(double x0, double y0, double coords[]) {
 243         if (y0 < ylo && coords[1] < ylo && coords[3] < ylo) {
 244             return false;
 245         }
 246         if (y0 > yhi && coords[1] > yhi && coords[3] > yhi) {
 247             return false;
 248         }
 249         if (x0 > xhi && coords[0] > xhi && coords[2] > xhi) {
 250             return false;
 251         }
 252         if (x0 < xlo && coords[0] < xlo && coords[2] < xlo) {
 253             if (y0 < coords[3]) {
 254                 record(Math.max(y0, ylo), Math.min(coords[3], yhi), 1);
 255             } else if (y0 > coords[3]) {
 256                 record(Math.max(coords[3], ylo), Math.min(y0, yhi), -1);
 257             }
 258             return false;
 259         }
 260         Curve.insertQuad(tmp, x0, y0, coords);
 261         Enumeration<Curve> enum_ = tmp.elements();
 262         while (enum_.hasMoreElements()) {
 263             Curve c = enum_.nextElement();
 264             if (c.accumulateCrossings(this)) {
 265                 return true;
 266             }
 267         }
 268         tmp.clear();
 269         return false;
 270     }
 271 
 272     public boolean accumulateCubic(double x0, double y0, double coords[]) {
 273         if (y0 < ylo && coords[1] < ylo &&
 274             coords[3] < ylo && coords[5] < ylo)
 275         {
 276             return false;
 277         }
 278         if (y0 > yhi && coords[1] > yhi &&
 279             coords[3] > yhi && coords[5] > yhi)
 280         {
 281             return false;
 282         }
 283         if (x0 > xhi && coords[0] > xhi &&
 284             coords[2] > xhi && coords[4] > xhi)
 285         {
 286             return false;
 287         }
 288         if (x0 < xlo && coords[0] < xlo &&
 289             coords[2] < xlo && coords[4] < xlo)
 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 final 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;