Index: /applications/editors/josm/plugins/terracer/build.xml
===================================================================
--- /applications/editors/josm/plugins/terracer/build.xml	(revision 20083)
+++ /applications/editors/josm/plugins/terracer/build.xml	(revision 20084)
@@ -32,5 +32,5 @@
 
 
-    <property name="commit.message" value="josm terracer plugin: fixed reverse terrace, minor updates" />
+    <property name="commit.message" value="josm terracer plugin: minor bug (Broken test, whether two sements are next to each other for a closed way.)" />
     <property name="plugin.main.version" value="2830" />
 
Index: /applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
===================================================================
--- /applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 20083)
+++ /applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 20084)
@@ -191,8 +191,6 @@
         // create intermediate nodes by interpolating.
         for (int i = 0; i <= nb; ++i) {
-            new_nodes[0][i] = interpolateAlong(interp.a, frontLength * (i)
-                    / (nb));
-            new_nodes[1][i] = interpolateAlong(interp.b, backLength * (i)
-                    / (nb));
+            new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i / nb);
+            new_nodes[1][i] = interpolateAlong(interp.b, backLength * i / nb);
             commands.add(new AddCommand(new_nodes[0][i]));
             commands.add(new AddCommand(new_nodes[1][i]));
@@ -323,8 +321,8 @@
         // than a quadrilateral would have been rejected at an earlier
         // stage.
-        if (Math.abs(side1 - side2) < 2) {
+        if (indexDistance(side1, side2, indexes.length) < 2) {
             side2 = indexes[2];
         }
-        if (Math.abs(side1 - side2) < 2) {
+        if (indexDistance(side1, side2, indexes.length) < 2) {
             side2 = indexes[3];
         }
@@ -366,4 +364,24 @@
 
     /**
+     * returns the distance of two segments of a closed polygon
+     */
+    private int indexDistance(int i1, int i2, int n) {
+        return Math.min(positiveModulus(i1 - i2, n), positiveModulus(i2 - i1, n));
+    }
+    
+    /**
+     * return the modulus in the range [0, n)
+     */
+    private int positiveModulus(int a, int n) {
+        if (n <=0) 
+            throw new IllegalArgumentException();
+        int res = a % n;
+        if (res < 0) {
+            res += n;
+        }
+        return res;
+    }
+    
+    /**
      * Calculate the length of a side (from node i to i+1) in a way. This assumes that
      * the way is closed, but I only ever call it for buildings.
