Revision 0729bc41
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/DistortedCubesGrid.java | ||
---|---|---|
159 | 159 |
} |
160 | 160 |
*/ |
161 | 161 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
162 |
// desc is guaranteed to be padded with 0s in the end (DistortedCubes constructor does it) |
|
162 | 163 |
|
163 | 164 |
private void buildGrid(int cols, String desc, boolean frontOnly) |
164 | 165 |
{ |
... | ... | |
166 | 167 |
mCols =0; |
167 | 168 |
dataLength=0; |
168 | 169 |
|
169 |
if( cols>0 ) |
|
170 |
if( cols>0 && desc.contains("1") )
|
|
170 | 171 |
{ |
171 |
int reallen = desc.length();
|
|
172 |
int len = reallen;
|
|
172 |
mCols = cols;
|
|
173 |
mRows = desc.length()/cols;
|
|
173 | 174 |
|
174 |
if( (reallen/cols)*cols != reallen ) |
|
175 |
{ |
|
176 |
len = ((reallen/cols)+1)*cols; |
|
177 |
for(int i=reallen; i<len; i++) desc += "0"; |
|
178 |
} |
|
179 |
|
|
180 |
if( desc.contains("1") ) |
|
181 |
{ |
|
182 |
mCols = cols; |
|
183 |
mRows = len/cols; |
|
184 |
|
|
185 |
mCubes = new short[mRows][mCols]; |
|
175 |
mCubes = new short[mRows][mCols]; |
|
186 | 176 |
|
187 |
for(int j=0; j<mCols; j++)
|
|
188 |
for(int i=0; i<mRows; i++)
|
|
189 |
mCubes[i][j] = (short)(desc.charAt(i*mCols+j) == '1' ? 1:0);
|
|
177 |
for(int j=0; j<mCols; j++)
|
|
178 |
for(int i=0; i<mRows; i++) |
|
179 |
mCubes[i][j] = (short)(desc.charAt(i*mCols+j) == '1' ? 1:0);
|
|
190 | 180 |
|
191 |
markRegions(); |
|
192 |
dataLength = computeDataLength(frontOnly); |
|
193 |
} |
|
181 |
markRegions(); |
|
182 |
dataLength = computeDataLength(frontOnly); |
|
194 | 183 |
} |
195 | 184 |
} |
196 | 185 |
|
Also available in: Unified diff
Add DistortedGridFactory to share Grids among same-shaped DistortedObjects.