Project

General

Profile

« Previous | Next » 

Revision 29dd01c6

Added by Leszek Koltunski almost 8 years ago

Further simplify and speed up the DistortedCubes target.

View differences:

src/main/java/org/distorted/library/DistortedCubesGrid.java
76 76

  
77 77
   private boolean isNE(int row,int col)
78 78
     {
79
     return ( (row<=(mRows-1)/2)^(col<=(mCols-1)/2) );
79
     return ( (2*row<mRows)^(2*col<mCols) );
80 80
     }
81 81

  
82 82
///////////////////////////////////////////////////////////////////////////////////////////////////
......
93 93
      boolean thisBlockIsNE;        // the block we are currently looking at is split into
94 94
                                    // two triangles along the NE-SW line (rather than NW-SE)
95 95

  
96
      for(int i=0; i<mRows; i++)
96
      for(int row=0; row<mRows; row++)
97 97
         {
98
         if( mCols>=2 && (mCubes[i][shiftCol]%2 == 1) && (mCubes[i][shiftCol+1]%2 == 1) ) triangleShifts++;
98
         if( mCols>=2 && (mCubes[row][shiftCol]%2 == 1) && (mCubes[row][shiftCol+1]%2 == 1) ) triangleShifts++;
99 99

  
100
         for(int j=0; j<mCols; j++)
100
         for(int col=0; col<mCols; col++)
101 101
            {
102
            if( mCubes[i][j]%2 == 1 )  // land
102
            if( mCubes[row][col]%2 == 1 )  // land
103 103
              {
104
              thisBlockIsNE = isNE(i,j);
104
              thisBlockIsNE = isNE(row,col);
105 105
              if( thisBlockIsNE^lastBlockIsNE ) windingShifts++;
106 106
              lastBlockIsNE = thisBlockIsNE;
107 107
/*
......
112 112
                }
113 113
*/
114 114
              frontWalls++;
115
              if( j==mCols-1 || mCubes[i][j+1]%2 == 0 ) frontSegments++;
115
              if( col==mCols-1 || mCubes[row][col+1]%2 == 0 ) frontSegments++;
116 116
              }
117 117
              
118
            if( (i==0 && mCubes[i][j]!=2) || (i!=0 && mCubes[i][j] != mCubes[i-1][j  ]) ) sideWalls++; // up
119
            if( (j==0 && mCubes[i][j]!=2) || (j!=0 && mCubes[i][j] != mCubes[i  ][j-1]) ) sideWalls++; // left
120
            if( i==mRows-1 && mCubes[i][j]!=2                                           ) sideWalls++; // bottom
121
            if( j==mCols-1 && mCubes[i][j]!=2                                           ) sideWalls++; // right
118
            if( (row==0 && mCubes[row][col]!=2) || (row!=0 && mCubes[row][col] != mCubes[row-1][col  ]) ) sideWalls++; // up
119
            if( (col==0 && mCubes[row][col]!=2) || (col!=0 && mCubes[row][col] != mCubes[row  ][col-1]) ) sideWalls++; // left
120
            if( row==mRows-1 && mCubes[row][col]!=2                                                     ) sideWalls++; // bottom
121
            if( col==mCols-1 && mCubes[row][col]!=2                                                     ) sideWalls++; // right
122 122
            }
123 123
         }
124 124

  

Also available in: Unified diff