Revision efeca8ef
Added by Leszek Koltunski about 2 years ago
src/main/java/org/distorted/objectlib/helpers/ObjectSignature.java | ||
---|---|---|
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
73 |
// objects created from JSON (version2) |
|
73 |
// locally created bandaged cuboids created from JSON (version2) |
|
74 |
|
|
75 |
public ObjectSignature(String shortName, long signature1, long signature2, long signature3) |
|
76 |
{ |
|
77 |
mSignature1 = signature1; |
|
78 |
mSignature2 = signature2; |
|
79 |
mSignature3 = signature3; |
|
80 |
|
|
81 |
int x = shortName.charAt(0) - '0'; |
|
82 |
int y = shortName.charAt(1) - '0'; |
|
83 |
int z = shortName.charAt(2) - '0'; |
|
84 |
|
|
85 |
mLayer = new int[] {x,y,z}; |
|
86 |
|
|
87 |
prepareCubitTouch(); |
|
88 |
prepareAllCycles(); |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
// other objects created from JSON (version2) |
|
74 | 93 |
|
75 | 94 |
public ObjectSignature(long signature1, long signature2, long signature3) |
76 | 95 |
{ |
... | ... | |
96 | 115 |
int numCenters = pos.length/3; |
97 | 116 |
|
98 | 117 |
for(int i=0; i<numCenters; i++) |
118 |
{ |
|
119 |
float xi = pos[3*i ]; |
|
120 |
float yi = pos[3*i+1]; |
|
121 |
float zi = pos[3*i+2]; |
|
122 |
|
|
99 | 123 |
for(int j=i+1; j<numCenters; j++) |
100 | 124 |
{ |
101 |
float x1 = pos[3*i ]; |
|
102 |
float y1 = pos[3*i+1]; |
|
103 |
float z1 = pos[3*i+2]; |
|
104 |
float x2 = pos[3*i ]; |
|
105 |
float y2 = pos[3*i+1]; |
|
106 |
float z2 = pos[3*i+2]; |
|
107 |
|
|
108 |
if(areNeighbours(x1-x2,y1-y2,z1-z2)) |
|
125 |
float xj = pos[3*j ]; |
|
126 |
float yj = pos[3*j+1]; |
|
127 |
float zj = pos[3*j+2]; |
|
128 |
|
|
129 |
if(areNeighbours(xi-xj,yi-yj,zi-zj)) |
|
109 | 130 |
{ |
110 |
float xc = (x1+y1)/2;
|
|
111 |
float yc = (y1+y2)/2;
|
|
112 |
float zc = (z1+z2)/2;
|
|
131 |
float xc = (xi+xj)/2;
|
|
132 |
float yc = (yi+yj)/2;
|
|
133 |
float zc = (zi+zj)/2;
|
|
113 | 134 |
|
114 | 135 |
int bitIndex = getIndexOfCubitTouch(xc,yc,zc); |
115 | 136 |
setBit(bitIndex,1); |
116 | 137 |
} |
117 | 138 |
} |
139 |
} |
|
118 | 140 |
} |
119 | 141 |
} |
120 | 142 |
|
... | ... | |
168 | 190 |
|
169 | 191 |
public String getString() |
170 | 192 |
{ |
171 |
return mSignature1+"_"+mSignature2+"_"+mSignature3; |
|
193 |
String sig1 = String.format("0x%016X", mSignature1); |
|
194 |
String sig2 = String.format("0x%016X", mSignature2); |
|
195 |
String sig3 = String.format("0x%016X", mSignature3); |
|
196 |
|
|
197 |
return sig1+"_"+sig2+"_"+sig3; |
|
172 | 198 |
} |
173 | 199 |
|
174 | 200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
305 | 331 |
|
306 | 332 |
if( areNeighbours(x1-x2,y1-y2,z1-z2) ) |
307 | 333 |
{ |
308 |
float xc = (x1+y1)/2;
|
|
334 |
float xc = (x1+x2)/2;
|
|
309 | 335 |
float yc = (y1+y2)/2; |
310 | 336 |
float zc = (z1+z2)/2; |
311 | 337 |
|
... | ... | |
317 | 343 |
mNumCubitTouches = mTouch.size(); |
318 | 344 |
mCubitTouch = new float[mNumCubitTouches][]; |
319 | 345 |
for(int i=0; i<mNumCubitTouches; i++) mCubitTouch[i] = mTouch.remove(0); |
346 |
|
|
347 |
// now sort the touches so that the order agrees with 'Andreas signature' as defined here: |
|
348 |
// https://twistypuzzles.com/forum/viewtopic.php?p=415466#p415466 |
|
349 |
// i.e. we need to sort by Y first (increasing) then by Z (decreasing) then by X (decreasing) |
|
350 |
// i.e. we need to sort by 100Y-10Z-X (increasing) |
|
351 |
|
|
352 |
for(int i=0; i<mNumCubitTouches; i++) |
|
353 |
{ |
|
354 |
float[] ci = mCubitTouch[i]; |
|
355 |
float val_i = 100*ci[1]-10*ci[2]-ci[0]; |
|
356 |
|
|
357 |
for(int j=i+1; j<mNumCubitTouches; j++) |
|
358 |
{ |
|
359 |
float[] cj = mCubitTouch[j]; |
|
360 |
float val_j = 100*cj[1]-10*cj[2]-cj[0]; |
|
361 |
|
|
362 |
if( val_j<val_i ) |
|
363 |
{ |
|
364 |
mCubitTouch[i] = cj; |
|
365 |
mCubitTouch[j] = ci; |
|
366 |
val_i = val_j; |
|
367 |
ci = cj; |
|
368 |
} |
|
369 |
} |
|
370 |
} |
|
371 |
/* |
|
372 |
android.util.Log.e("D", "num touches="+mNumCubitTouches); |
|
373 |
|
|
374 |
for(int i=0; i<mNumCubitTouches; i++) |
|
375 |
{ |
|
376 |
android.util.Log.e("D", mCubitTouch[i][0]+" "+mCubitTouch[i][1]+" "+mCubitTouch[i][2]); |
|
377 |
} |
|
378 |
*/ |
|
320 | 379 |
} |
321 | 380 |
|
322 | 381 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Fixes for scrambling locally-produced bandaged cuboid.
Still does not work completely.