home *** CD-ROM | disk | FTP | other *** search
- package java.awt.geom;
-
- import java.awt.Rectangle;
- import java.awt.Shape;
- import java.util.Enumeration;
- import java.util.Vector;
- import sun.awt.geom.AreaOp;
- import sun.awt.geom.Crossings;
- import sun.awt.geom.Curve;
-
- public class Area implements Shape, Cloneable {
- private static Vector EmptyCurves = new Vector();
- private Vector curves;
- private Rectangle2D cachedBounds;
-
- public Area() {
- this.curves = EmptyCurves;
- }
-
- public Area(Shape var1) {
- if (var1 instanceof Area) {
- this.curves = ((Area)var1).curves;
- } else {
- this.curves = new Vector();
- PathIterator var2 = var1.getPathIterator((AffineTransform)null);
- int var3 = var2.getWindingRule();
- double[] var4 = new double[23];
- double var5 = (double)0.0F;
- double var7 = (double)0.0F;
- double var9 = (double)0.0F;
-
- double var11;
- for(var11 = (double)0.0F; !var2.isDone(); var2.next()) {
- switch (var2.currentSegment(var4)) {
- case 0:
- Curve.insertLine(this.curves, var9, var11, var5, var7);
- var9 = var5 = var4[0];
- var11 = var7 = var4[1];
- Curve.insertMove(this.curves, var5, var7);
- break;
- case 1:
- double var19 = var4[0];
- double var21 = var4[1];
- Curve.insertLine(this.curves, var9, var11, var19, var21);
- var9 = var19;
- var11 = var21;
- break;
- case 2:
- double var18 = var4[2];
- double var20 = var4[3];
- Curve.insertQuad(this.curves, var9, var11, var4);
- var9 = var18;
- var11 = var20;
- break;
- case 3:
- double var13 = var4[4];
- double var15 = var4[5];
- Curve.insertCubic(this.curves, var9, var11, var4);
- var9 = var13;
- var11 = var15;
- break;
- case 4:
- Curve.insertLine(this.curves, var9, var11, var5, var7);
- var9 = var5;
- var11 = var7;
- }
- }
-
- Curve.insertLine(this.curves, var9, var11, var5, var7);
- Object var17;
- if (var3 == 0) {
- var17 = new AreaOp.EOWindOp();
- } else {
- var17 = new AreaOp.NZWindOp();
- }
-
- this.curves = ((AreaOp)var17).calculate(this.curves, EmptyCurves);
- }
- }
-
- public void add(Area var1) {
- this.curves = (new AreaOp.AddOp()).calculate(this.curves, var1.curves);
- this.invalidateBounds();
- }
-
- public void subtract(Area var1) {
- this.curves = (new AreaOp.SubOp()).calculate(this.curves, var1.curves);
- this.invalidateBounds();
- }
-
- public void intersect(Area var1) {
- this.curves = (new AreaOp.IntOp()).calculate(this.curves, var1.curves);
- this.invalidateBounds();
- }
-
- public void exclusiveOr(Area var1) {
- this.curves = (new AreaOp.XorOp()).calculate(this.curves, var1.curves);
- this.invalidateBounds();
- }
-
- public void reset() {
- this.curves = new Vector();
- this.invalidateBounds();
- }
-
- public boolean isEmpty() {
- return this.curves.size() == 0;
- }
-
- public boolean isPolygonal() {
- Enumeration var1 = this.curves.elements();
-
- while(var1.hasMoreElements()) {
- if (((Curve)var1.nextElement()).getOrder() > 1) {
- return false;
- }
- }
-
- return true;
- }
-
- public boolean isRectangular() {
- int var1 = this.curves.size();
- if (var1 == 0) {
- return true;
- } else if (var1 > 3) {
- return false;
- } else {
- Curve var2 = (Curve)this.curves.get(1);
- Curve var3 = (Curve)this.curves.get(2);
- if (var2.getOrder() == 1 && var3.getOrder() == 1) {
- if (var2.getXTop() == var2.getXBot() && var3.getXTop() == var3.getXBot()) {
- return var2.getYTop() == var3.getYTop() && var2.getYBot() == var3.getYBot();
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- }
-
- public boolean isSingular() {
- if (this.curves.size() < 3) {
- return true;
- } else {
- Enumeration var1 = this.curves.elements();
- var1.nextElement();
-
- while(var1.hasMoreElements()) {
- if (((Curve)var1.nextElement()).getOrder() == 0) {
- return false;
- }
- }
-
- return true;
- }
- }
-
- private void invalidateBounds() {
- this.cachedBounds = null;
- }
-
- private Rectangle2D getCachedBounds() {
- if (this.cachedBounds != null) {
- return this.cachedBounds;
- } else {
- Rectangle2D.Double var1 = new Rectangle2D.Double();
- if (this.curves.size() > 0) {
- Curve var2 = (Curve)this.curves.get(0);
- ((Rectangle2D)var1).setRect(var2.getX0(), var2.getY0(), (double)0.0F, (double)0.0F);
-
- for(int var3 = 1; var3 < this.curves.size(); ++var3) {
- ((Curve)this.curves.get(var3)).enlarge(var1);
- }
- }
-
- return this.cachedBounds = var1;
- }
- }
-
- public Rectangle2D getBounds2D() {
- return this.getCachedBounds().getBounds2D();
- }
-
- public Rectangle getBounds() {
- return this.getCachedBounds().getBounds();
- }
-
- public Object clone() {
- return new Area(this);
- }
-
- public boolean equals(Area var1) {
- if (var1 == this) {
- return true;
- } else if (var1 == null) {
- return false;
- } else {
- Vector var2 = (new AreaOp.XorOp()).calculate(this.curves, var1.curves);
- return var2.isEmpty();
- }
- }
-
- public void transform(AffineTransform var1) {
- this.curves = (new Area(var1.createTransformedShape(this))).curves;
- this.invalidateBounds();
- }
-
- public Area createTransformedArea(AffineTransform var1) {
- return new Area(var1.createTransformedShape(this));
- }
-
- public boolean contains(double var1, double var3) {
- if (!this.getCachedBounds().contains(var1, var3)) {
- return false;
- } else {
- Enumeration var5 = this.curves.elements();
-
- int var6;
- Curve var7;
- for(var6 = 0; var5.hasMoreElements(); var6 += var7.crossingsFor(var1, var3)) {
- var7 = (Curve)var5.nextElement();
- }
-
- return (var6 & 1) == 1;
- }
- }
-
- public boolean contains(Point2D var1) {
- return this.contains(var1.getX(), var1.getY());
- }
-
- public boolean contains(double var1, double var3, double var5, double var7) {
- if (!(var5 < (double)0.0F) && !(var7 < (double)0.0F)) {
- if (!this.getCachedBounds().contains(var1, var3, var5, var7)) {
- return false;
- } else {
- Crossings var9 = Crossings.findCrossings(this.curves, var1, var3, var1 + var5, var3 + var7);
- return var9 != null && var9.covers(var3, var3 + var7);
- }
- } else {
- return false;
- }
- }
-
- public boolean contains(Rectangle2D var1) {
- return this.contains(((RectangularShape)var1).getX(), ((RectangularShape)var1).getY(), ((RectangularShape)var1).getWidth(), ((RectangularShape)var1).getHeight());
- }
-
- public boolean intersects(double var1, double var3, double var5, double var7) {
- if (!(var5 < (double)0.0F) && !(var7 < (double)0.0F)) {
- if (!this.getCachedBounds().intersects(var1, var3, var5, var7)) {
- return false;
- } else {
- Crossings var9 = Crossings.findCrossings(this.curves, var1, var3, var1 + var5, var3 + var7);
- return var9 == null || !var9.isEmpty();
- }
- } else {
- return false;
- }
- }
-
- public boolean intersects(Rectangle2D var1) {
- return this.intersects(((RectangularShape)var1).getX(), ((RectangularShape)var1).getY(), ((RectangularShape)var1).getWidth(), ((RectangularShape)var1).getHeight());
- }
-
- public PathIterator getPathIterator(AffineTransform var1) {
- return new AreaIterator(this.curves, var1);
- }
-
- public PathIterator getPathIterator(AffineTransform var1, double var2) {
- return new FlatteningPathIterator(this.getPathIterator(var1), var2);
- }
- }
-