Revision b62632fc
Added by Leszek Koltunski about 8 years ago
src/main/java/org/distorted/library/DistortedCubesGrid.java | ||
---|---|---|
66 | 66 |
private int remainingVert; |
67 | 67 |
private int mSideBends; |
68 | 68 |
private int mEdgeNum; |
69 |
private int mSideWalls; |
|
69 | 70 |
|
70 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
71 | 72 |
// a Block is split into two triangles along the NE-SW line iff it is in the top-right |
... | ... | |
81 | 82 |
|
82 | 83 |
private int computeDataLength(boolean frontOnly) |
83 | 84 |
{ |
84 |
int frontWalls=0, frontSegments=0, sideWalls=0, triangleShifts=0, windingShifts=0;
|
|
85 |
int frontWalls=0, frontSegments=0, triangleShifts=0, windingShifts=0; |
|
85 | 86 |
int shiftCol = (mCols-1)/2; |
86 | 87 |
|
87 | 88 |
boolean lastBlockIsNE=false; |
88 | 89 |
boolean thisBlockIsNE; // the block we are currently looking at is split into |
89 | 90 |
// two triangles along the NE-SW line (rather than NW-SE) |
90 | 91 |
for(int row=0; row<mRows; row++) |
91 |
{
|
|
92 |
if( mCols>=2 && (mCubes[row][shiftCol]%2 == 1) && (mCubes[row][shiftCol+1]%2 == 1) ) triangleShifts++;
|
|
92 |
{ |
|
93 |
if( mCols>=2 && (mCubes[row][shiftCol]%2 == 1) && (mCubes[row][shiftCol+1]%2 == 1) ) triangleShifts++; |
|
93 | 94 |
|
94 |
for(int col=0; col<mCols; col++) |
|
95 |
for(int col=0; col<mCols; col++) |
|
96 |
{ |
|
97 |
if( mCubes[row][col]%2 == 1 ) // land |
|
95 | 98 |
{ |
96 |
if( mCubes[row][col]%2 == 1 ) // land |
|
97 |
{ |
|
98 |
thisBlockIsNE = isNE(row,col); |
|
99 |
if( thisBlockIsNE^lastBlockIsNE ) windingShifts++; |
|
100 |
lastBlockIsNE = thisBlockIsNE; |
|
101 |
frontWalls++; |
|
102 |
if( col==mCols-1 || mCubes[row][col+1]%2 == 0 ) frontSegments++; |
|
103 |
} |
|
104 |
|
|
105 |
if( (row==0 && mCubes[row][col]!=2) || (row!=0 && mCubes[row][col] != mCubes[row-1][col ]) ) sideWalls++; // up |
|
106 |
if( (col==0 && mCubes[row][col]!=2) || (col!=0 && mCubes[row][col] != mCubes[row ][col-1]) ) sideWalls++; // left |
|
107 |
if( row==mRows-1 && mCubes[row][col]!=2 ) sideWalls++; // bottom |
|
108 |
if( col==mCols-1 && mCubes[row][col]!=2 ) sideWalls++; // right |
|
99 |
thisBlockIsNE = isNE(row,col); |
|
100 |
if( thisBlockIsNE^lastBlockIsNE ) windingShifts++; |
|
101 |
lastBlockIsNE = thisBlockIsNE; |
|
102 |
frontWalls++; |
|
103 |
if( col==mCols-1 || mCubes[row][col+1]%2 == 0 ) frontSegments++; |
|
109 | 104 |
} |
110 |
} |
|
105 |
} |
|
106 |
} |
|
111 | 107 |
|
112 | 108 |
int frontVert = 2*( frontWalls + 2*frontSegments - 1) +2*triangleShifts + windingShifts; |
113 |
int sideVert = 2*( sideWalls + mSideBends + mEdgeNum -1);
|
|
109 |
int sideVert = 2*( mSideWalls + mSideBends + mEdgeNum -1);
|
|
114 | 110 |
int firstWinding= (!frontOnly && (frontVert+1)%2==1 ) ? 1:0; |
115 | 111 |
int dataL = frontOnly ? frontVert : (frontVert+1) +firstWinding+ (1+sideVert+1) + (1+frontVert); |
116 | 112 |
/* |
117 |
android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts); |
|
118 |
android.util.Log.e("CUBES","Winding1="+firstWinding+" frontVert="+frontVert+" sideVert="+sideVert); |
|
119 |
android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+sideWalls+" sSegments="+mEdgeNum+" sideBends="+mSideBends+" dataLen="+dataL ); |
|
113 |
android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts+" winding1="+firstWinding+" frontVert="+frontVert+" sideVert="+sideVert); |
|
114 |
android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+mSideWalls+" sSegments="+mEdgeNum+" sideBends="+mSideBends+" dataLen="+dataL ); |
|
120 | 115 |
*/ |
121 | 116 |
return dataL<0 ? 0:dataL; |
122 | 117 |
} |
... | ... | |
266 | 261 |
{ |
267 | 262 |
//android.util.Log.d("CUBES", "checking edge "+debug(e1)); |
268 | 263 |
|
264 |
mSideWalls++; |
|
265 |
|
|
269 | 266 |
if( e1.side==NORTH || e1.side==SOUTH ) |
270 | 267 |
{ |
271 | 268 |
for(j=i+1;j<mEdgeNum;j++) |
Also available in: Unified diff
Some speedup in CubesGrid