commit e99dd9d6b277ba209533791608d9ecf662c232cf
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Fri Dec 9 15:50:50 2016 +0000

    Chasing a bug in DistortedCubesGrid.markRegions()   ( visible with a 5x5 grid, 11111 11011 10101 11011 11111 ) - some side edges are missing. markRegions computes incorrect number of side Segments in this case.

diff --git a/src/main/java/org/distorted/library/DistortedCubesGrid.java b/src/main/java/org/distorted/library/DistortedCubesGrid.java
index 6df2e6f..6b132a4 100644
--- a/src/main/java/org/distorted/library/DistortedCubesGrid.java
+++ b/src/main/java/org/distorted/library/DistortedCubesGrid.java
@@ -82,12 +82,9 @@ class DistortedCubesGrid extends DistortedObjectGrid
       int frontWalls=0, frontSegments=0, sideWalls=0, sideBends=0, triangleShifts=0, windingShifts=0;
       int shiftCol = (mCols-1)/2;
 
-      //boolean seenLand=false;
-      //boolean firstBlockIsNE=false;
       boolean lastBlockIsNE=false;
       boolean thisBlockIsNE;        // the block we are currently looking at is split into
                                     // two triangles along the NE-SW line (rather than NW-SE)
-
       for(int row=0; row<mRows; row++)
          {
          if( mCols>=2 && (mCubes[row][shiftCol]%2 == 1) && (mCubes[row][shiftCol+1]%2 == 1) ) triangleShifts++;
@@ -99,13 +96,6 @@ class DistortedCubesGrid extends DistortedObjectGrid
               thisBlockIsNE = isNE(row,col);
               if( thisBlockIsNE^lastBlockIsNE ) windingShifts++;
               lastBlockIsNE = thisBlockIsNE;
-/*
-              if( !seenLand )
-                {
-                seenLand=true;
-                firstBlockIsNE = thisBlockIsNE;
-                }
-*/
               frontWalls++;
               if( col==mCols-1 || mCubes[row][col+1]%2 == 0 ) frontSegments++;
               }
@@ -138,21 +128,12 @@ class DistortedCubesGrid extends DistortedObjectGrid
 
       int frontVert = 2*( frontWalls + 2*frontSegments - 1) +2*triangleShifts + windingShifts;
       int sideVert  = 2*( sideWalls + sideBends + edges -1);
-      int firstWinding=0;
-      //int secondWinding=0;
-
-      if( !frontOnly )
-        {
-        if( (frontVert+1)%2==1 ) firstWinding=1;
-        //if( (((frontVert+1)+firstWinding+(1+sideVert+1))%2==1)^firstBlockIsNE ) secondWinding=1;
-        }
-
+      int firstWinding=( !frontOnly && (frontVert+1)%2==1 ) ? 1:0;
       int dataL = frontOnly ? frontVert : (frontVert+1) +firstWinding+ (1+sideVert+1) + (1+frontVert);
 
-      //android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts);
-      //android.util.Log.e("CUBES","Winding1="+firstWinding+" Winding2="+secondWinding);
-      //android.util.Log.e("CUBES","frontVert="+frontVert+" sideVert="+sideVert);
-      //android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+sideWalls+" sSegments="+edges+" sideBends="+sideBends+" dataLen="+dataL );
+      android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts);
+      android.util.Log.e("CUBES","Winding1="+firstWinding+" frontVert="+frontVert+" sideVert="+sideVert);
+      android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+sideWalls+" sSegments="+edges+" sideBends="+sideBends+" dataLen="+dataL );
       
       return dataL<0 ? 0:dataL;
       }
@@ -184,7 +165,7 @@ class DistortedCubesGrid extends DistortedObjectGrid
      }
 */  
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-/*
+
    private static String debug(Edge e)
      {
      String d = "";
@@ -201,7 +182,7 @@ class DistortedCubesGrid extends DistortedObjectGrid
      
      return d;
      }   
-*/ 
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // desc is guaranteed to be padded with 0s in the end (DistortedCubes constructor does it)
 
@@ -296,14 +277,14 @@ class DistortedCubesGrid extends DistortedObjectGrid
      int initCol, initRow;
      boolean kicked;
      Edge e;
-     
+
      for(i=0; i<numEdges; i++) 
        {
        e = mEdges.get(i);
        initRow= e.row;
        initCol= e.col;
          
-       //android.util.Log.e("CUBES", "checking edge "+debug(e));
+       android.util.Log.e("CUBES", "checking edge "+debug(e));
              
        if( mCubes[initRow][initCol]%2==0 )
          {
@@ -313,7 +294,7 @@ class DistortedCubesGrid extends DistortedObjectGrid
          do
            {
            e = getNextEdge(e); 
-           //android.util.Log.e("CUBES", " next edge "+debug(e));   
+           android.util.Log.e("CUBES", " next edge "+debug(e));
        
            switch(e.side)
              {
@@ -325,15 +306,15 @@ class DistortedCubesGrid extends DistortedObjectGrid
            
            if( kicked )
              {
-             //android.util.Log.e("CUBES", "kicking out edge!");
+             android.util.Log.e("CUBES", "kicking out edge!");
              mEdges.remove(i);
              i--;
              numEdges--; 
              }
            }
-         while( kicked==false && (e.col!=initCol || e.row!=initRow || e.side!=NORTH) );
+         while( !kicked && (e.col!=initCol || e.row!=initRow || e.side!=NORTH) );
          
-         if( kicked==false )
+         if( !kicked )
            {
            mEdges.set(i, new Edge(SOUTH,e.row-1,e.col)); 
            }
