Revision e99dd9d6
Added by Leszek Koltunski almost 9 years ago
| src/main/java/org/distorted/library/DistortedCubesGrid.java | ||
|---|---|---|
| 82 | 82 | int frontWalls=0, frontSegments=0, sideWalls=0, sideBends=0, triangleShifts=0, windingShifts=0; | 
| 83 | 83 | int shiftCol = (mCols-1)/2; | 
| 84 | 84 |  | 
| 85 | //boolean seenLand=false; | |
| 86 | //boolean firstBlockIsNE=false; | |
| 87 | 85 | boolean lastBlockIsNE=false; | 
| 88 | 86 | boolean thisBlockIsNE; // the block we are currently looking at is split into | 
| 89 | 87 | // two triangles along the NE-SW line (rather than NW-SE) | 
| 90 |  | |
| 91 | 88 | for(int row=0; row<mRows; row++) | 
| 92 | 89 |          {
 | 
| 93 | 90 | if( mCols>=2 && (mCubes[row][shiftCol]%2 == 1) && (mCubes[row][shiftCol+1]%2 == 1) ) triangleShifts++; | 
| ... | ... | |
| 99 | 96 | thisBlockIsNE = isNE(row,col); | 
| 100 | 97 | if( thisBlockIsNE^lastBlockIsNE ) windingShifts++; | 
| 101 | 98 | lastBlockIsNE = thisBlockIsNE; | 
| 102 | /* | |
| 103 | if( !seenLand ) | |
| 104 |                 {
 | |
| 105 | seenLand=true; | |
| 106 | firstBlockIsNE = thisBlockIsNE; | |
| 107 | } | |
| 108 | */ | |
| 109 | 99 | frontWalls++; | 
| 110 | 100 | if( col==mCols-1 || mCubes[row][col+1]%2 == 0 ) frontSegments++; | 
| 111 | 101 | } | 
| ... | ... | |
| 138 | 128 |  | 
| 139 | 129 | int frontVert = 2*( frontWalls + 2*frontSegments - 1) +2*triangleShifts + windingShifts; | 
| 140 | 130 | int sideVert = 2*( sideWalls + sideBends + edges -1); | 
| 141 | int firstWinding=0; | |
| 142 | //int secondWinding=0; | |
| 143 |  | |
| 144 | if( !frontOnly ) | |
| 145 |         {
 | |
| 146 | if( (frontVert+1)%2==1 ) firstWinding=1; | |
| 147 | //if( (((frontVert+1)+firstWinding+(1+sideVert+1))%2==1)^firstBlockIsNE ) secondWinding=1; | |
| 148 | } | |
| 149 |  | |
| 131 | int firstWinding=( !frontOnly && (frontVert+1)%2==1 ) ? 1:0; | |
| 150 | 132 | int dataL = frontOnly ? frontVert : (frontVert+1) +firstWinding+ (1+sideVert+1) + (1+frontVert); | 
| 151 | 133 |  | 
| 152 |       //android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts);
 | |
| 153 |       //android.util.Log.e("CUBES","Winding1="+firstWinding+" Winding2="+secondWinding);
 | |
| 154 |       //android.util.Log.e("CUBES","frontVert="+frontVert+" sideVert="+sideVert);
 | |
| 155 |       //android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+sideWalls+" sSegments="+edges+" sideBends="+sideBends+" dataLen="+dataL );
 | |
| 134 |       android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts);
 | |
| 135 |       android.util.Log.e("CUBES","Winding1="+firstWinding+" frontVert="+frontVert+" sideVert="+sideVert);
 | |
| 136 |       android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+sideWalls+" sSegments="+edges+" sideBends="+sideBends+" dataLen="+dataL );
 | |
| 156 | 137 |  | 
| 157 | 138 | return dataL<0 ? 0:dataL; | 
| 158 | 139 | } | 
| ... | ... | |
| 184 | 165 | } | 
| 185 | 166 | */ | 
| 186 | 167 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 187 | /* | |
| 168 |  | |
| 188 | 169 | private static String debug(Edge e) | 
| 189 | 170 |      {
 | 
| 190 | 171 | String d = ""; | 
| ... | ... | |
| 201 | 182 |  | 
| 202 | 183 | return d; | 
| 203 | 184 | } | 
| 204 | */ | |
| 185 |  | |
| 205 | 186 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 206 | 187 | // desc is guaranteed to be padded with 0s in the end (DistortedCubes constructor does it) | 
| 207 | 188 |  | 
| ... | ... | |
| 296 | 277 | int initCol, initRow; | 
| 297 | 278 | boolean kicked; | 
| 298 | 279 | Edge e; | 
| 299 |  | |
| 280 |  | |
| 300 | 281 | for(i=0; i<numEdges; i++) | 
| 301 | 282 |        {
 | 
| 302 | 283 | e = mEdges.get(i); | 
| 303 | 284 | initRow= e.row; | 
| 304 | 285 | initCol= e.col; | 
| 305 | 286 |  | 
| 306 |        //android.util.Log.e("CUBES", "checking edge "+debug(e));
 | |
| 287 |        android.util.Log.e("CUBES", "checking edge "+debug(e));
 | |
| 307 | 288 |  | 
| 308 | 289 | if( mCubes[initRow][initCol]%2==0 ) | 
| 309 | 290 |          {
 | 
| ... | ... | |
| 313 | 294 | do | 
| 314 | 295 |            {
 | 
| 315 | 296 | e = getNextEdge(e); | 
| 316 |            //android.util.Log.e("CUBES", " next edge "+debug(e));   
 | |
| 297 |            android.util.Log.e("CUBES", " next edge "+debug(e));
 | |
| 317 | 298 |  | 
| 318 | 299 | switch(e.side) | 
| 319 | 300 |              {
 | 
| ... | ... | |
| 325 | 306 |  | 
| 326 | 307 | if( kicked ) | 
| 327 | 308 |              {
 | 
| 328 |              //android.util.Log.e("CUBES", "kicking out edge!");
 | |
| 309 |              android.util.Log.e("CUBES", "kicking out edge!");
 | |
| 329 | 310 | mEdges.remove(i); | 
| 330 | 311 | i--; | 
| 331 | 312 | numEdges--; | 
| 332 | 313 | } | 
| 333 | 314 | } | 
| 334 |          while( kicked==false && (e.col!=initCol || e.row!=initRow || e.side!=NORTH) );
 | |
| 315 |          while( !kicked && (e.col!=initCol || e.row!=initRow || e.side!=NORTH) );
 | |
| 335 | 316 |  | 
| 336 |          if( kicked==false )
 | |
| 317 |          if( !kicked )
 | |
| 337 | 318 |            {
 | 
| 338 | 319 | mEdges.set(i, new Edge(SOUTH,e.row-1,e.col)); | 
| 339 | 320 | } | 
Also available in: Unified diff
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.