home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / java / awt / Polygon.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-27  |  1.9 KB  |  108 lines

  1. package java.awt;
  2.  
  3. public class Polygon {
  4.    public int npoints;
  5.    public int[] xpoints = new int[4];
  6.    public int[] ypoints = new int[4];
  7.    Rectangle bounds;
  8.  
  9.    public Polygon() {
  10.    }
  11.  
  12.    public Polygon(int[] var1, int[] var2, int var3) {
  13.       this.npoints = var3;
  14.       this.xpoints = new int[var3];
  15.       this.ypoints = new int[var3];
  16.       System.arraycopy(var1, 0, this.xpoints, 0, var3);
  17.       System.arraycopy(var2, 0, this.ypoints, 0, var3);
  18.    }
  19.  
  20.    void calculateBounds(int[] var1, int[] var2, int var3) {
  21.       int var4 = Integer.MAX_VALUE;
  22.       int var5 = Integer.MAX_VALUE;
  23.       int var6 = Integer.MIN_VALUE;
  24.       int var7 = Integer.MIN_VALUE;
  25.  
  26.       for(int var8 = 0; var8 < var3; ++var8) {
  27.          int var9 = var1[var8];
  28.          var4 = Math.min(var4, var9);
  29.          var6 = Math.max(var6, var9);
  30.          int var10 = var2[var8];
  31.          var5 = Math.min(var5, var10);
  32.          var7 = Math.max(var7, var10);
  33.       }
  34.  
  35.       this.bounds = new Rectangle(var4, var5, var6 - var4, var7 - var5);
  36.    }
  37.  
  38.    void updateBounds(int var1, int var2) {
  39.       this.bounds.x = Math.min(this.bounds.x, var1);
  40.       this.bounds.width = Math.max(this.bounds.width, var1 - this.bounds.x);
  41.       this.bounds.y = Math.min(this.bounds.y, var2);
  42.       this.bounds.height = Math.max(this.bounds.height, var2 - this.bounds.y);
  43.    }
  44.  
  45.    public void addPoint(int var1, int var2) {
  46.       if (this.npoints == this.xpoints.length) {
  47.          int[] var3 = new int[this.npoints * 2];
  48.          System.arraycopy(this.xpoints, 0, var3, 0, this.npoints);
  49.          this.xpoints = var3;
  50.          var3 = new int[this.npoints * 2];
  51.          System.arraycopy(this.ypoints, 0, var3, 0, this.npoints);
  52.          this.ypoints = var3;
  53.       }
  54.  
  55.       this.xpoints[this.npoints] = var1;
  56.       this.ypoints[this.npoints] = var2;
  57.       ++this.npoints;
  58.       if (this.bounds != null) {
  59.          this.updateBounds(var1, var2);
  60.       }
  61.  
  62.    }
  63.  
  64.    public Rectangle getBoundingBox() {
  65.       if (this.bounds == null) {
  66.          this.calculateBounds(this.xpoints, this.ypoints, this.npoints);
  67.       }
  68.  
  69.       return this.bounds;
  70.    }
  71.  
  72.    public boolean inside(int var1, int var2) {
  73.       if (this.getBoundingBox().inside(var1, var2)) {
  74.          int var3 = 0;
  75.  
  76.          for(int var4 = 0; var4 < this.npoints; ++var4) {
  77.             int var5 = (var4 + 1) % this.npoints;
  78.             int var6 = this.xpoints[var5] - this.xpoints[var4];
  79.             int var7 = this.ypoints[var5] - this.ypoints[var4];
  80.             if (var7 != 0) {
  81.                int var8 = var1 - this.xpoints[var4];
  82.                int var9 = var2 - this.ypoints[var4];
  83.                if (this.ypoints[var4] == var2) {
  84.                   --var9;
  85.                }
  86.  
  87.                if (this.ypoints[var5] == var2) {
  88.                   ++var7;
  89.                }
  90.  
  91.                float var10 = (float)var9 / (float)var7;
  92.                if ((double)var10 >= (double)0.0F && (double)var10 <= (double)1.0F && (int)(var10 * (float)var6) > var8) {
  93.                   ++var3;
  94.                }
  95.             }
  96.          }
  97.  
  98.          if (var3 % 2 == 0) {
  99.             return false;
  100.          } else {
  101.             return true;
  102.          }
  103.       } else {
  104.          return false;
  105.       }
  106.    }
  107. }
  108.