home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 31 / SUPERCDa.iso / Inet / HotJava / hjava.exe / Windows / resource / jre / lib / rt.jar / java / awt / Polygon.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-11  |  2.5 KB  |  155 lines

  1. package java.awt;
  2.  
  3. import java.io.Serializable;
  4.  
  5. public class Polygon implements Shape, Serializable {
  6.    public int npoints;
  7.    public int[] xpoints = new int[4];
  8.    public int[] ypoints = new int[4];
  9.    protected Rectangle bounds;
  10.    private static final long serialVersionUID = -6460061437900069969L;
  11.  
  12.    public Polygon() {
  13.    }
  14.  
  15.    public Polygon(int[] var1, int[] var2, int var3) {
  16.       this.npoints = var3;
  17.       this.xpoints = new int[var3];
  18.       this.ypoints = new int[var3];
  19.       System.arraycopy(var1, 0, this.xpoints, 0, var3);
  20.       System.arraycopy(var2, 0, this.ypoints, 0, var3);
  21.    }
  22.  
  23.    public void translate(int var1, int var2) {
  24.       for(int var3 = 0; var3 < this.npoints; ++var3) {
  25.          int[] var10000 = this.xpoints;
  26.          var10000[var3] += var1;
  27.          var10000 = this.ypoints;
  28.          var10000[var3] += var2;
  29.       }
  30.  
  31.       if (this.bounds != null) {
  32.          this.bounds.translate(var1, var2);
  33.       }
  34.  
  35.    }
  36.  
  37.    void calculateBounds(int[] var1, int[] var2, int var3) {
  38.       int var4 = Integer.MAX_VALUE;
  39.       int var5 = Integer.MAX_VALUE;
  40.       int var6 = Integer.MIN_VALUE;
  41.       int var7 = Integer.MIN_VALUE;
  42.  
  43.       for(int var8 = 0; var8 < var3; ++var8) {
  44.          int var9 = var1[var8];
  45.          var4 = Math.min(var4, var9);
  46.          var6 = Math.max(var6, var9);
  47.          int var10 = var2[var8];
  48.          var5 = Math.min(var5, var10);
  49.          var7 = Math.max(var7, var10);
  50.       }
  51.  
  52.       this.bounds = new Rectangle(var4, var5, var6 - var4, var7 - var5);
  53.    }
  54.  
  55.    void updateBounds(int var1, int var2) {
  56.       if (var1 < this.bounds.x) {
  57.          this.bounds.width += this.bounds.x - var1;
  58.          this.bounds.x = var1;
  59.       } else {
  60.          this.bounds.width = Math.max(this.bounds.width, var1 - this.bounds.x);
  61.       }
  62.  
  63.       if (var2 < this.bounds.y) {
  64.          this.bounds.height += this.bounds.y - var2;
  65.          this.bounds.y = var2;
  66.       } else {
  67.          this.bounds.height = Math.max(this.bounds.height, var2 - this.bounds.y);
  68.       }
  69.    }
  70.  
  71.    public void addPoint(int var1, int var2) {
  72.       if (this.npoints == this.xpoints.length) {
  73.          int[] var3 = new int[this.npoints * 2];
  74.          System.arraycopy(this.xpoints, 0, var3, 0, this.npoints);
  75.          this.xpoints = var3;
  76.          var3 = new int[this.npoints * 2];
  77.          System.arraycopy(this.ypoints, 0, var3, 0, this.npoints);
  78.          this.ypoints = var3;
  79.       }
  80.  
  81.       this.xpoints[this.npoints] = var1;
  82.       this.ypoints[this.npoints] = var2;
  83.       ++this.npoints;
  84.       if (this.bounds != null) {
  85.          this.updateBounds(var1, var2);
  86.       }
  87.  
  88.    }
  89.  
  90.    public Rectangle getBounds() {
  91.       return this.getBoundingBox();
  92.    }
  93.  
  94.    /** @deprecated */
  95.    public Rectangle getBoundingBox() {
  96.       if (this.bounds == null) {
  97.          this.calculateBounds(this.xpoints, this.ypoints, this.npoints);
  98.       }
  99.  
  100.       return this.bounds;
  101.    }
  102.  
  103.    public boolean contains(Point var1) {
  104.       return this.contains(var1.x, var1.y);
  105.    }
  106.  
  107.    public boolean contains(int var1, int var2) {
  108.       return this.inside(var1, var2);
  109.    }
  110.  
  111.    /** @deprecated */
  112.    public boolean inside(int var1, int var2) {
  113.       if (!this.getBoundingBox().inside(var1, var2)) {
  114.          return false;
  115.       } else {
  116.          int var3 = 0;
  117.          int var4 = 0;
  118.  
  119.          int var5;
  120.          for(var5 = 0; var5 < this.npoints && this.ypoints[var5] == var2; ++var5) {
  121.          }
  122.  
  123.          for(int var6 = 0; var6 < this.npoints; ++var6) {
  124.             int var7 = (var5 + 1) % this.npoints;
  125.             int var8 = this.xpoints[var7] - this.xpoints[var5];
  126.             int var9 = this.ypoints[var7] - this.ypoints[var5];
  127.             if (var9 != 0) {
  128.                int var10 = var1 - this.xpoints[var5];
  129.                int var11 = var2 - this.ypoints[var5];
  130.                if (this.ypoints[var7] == var2 && this.xpoints[var7] >= var1) {
  131.                   var4 = this.ypoints[var5];
  132.                }
  133.  
  134.                if (this.ypoints[var5] == var2 && this.xpoints[var5] >= var1 && var4 > var2 != this.ypoints[var7] > var2) {
  135.                   --var3;
  136.                }
  137.  
  138.                float var12 = (float)var11 / (float)var9;
  139.                if ((double)var12 >= (double)0.0F && (double)var12 <= (double)1.0F && var12 * (float)var8 >= (float)var10) {
  140.                   ++var3;
  141.                }
  142.             }
  143.  
  144.             var5 = var7;
  145.          }
  146.  
  147.          if (var3 % 2 == 0) {
  148.             return false;
  149.          } else {
  150.             return true;
  151.          }
  152.       }
  153.    }
  154. }
  155.