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

  1. package java.awt.geom;
  2.  
  3. import java.awt.Rectangle;
  4. import java.awt.Shape;
  5. import java.util.Enumeration;
  6. import java.util.Vector;
  7. import sun.awt.geom.AreaOp;
  8. import sun.awt.geom.Crossings;
  9. import sun.awt.geom.Curve;
  10.  
  11. public class Area implements Shape, Cloneable {
  12.    private static Vector EmptyCurves = new Vector();
  13.    private Vector curves;
  14.    private Rectangle2D cachedBounds;
  15.  
  16.    public Area() {
  17.       this.curves = EmptyCurves;
  18.    }
  19.  
  20.    public Area(Shape var1) {
  21.       if (var1 instanceof Area) {
  22.          this.curves = ((Area)var1).curves;
  23.       } else {
  24.          this.curves = new Vector();
  25.          PathIterator var2 = var1.getPathIterator((AffineTransform)null);
  26.          int var3 = var2.getWindingRule();
  27.          double[] var4 = new double[23];
  28.          double var5 = (double)0.0F;
  29.          double var7 = (double)0.0F;
  30.          double var9 = (double)0.0F;
  31.  
  32.          double var11;
  33.          for(var11 = (double)0.0F; !var2.isDone(); var2.next()) {
  34.             switch (var2.currentSegment(var4)) {
  35.                case 0:
  36.                   Curve.insertLine(this.curves, var9, var11, var5, var7);
  37.                   var9 = var5 = var4[0];
  38.                   var11 = var7 = var4[1];
  39.                   Curve.insertMove(this.curves, var5, var7);
  40.                   break;
  41.                case 1:
  42.                   double var19 = var4[0];
  43.                   double var21 = var4[1];
  44.                   Curve.insertLine(this.curves, var9, var11, var19, var21);
  45.                   var9 = var19;
  46.                   var11 = var21;
  47.                   break;
  48.                case 2:
  49.                   double var18 = var4[2];
  50.                   double var20 = var4[3];
  51.                   Curve.insertQuad(this.curves, var9, var11, var4);
  52.                   var9 = var18;
  53.                   var11 = var20;
  54.                   break;
  55.                case 3:
  56.                   double var13 = var4[4];
  57.                   double var15 = var4[5];
  58.                   Curve.insertCubic(this.curves, var9, var11, var4);
  59.                   var9 = var13;
  60.                   var11 = var15;
  61.                   break;
  62.                case 4:
  63.                   Curve.insertLine(this.curves, var9, var11, var5, var7);
  64.                   var9 = var5;
  65.                   var11 = var7;
  66.             }
  67.          }
  68.  
  69.          Curve.insertLine(this.curves, var9, var11, var5, var7);
  70.          Object var17;
  71.          if (var3 == 0) {
  72.             var17 = new AreaOp.EOWindOp();
  73.          } else {
  74.             var17 = new AreaOp.NZWindOp();
  75.          }
  76.  
  77.          this.curves = ((AreaOp)var17).calculate(this.curves, EmptyCurves);
  78.       }
  79.    }
  80.  
  81.    public void add(Area var1) {
  82.       this.curves = (new AreaOp.AddOp()).calculate(this.curves, var1.curves);
  83.       this.invalidateBounds();
  84.    }
  85.  
  86.    public void subtract(Area var1) {
  87.       this.curves = (new AreaOp.SubOp()).calculate(this.curves, var1.curves);
  88.       this.invalidateBounds();
  89.    }
  90.  
  91.    public void intersect(Area var1) {
  92.       this.curves = (new AreaOp.IntOp()).calculate(this.curves, var1.curves);
  93.       this.invalidateBounds();
  94.    }
  95.  
  96.    public void exclusiveOr(Area var1) {
  97.       this.curves = (new AreaOp.XorOp()).calculate(this.curves, var1.curves);
  98.       this.invalidateBounds();
  99.    }
  100.  
  101.    public void reset() {
  102.       this.curves = new Vector();
  103.       this.invalidateBounds();
  104.    }
  105.  
  106.    public boolean isEmpty() {
  107.       return this.curves.size() == 0;
  108.    }
  109.  
  110.    public boolean isPolygonal() {
  111.       Enumeration var1 = this.curves.elements();
  112.  
  113.       while(var1.hasMoreElements()) {
  114.          if (((Curve)var1.nextElement()).getOrder() > 1) {
  115.             return false;
  116.          }
  117.       }
  118.  
  119.       return true;
  120.    }
  121.  
  122.    public boolean isRectangular() {
  123.       int var1 = this.curves.size();
  124.       if (var1 == 0) {
  125.          return true;
  126.       } else if (var1 > 3) {
  127.          return false;
  128.       } else {
  129.          Curve var2 = (Curve)this.curves.get(1);
  130.          Curve var3 = (Curve)this.curves.get(2);
  131.          if (var2.getOrder() == 1 && var3.getOrder() == 1) {
  132.             if (var2.getXTop() == var2.getXBot() && var3.getXTop() == var3.getXBot()) {
  133.                return var2.getYTop() == var3.getYTop() && var2.getYBot() == var3.getYBot();
  134.             } else {
  135.                return false;
  136.             }
  137.          } else {
  138.             return false;
  139.          }
  140.       }
  141.    }
  142.  
  143.    public boolean isSingular() {
  144.       if (this.curves.size() < 3) {
  145.          return true;
  146.       } else {
  147.          Enumeration var1 = this.curves.elements();
  148.          var1.nextElement();
  149.  
  150.          while(var1.hasMoreElements()) {
  151.             if (((Curve)var1.nextElement()).getOrder() == 0) {
  152.                return false;
  153.             }
  154.          }
  155.  
  156.          return true;
  157.       }
  158.    }
  159.  
  160.    private void invalidateBounds() {
  161.       this.cachedBounds = null;
  162.    }
  163.  
  164.    private Rectangle2D getCachedBounds() {
  165.       if (this.cachedBounds != null) {
  166.          return this.cachedBounds;
  167.       } else {
  168.          Rectangle2D.Double var1 = new Rectangle2D.Double();
  169.          if (this.curves.size() > 0) {
  170.             Curve var2 = (Curve)this.curves.get(0);
  171.             ((Rectangle2D)var1).setRect(var2.getX0(), var2.getY0(), (double)0.0F, (double)0.0F);
  172.  
  173.             for(int var3 = 1; var3 < this.curves.size(); ++var3) {
  174.                ((Curve)this.curves.get(var3)).enlarge(var1);
  175.             }
  176.          }
  177.  
  178.          return this.cachedBounds = var1;
  179.       }
  180.    }
  181.  
  182.    public Rectangle2D getBounds2D() {
  183.       return this.getCachedBounds().getBounds2D();
  184.    }
  185.  
  186.    public Rectangle getBounds() {
  187.       return this.getCachedBounds().getBounds();
  188.    }
  189.  
  190.    public Object clone() {
  191.       return new Area(this);
  192.    }
  193.  
  194.    public boolean equals(Area var1) {
  195.       if (var1 == this) {
  196.          return true;
  197.       } else if (var1 == null) {
  198.          return false;
  199.       } else {
  200.          Vector var2 = (new AreaOp.XorOp()).calculate(this.curves, var1.curves);
  201.          return var2.isEmpty();
  202.       }
  203.    }
  204.  
  205.    public void transform(AffineTransform var1) {
  206.       this.curves = (new Area(var1.createTransformedShape(this))).curves;
  207.       this.invalidateBounds();
  208.    }
  209.  
  210.    public Area createTransformedArea(AffineTransform var1) {
  211.       return new Area(var1.createTransformedShape(this));
  212.    }
  213.  
  214.    public boolean contains(double var1, double var3) {
  215.       if (!this.getCachedBounds().contains(var1, var3)) {
  216.          return false;
  217.       } else {
  218.          Enumeration var5 = this.curves.elements();
  219.  
  220.          int var6;
  221.          Curve var7;
  222.          for(var6 = 0; var5.hasMoreElements(); var6 += var7.crossingsFor(var1, var3)) {
  223.             var7 = (Curve)var5.nextElement();
  224.          }
  225.  
  226.          return (var6 & 1) == 1;
  227.       }
  228.    }
  229.  
  230.    public boolean contains(Point2D var1) {
  231.       return this.contains(var1.getX(), var1.getY());
  232.    }
  233.  
  234.    public boolean contains(double var1, double var3, double var5, double var7) {
  235.       if (!(var5 < (double)0.0F) && !(var7 < (double)0.0F)) {
  236.          if (!this.getCachedBounds().contains(var1, var3, var5, var7)) {
  237.             return false;
  238.          } else {
  239.             Crossings var9 = Crossings.findCrossings(this.curves, var1, var3, var1 + var5, var3 + var7);
  240.             return var9 != null && var9.covers(var3, var3 + var7);
  241.          }
  242.       } else {
  243.          return false;
  244.       }
  245.    }
  246.  
  247.    public boolean contains(Rectangle2D var1) {
  248.       return this.contains(((RectangularShape)var1).getX(), ((RectangularShape)var1).getY(), ((RectangularShape)var1).getWidth(), ((RectangularShape)var1).getHeight());
  249.    }
  250.  
  251.    public boolean intersects(double var1, double var3, double var5, double var7) {
  252.       if (!(var5 < (double)0.0F) && !(var7 < (double)0.0F)) {
  253.          if (!this.getCachedBounds().intersects(var1, var3, var5, var7)) {
  254.             return false;
  255.          } else {
  256.             Crossings var9 = Crossings.findCrossings(this.curves, var1, var3, var1 + var5, var3 + var7);
  257.             return var9 == null || !var9.isEmpty();
  258.          }
  259.       } else {
  260.          return false;
  261.       }
  262.    }
  263.  
  264.    public boolean intersects(Rectangle2D var1) {
  265.       return this.intersects(((RectangularShape)var1).getX(), ((RectangularShape)var1).getY(), ((RectangularShape)var1).getWidth(), ((RectangularShape)var1).getHeight());
  266.    }
  267.  
  268.    public PathIterator getPathIterator(AffineTransform var1) {
  269.       return new AreaIterator(this.curves, var1);
  270.    }
  271.  
  272.    public PathIterator getPathIterator(AffineTransform var1, double var2) {
  273.       return new FlatteningPathIterator(this.getPathIterator(var1), var2);
  274.    }
  275. }
  276.