--- Area.java	Mon Mar  5 14:00:31 2012
+++ Area_new.java	Mon Mar  5 14:02:38 2012
@@ -27,6 +27,7 @@

 import java.awt.Shape;
 import java.awt.Rectangle;
+import java.util.Iterator;
 import java.util.Vector;
 import java.util.Enumeration;
 import java.util.NoSuchElementException;
@@ -658,16 +659,15 @@

 class AreaIterator implements PathIterator {
     private AffineTransform transform;
-    private Vector curves;
-    private int index;
+    private final Iterator it;
     private Curve prevcurve;
     private Curve thiscurve;

     public AreaIterator(Vector curves, AffineTransform at) {
-        this.curves = curves;
+        this.it = curves.iterator();
         this.transform = at;
-        if (curves.size() >= 1) {
-            thiscurve = (Curve) curves.get(0);
+        if (it.hasNext()) {
+            thiscurve = (Curve) it.next();
         }
     }

@@ -682,23 +682,31 @@
         return (prevcurve == null && thiscurve == null);
     }

+    private static boolean isClose(final double a, final double b) {
+        return a == b || Math.abs(a - b) < 1e-7;
+    }
+
+    private static boolean isOverlap(final Curve a, final Curve b) {
+        return isClose(a.getX1(), b.getX0()) && isClose(a.getY1(), b.getY0());
+    }
+
     public void next() {
         if (prevcurve != null) {
             prevcurve = null;
         } else {
             prevcurve = thiscurve;
-            index++;
-            if (index < curves.size()) {
-                thiscurve = (Curve) curves.get(index);
-                if (thiscurve.getOrder() != 0 &&
-                    prevcurve.getX1() == thiscurve.getX0() &&
-                    prevcurve.getY1() == thiscurve.getY0())
-                {
-                    prevcurve = null;
+            while (it.hasNext()) {
+                thiscurve = (Curve) it.next();
+                if (thiscurve.getOrder() == 0) {
+                    return;
+                } else if (!isOverlap(thiscurve, thiscurve)) {
+                    if (isOverlap(prevcurve, thiscurve)) {
+                        prevcurve = null;
+                    }
+                    return;
                 }
-            } else {
-                thiscurve = null;
             }
+            thiscurve = null;
         }
     }

