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 / GeneralPath.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.2 KB  |  326 lines

  1. package java.awt.geom;
  2.  
  3. import java.awt.Rectangle;
  4. import java.awt.Shape;
  5. import sun.awt.geom.Crossings;
  6. import sun.awt.geom.Curve;
  7.  
  8. public final class GeneralPath implements Shape, Cloneable {
  9.    public static final int WIND_EVEN_ODD = 0;
  10.    public static final int WIND_NON_ZERO = 1;
  11.    private static final byte SEG_MOVETO = 0;
  12.    private static final byte SEG_LINETO = 1;
  13.    private static final byte SEG_QUADTO = 2;
  14.    private static final byte SEG_CUBICTO = 3;
  15.    private static final byte SEG_CLOSE = 4;
  16.    byte[] pointTypes;
  17.    float[] pointCoords;
  18.    int numTypes;
  19.    int numCoords;
  20.    int windingRule;
  21.    static final int INIT_SIZE = 20;
  22.    static final int EXPAND_MAX = 500;
  23.  
  24.    public GeneralPath() {
  25.       this(1, 20, 20);
  26.    }
  27.  
  28.    public GeneralPath(int var1) {
  29.       this(var1, 20, 20);
  30.    }
  31.  
  32.    public GeneralPath(int var1, int var2) {
  33.       this(var1, var2, var2);
  34.    }
  35.  
  36.    GeneralPath(int var1, int var2, int var3) {
  37.       this.setWindingRule(var1);
  38.       this.pointTypes = new byte[var2];
  39.       this.pointCoords = new float[var3 * 2];
  40.    }
  41.  
  42.    public GeneralPath(Shape var1) {
  43.       this(1, 20, 20);
  44.       PathIterator var2 = var1.getPathIterator((AffineTransform)null);
  45.       this.setWindingRule(var2.getWindingRule());
  46.       this.append(var2, false);
  47.    }
  48.  
  49.    private void needRoom(int var1, int var2, boolean var3) {
  50.       if (var3 && this.numTypes == 0) {
  51.          throw new IllegalPathStateException("missing initial moveto in path definition");
  52.       } else {
  53.          int var4 = this.pointCoords.length;
  54.          if (this.numCoords + var2 > var4) {
  55.             int var5 = var4;
  56.             if (var4 > 1000) {
  57.                var5 = 1000;
  58.             }
  59.  
  60.             if (var5 < var2) {
  61.                var5 = var2;
  62.             }
  63.  
  64.             float[] var6 = new float[var4 + var5];
  65.             System.arraycopy(this.pointCoords, 0, var6, 0, this.numCoords);
  66.             this.pointCoords = var6;
  67.          }
  68.  
  69.          var4 = this.pointTypes.length;
  70.          if (this.numTypes + var1 > var4) {
  71.             int var8 = var4;
  72.             if (var4 > 500) {
  73.                var8 = 500;
  74.             }
  75.  
  76.             if (var8 < var1) {
  77.                var8 = var1;
  78.             }
  79.  
  80.             byte[] var9 = new byte[var4 + var8];
  81.             System.arraycopy(this.pointTypes, 0, var9, 0, this.numTypes);
  82.             this.pointTypes = var9;
  83.          }
  84.  
  85.       }
  86.    }
  87.  
  88.    public synchronized void moveTo(float var1, float var2) {
  89.       if (this.numTypes > 0 && this.pointTypes[this.numTypes - 1] == 0) {
  90.          this.pointCoords[this.numCoords - 2] = var1;
  91.          this.pointCoords[this.numCoords - 1] = var2;
  92.       } else {
  93.          this.needRoom(1, 2, false);
  94.          this.pointTypes[this.numTypes++] = 0;
  95.          this.pointCoords[this.numCoords++] = var1;
  96.          this.pointCoords[this.numCoords++] = var2;
  97.       }
  98.  
  99.    }
  100.  
  101.    public synchronized void lineTo(float var1, float var2) {
  102.       this.needRoom(1, 2, true);
  103.       this.pointTypes[this.numTypes++] = 1;
  104.       this.pointCoords[this.numCoords++] = var1;
  105.       this.pointCoords[this.numCoords++] = var2;
  106.    }
  107.  
  108.    public synchronized void quadTo(float var1, float var2, float var3, float var4) {
  109.       this.needRoom(1, 4, true);
  110.       this.pointTypes[this.numTypes++] = 2;
  111.       this.pointCoords[this.numCoords++] = var1;
  112.       this.pointCoords[this.numCoords++] = var2;
  113.       this.pointCoords[this.numCoords++] = var3;
  114.       this.pointCoords[this.numCoords++] = var4;
  115.    }
  116.  
  117.    public synchronized void curveTo(float var1, float var2, float var3, float var4, float var5, float var6) {
  118.       this.needRoom(1, 6, true);
  119.       this.pointTypes[this.numTypes++] = 3;
  120.       this.pointCoords[this.numCoords++] = var1;
  121.       this.pointCoords[this.numCoords++] = var2;
  122.       this.pointCoords[this.numCoords++] = var3;
  123.       this.pointCoords[this.numCoords++] = var4;
  124.       this.pointCoords[this.numCoords++] = var5;
  125.       this.pointCoords[this.numCoords++] = var6;
  126.    }
  127.  
  128.    public synchronized void closePath() {
  129.       if (this.numTypes == 0 || this.pointTypes[this.numTypes - 1] != 4) {
  130.          this.needRoom(1, 0, true);
  131.          this.pointTypes[this.numTypes++] = 4;
  132.       }
  133.  
  134.    }
  135.  
  136.    public void append(Shape var1, boolean var2) {
  137.       PathIterator var3 = var1.getPathIterator((AffineTransform)null);
  138.       this.append(var3, var2);
  139.    }
  140.  
  141.    public void append(PathIterator var1, boolean var2) {
  142.       for(float[] var3 = new float[6]; !var1.isDone(); var2 = false) {
  143.          switch (var1.currentSegment(var3)) {
  144.             case 0:
  145.                if (!var2 || this.numTypes < 1 || this.numCoords < 2) {
  146.                   this.moveTo(var3[0], var3[1]);
  147.                   break;
  148.                } else if (this.pointTypes[this.numTypes - 1] != 4 && this.pointCoords[this.numCoords - 2] == var3[0] && this.pointCoords[this.numCoords - 1] == var3[1]) {
  149.                   break;
  150.                }
  151.             case 1:
  152.                this.lineTo(var3[0], var3[1]);
  153.                break;
  154.             case 2:
  155.                this.quadTo(var3[0], var3[1], var3[2], var3[3]);
  156.                break;
  157.             case 3:
  158.                this.curveTo(var3[0], var3[1], var3[2], var3[3], var3[4], var3[5]);
  159.                break;
  160.             case 4:
  161.                this.closePath();
  162.          }
  163.  
  164.          var1.next();
  165.       }
  166.  
  167.    }
  168.  
  169.    public synchronized int getWindingRule() {
  170.       return this.windingRule;
  171.    }
  172.  
  173.    public void setWindingRule(int var1) {
  174.       if (var1 != 0 && var1 != 1) {
  175.          throw new IllegalArgumentException("winding rule must be WIND_EVEN_ODD or WIND_NON_ZERO");
  176.       } else {
  177.          this.windingRule = var1;
  178.       }
  179.    }
  180.  
  181.    public synchronized Point2D getCurrentPoint() {
  182.       if (this.numTypes >= 1 && this.numCoords >= 2) {
  183.          int var1 = this.numCoords;
  184.          if (this.pointTypes[this.numTypes - 1] == 4) {
  185.             for(int var2 = this.numTypes - 2; var2 > 0; --var2) {
  186.                switch (this.pointTypes[var2]) {
  187.                   case 0:
  188.                      return new Point2D.Float(this.pointCoords[var1 - 2], this.pointCoords[var1 - 1]);
  189.                   case 1:
  190.                      var1 -= 2;
  191.                      break;
  192.                   case 2:
  193.                      var1 -= 4;
  194.                      break;
  195.                   case 3:
  196.                      var1 -= 6;
  197.                   case 4:
  198.                }
  199.             }
  200.          }
  201.  
  202.          return new Point2D.Float(this.pointCoords[var1 - 2], this.pointCoords[var1 - 1]);
  203.       } else {
  204.          return null;
  205.       }
  206.    }
  207.  
  208.    public synchronized void reset() {
  209.       this.numTypes = this.numCoords = 0;
  210.    }
  211.  
  212.    public void transform(AffineTransform var1) {
  213.       var1.transform(this.pointCoords, 0, this.pointCoords, 0, this.numCoords / 2);
  214.    }
  215.  
  216.    public synchronized Shape createTransformedShape(AffineTransform var1) {
  217.       GeneralPath var2 = (GeneralPath)this.clone();
  218.       if (var1 != null) {
  219.          var2.transform(var1);
  220.       }
  221.  
  222.       return var2;
  223.    }
  224.  
  225.    public Rectangle getBounds() {
  226.       return this.getBounds2D().getBounds();
  227.    }
  228.  
  229.    public synchronized Rectangle2D getBounds2D() {
  230.       int var5 = this.numCoords;
  231.       float var1;
  232.       float var2;
  233.       float var3;
  234.       float var4;
  235.       if (var5 > 0) {
  236.          --var5;
  237.          var2 = var4 = this.pointCoords[var5];
  238.          --var5;
  239.          var1 = var3 = this.pointCoords[var5];
  240.  
  241.          while(var5 > 0) {
  242.             --var5;
  243.             float var6 = this.pointCoords[var5];
  244.             --var5;
  245.             float var7 = this.pointCoords[var5];
  246.             if (var7 < var1) {
  247.                var1 = var7;
  248.             }
  249.  
  250.             if (var6 < var2) {
  251.                var2 = var6;
  252.             }
  253.  
  254.             if (var7 > var3) {
  255.                var3 = var7;
  256.             }
  257.  
  258.             if (var6 > var4) {
  259.                var4 = var6;
  260.             }
  261.          }
  262.       } else {
  263.          var4 = 0.0F;
  264.          var3 = 0.0F;
  265.          var2 = 0.0F;
  266.          var1 = 0.0F;
  267.       }
  268.  
  269.       return new Rectangle2D.Float(var1, var2, var3 - var1, var4 - var2);
  270.    }
  271.  
  272.    public boolean contains(double var1, double var3) {
  273.       if (this.numTypes < 2) {
  274.          return false;
  275.       } else {
  276.          int var5 = Curve.crossingsForPath(this.getPathIterator((AffineTransform)null), var1, var3);
  277.          if (this.windingRule == 1) {
  278.             return var5 != 0;
  279.          } else {
  280.             return (var5 & 1) != 0;
  281.          }
  282.       }
  283.    }
  284.  
  285.    public boolean contains(Point2D var1) {
  286.       return this.contains(var1.getX(), var1.getY());
  287.    }
  288.  
  289.    public boolean contains(double var1, double var3, double var5, double var7) {
  290.       Crossings var9 = Crossings.findCrossings(this.getPathIterator((AffineTransform)null), var1, var3, var1 + var5, var3 + var7);
  291.       return var9 != null && var9.covers(var3, var3 + var7);
  292.    }
  293.  
  294.    public boolean contains(Rectangle2D var1) {
  295.       return this.contains(((RectangularShape)var1).getX(), ((RectangularShape)var1).getY(), ((RectangularShape)var1).getWidth(), ((RectangularShape)var1).getHeight());
  296.    }
  297.  
  298.    public boolean intersects(double var1, double var3, double var5, double var7) {
  299.       Crossings var9 = Crossings.findCrossings(this.getPathIterator((AffineTransform)null), var1, var3, var1 + var5, var3 + var7);
  300.       return var9 == null || !var9.isEmpty();
  301.    }
  302.  
  303.    public boolean intersects(Rectangle2D var1) {
  304.       return this.intersects(((RectangularShape)var1).getX(), ((RectangularShape)var1).getY(), ((RectangularShape)var1).getWidth(), ((RectangularShape)var1).getHeight());
  305.    }
  306.  
  307.    public PathIterator getPathIterator(AffineTransform var1) {
  308.       return new GeneralPathIterator(this, var1);
  309.    }
  310.  
  311.    public PathIterator getPathIterator(AffineTransform var1, double var2) {
  312.       return new FlatteningPathIterator(this.getPathIterator(var1), var2);
  313.    }
  314.  
  315.    public Object clone() {
  316.       try {
  317.          GeneralPath var1 = (GeneralPath)super.clone();
  318.          var1.pointTypes = (byte[])this.pointTypes.clone();
  319.          var1.pointCoords = (float[])this.pointCoords.clone();
  320.          return var1;
  321.       } catch (CloneNotSupportedException var2) {
  322.          throw new InternalError();
  323.       }
  324.    }
  325. }
  326.