commit 10a2e3602c5294073e03f4d2d6b22afec7668868
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Mar 5 17:13:07 2020 +0000

    Progress towards generalizing belongsToRotation()

diff --git a/src/main/java/org/distorted/object/Cubit.java b/src/main/java/org/distorted/object/Cubit.java
index d0d6c95f..28b21fc8 100644
--- a/src/main/java/org/distorted/object/Cubit.java
+++ b/src/main/java/org/distorted/object/Cubit.java
@@ -52,6 +52,7 @@ class Cubit
   DistortedNode mNode;
   DistortedEffects mEffect;
   Static4D mQuatScramble;
+  int[] mRotationRow;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Because of quatMultiplication, errors can accumulate - so to avoid this, we
@@ -149,6 +150,18 @@ class Cubit
     int roundedZ = (int)(rotatedZ+0.1f);
 
     currentPosition.set(roundedX, roundedY, roundedZ);
+    computeRotationRow();
+    }
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO: this is only right in case of RubikCube
+
+  private void computeRotationRow()
+    {
+    mRotationRow[0] = (int)mCurrentPosition.get0();
+    mRotationRow[1] = (int)mCurrentPosition.get1();
+    mRotationRow[2] = (int)mCurrentPosition.get2();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -171,6 +184,9 @@ class Cubit
     mCurrentPosition = position;
     mRotateEffect    = new MatrixEffectRotate(mRotationAngle, mRotationAxis, matrCenter);
 
+    mRotationRow = new int[mParent.ROTATION_AXIS.length];
+    computeRotationRow();
+
     mEffect = new DistortedEffects();
     mEffect.apply(mParent.mSinkEffect);
     mEffect.apply( new MatrixEffectMove(vector) );
diff --git a/src/main/java/org/distorted/object/RubikCube.java b/src/main/java/org/distorted/object/RubikCube.java
index 14af9baf..5b7cb048 100644
--- a/src/main/java/org/distorted/object/RubikCube.java
+++ b/src/main/java/org/distorted/object/RubikCube.java
@@ -82,38 +82,24 @@ class RubikCube extends RubikObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  int[][] getCubitPositions(int size)
+  Static3D[] getCubitPositions(int size)
     {
-    int[][] tmp = new int[getNumCubits(size)][3];
+    int numCubits = size>1 ? 6*size*size - 12*size + 8 : 1;
+    Static3D[] tmp = new Static3D[numCubits];
 
     int currentPosition = 0;
 
     for(int x = 0; x<size; x++)
       for(int y = 0; y<size; y++)
         for(int z = 0; z<size; z++)
-          {
           if( x==0 || x==size-1 || y==0 || y==size-1 || z==0 || z==size-1 )
             {
-            tmp[currentPosition][0] = x;
-            tmp[currentPosition][1] = y;
-            tmp[currentPosition][2] = z;
-
-            currentPosition++;
+            tmp[currentPosition++] = new Static3D(x,y,z);
             }
-          }
 
     return tmp;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// i.e. size^3 - (size-2)^3 - number of cubits in the outside wall of the Cube (we don't create or
-// render the inside)
-
-  int getNumCubits(int size)
-    {
-    return size>1 ? 6*size*size - 12*size + 8 : 1;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   float[] getLegalQuats()
diff --git a/src/main/java/org/distorted/object/RubikObject.java b/src/main/java/org/distorted/object/RubikObject.java
index 693f5bd6..606debf5 100644
--- a/src/main/java/org/distorted/object/RubikObject.java
+++ b/src/main/java/org/distorted/object/RubikObject.java
@@ -76,8 +76,10 @@ public abstract class RubikObject extends DistortedNode
 
     resizeFBO(NODE_FBO_SIZE, NODE_FBO_SIZE);
 
+    Static3D[] positions = getCubitPositions(size);
+
     LEGAL_QUATS = getLegalQuats();
-    NUM_CUBITS  = getNumCubits(size);
+    NUM_CUBITS  = positions.length;
     ROTATION_AXIS = getRotationAxis();
 
     mSize = size;
@@ -106,13 +108,11 @@ public abstract class RubikObject extends DistortedNode
     mTexture = new DistortedTexture();
 
     int vertices = (int)(24.0f/mSize + 2.0f);
-    int[][] positions = getCubitPositions(size);
 
     for(int i=0; i<NUM_CUBITS; i++)
       {
-      Static3D pos = new Static3D(positions[i][0],positions[i][1],positions[i][2]);
       MeshBase cubitMesh = createCubitMesh(vertices);
-      mCubits[i] = new Cubit(this,cubitMesh,pos);
+      mCubits[i] = new Cubit(this,cubitMesh,positions[i]);
       textureCubitMesh(cubitMesh,i);
 
       attach(mCubits[i].mNode);
@@ -149,17 +149,10 @@ public abstract class RubikObject extends DistortedNode
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// TODO: only works for RubikCube
 
   private boolean belongsToRotation( int cubit, int axis, int row)
     {
-    Static3D position = mCubits[cubit].mCurrentPosition;
-
-    if( axis==0 ) return position.get0()==row;
-    if( axis==1 ) return position.get1()==row;
-    if( axis==2 ) return position.get2()==row;
-
-    return false;
+    return mCubits[cubit].mRotationRow[axis]==row;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -403,8 +396,14 @@ public abstract class RubikObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  abstract int getNumCubits(int size);
-  abstract int[][] getCubitPositions(int size);
+  public int getNumRotations()
+    {
+    return ROTATION_AXIS.length;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  abstract Static3D[] getCubitPositions(int size);
   abstract float[] getLegalQuats();
   abstract int getNumFaces();
   abstract void createFaceTexture(Canvas canvas, Paint paint, int face);
