home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / awt / geom / FlatteningPathIterator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.8 KB  |  196 lines

  1. package java.awt.geom;
  2.  
  3. import java.util.NoSuchElementException;
  4.  
  5. public class FlatteningPathIterator implements PathIterator {
  6.    static final int GROW_SIZE = 24;
  7.    PathIterator src;
  8.    double squareflat;
  9.    int limit;
  10.    double[] hold;
  11.    double curx;
  12.    double cury;
  13.    double movx;
  14.    double movy;
  15.    int holdType;
  16.    int holdEnd;
  17.    int holdIndex;
  18.    int[] levels;
  19.    int levelIndex;
  20.    boolean done;
  21.  
  22.    public FlatteningPathIterator(PathIterator var1, double var2) {
  23.       this(var1, var2, 10);
  24.    }
  25.  
  26.    public FlatteningPathIterator(PathIterator var1, double var2, int var4) {
  27.       this.hold = new double[14];
  28.       if (var2 < (double)0.0F) {
  29.          throw new IllegalArgumentException("flatness must be >= 0");
  30.       } else if (var4 < 0) {
  31.          throw new IllegalArgumentException("limit must be >= 0");
  32.       } else {
  33.          this.src = var1;
  34.          this.squareflat = var2 * var2;
  35.          this.limit = var4;
  36.          this.levels = new int[var4 + 1];
  37.          this.next(false);
  38.       }
  39.    }
  40.  
  41.    public double getFlatness() {
  42.       return Math.sqrt(this.squareflat);
  43.    }
  44.  
  45.    public int getRecursionLimit() {
  46.       return this.limit;
  47.    }
  48.  
  49.    public int getWindingRule() {
  50.       return this.src.getWindingRule();
  51.    }
  52.  
  53.    public boolean isDone() {
  54.       return this.done;
  55.    }
  56.  
  57.    void ensureHoldCapacity(int var1) {
  58.       if (this.holdIndex - var1 < 0) {
  59.          int var2 = this.hold.length - this.holdIndex;
  60.          int var3 = this.hold.length + 24;
  61.          double[] var4 = new double[var3];
  62.          System.arraycopy(this.hold, this.holdIndex, var4, this.holdIndex + 24, var2);
  63.          this.hold = var4;
  64.          this.holdIndex += 24;
  65.          this.holdEnd += 24;
  66.       }
  67.  
  68.    }
  69.  
  70.    public void next() {
  71.       this.next(true);
  72.    }
  73.  
  74.    private void next(boolean var1) {
  75.       if (this.holdIndex >= this.holdEnd) {
  76.          if (var1) {
  77.             this.src.next();
  78.          }
  79.  
  80.          if (this.src.isDone()) {
  81.             this.done = true;
  82.             return;
  83.          }
  84.  
  85.          this.holdType = this.src.currentSegment(this.hold);
  86.          this.levelIndex = 0;
  87.          this.levels[0] = 0;
  88.       }
  89.  
  90.       switch (this.holdType) {
  91.          case 0:
  92.          case 1:
  93.             this.curx = this.hold[0];
  94.             this.cury = this.hold[1];
  95.             if (this.holdType == 0) {
  96.                this.movx = this.curx;
  97.                this.movy = this.cury;
  98.             }
  99.  
  100.             this.holdIndex = 0;
  101.             this.holdEnd = 0;
  102.             break;
  103.          case 2:
  104.             if (this.holdIndex >= this.holdEnd) {
  105.                this.holdIndex = this.hold.length - 6;
  106.                this.holdEnd = this.hold.length - 2;
  107.                this.hold[this.holdIndex + 0] = this.curx;
  108.                this.hold[this.holdIndex + 1] = this.cury;
  109.                this.hold[this.holdIndex + 2] = this.hold[0];
  110.                this.hold[this.holdIndex + 3] = this.hold[1];
  111.                this.hold[this.holdIndex + 4] = this.curx = this.hold[2];
  112.                this.hold[this.holdIndex + 5] = this.cury = this.hold[3];
  113.             }
  114.  
  115.             for(int var3 = this.levels[this.levelIndex]; var3 < this.limit && !(QuadCurve2D.getFlatnessSq(this.hold, this.holdIndex) < this.squareflat); this.levels[this.levelIndex] = var3) {
  116.                this.ensureHoldCapacity(4);
  117.                QuadCurve2D.subdivide(this.hold, this.holdIndex, this.hold, this.holdIndex - 4, this.hold, this.holdIndex);
  118.                this.holdIndex -= 4;
  119.                ++var3;
  120.                this.levels[this.levelIndex] = var3;
  121.                ++this.levelIndex;
  122.             }
  123.  
  124.             this.holdIndex += 4;
  125.             --this.levelIndex;
  126.             break;
  127.          case 3:
  128.             if (this.holdIndex >= this.holdEnd) {
  129.                this.holdIndex = this.hold.length - 8;
  130.                this.holdEnd = this.hold.length - 2;
  131.                this.hold[this.holdIndex + 0] = this.curx;
  132.                this.hold[this.holdIndex + 1] = this.cury;
  133.                this.hold[this.holdIndex + 2] = this.hold[0];
  134.                this.hold[this.holdIndex + 3] = this.hold[1];
  135.                this.hold[this.holdIndex + 4] = this.hold[2];
  136.                this.hold[this.holdIndex + 5] = this.hold[3];
  137.                this.hold[this.holdIndex + 6] = this.curx = this.hold[4];
  138.                this.hold[this.holdIndex + 7] = this.cury = this.hold[5];
  139.             }
  140.  
  141.             for(int var2 = this.levels[this.levelIndex]; var2 < this.limit && !(CubicCurve2D.getFlatnessSq(this.hold, this.holdIndex) < this.squareflat); this.levels[this.levelIndex] = var2) {
  142.                this.ensureHoldCapacity(6);
  143.                CubicCurve2D.subdivide(this.hold, this.holdIndex, this.hold, this.holdIndex - 6, this.hold, this.holdIndex);
  144.                this.holdIndex -= 6;
  145.                ++var2;
  146.                this.levels[this.levelIndex] = var2;
  147.                ++this.levelIndex;
  148.             }
  149.  
  150.             this.holdIndex += 6;
  151.             --this.levelIndex;
  152.             break;
  153.          case 4:
  154.             this.curx = this.movx;
  155.             this.cury = this.movy;
  156.             this.holdIndex = 0;
  157.             this.holdEnd = 0;
  158.       }
  159.  
  160.    }
  161.  
  162.    public int currentSegment(float[] var1) {
  163.       if (this.isDone()) {
  164.          throw new NoSuchElementException("flattening iterator out of bounds");
  165.       } else {
  166.          int var2 = this.holdType;
  167.          if (var2 != 4) {
  168.             var1[0] = (float)this.hold[this.holdIndex + 0];
  169.             var1[1] = (float)this.hold[this.holdIndex + 1];
  170.             if (var2 != 0) {
  171.                var2 = 1;
  172.             }
  173.          }
  174.  
  175.          return var2;
  176.       }
  177.    }
  178.  
  179.    public int currentSegment(double[] var1) {
  180.       if (this.isDone()) {
  181.          throw new NoSuchElementException("flattening iterator out of bounds");
  182.       } else {
  183.          int var2 = this.holdType;
  184.          if (var2 != 4) {
  185.             var1[0] = this.hold[this.holdIndex + 0];
  186.             var1[1] = this.hold[this.holdIndex + 1];
  187.             if (var2 != 0) {
  188.                var2 = 1;
  189.             }
  190.          }
  191.  
  192.          return var2;
  193.       }
  194.    }
  195. }
  196.