commit eb389a97700bf11a20c3c5f21f0df3c4500fb4bb
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Oct 15 11:49:13 2020 +0100

    Move computation of the rotation rows to the Object from Cubits.

diff --git a/src/main/java/org/distorted/objects/Cubit.java b/src/main/java/org/distorted/objects/Cubit.java
index ccc4d96e..05ff4570 100644
--- a/src/main/java/org/distorted/objects/Cubit.java
+++ b/src/main/java/org/distorted/objects/Cubit.java
@@ -36,7 +36,7 @@ class Cubit
   private int mNumAxis;
 
   int mQuatIndex;
-  float[] mRotationRow;
+  int[] mRotationRow;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -52,7 +52,7 @@ class Cubit
     mQuatIndex       = 0;
 
     mNumAxis     = mParent.ROTATION_AXIS.length;
-    mRotationRow = new float[mNumAxis];
+    mRotationRow = new int[mNumAxis];
     computeRotationRow();
     }
 
@@ -111,21 +111,16 @@ class Cubit
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// cast current position on axis; use mStart and mStep to compute the rotation row for each axis.
 
   private void computeRotationRow()
     {
-    float tmp;
-    Static3D axis;
     float x = mCurrentPosition.get0();
     float y = mCurrentPosition.get1();
     float z = mCurrentPosition.get2();
 
     for(int i=0; i<mNumAxis; i++)
       {
-      axis = mParent.ROTATION_AXIS[i];
-      tmp = x*axis.get0() + y*axis.get1() + z*axis.get2();
-      mRotationRow[i] = (tmp-mParent.mStart)/mParent.mStep;
+      mRotationRow[i] = mParent.computeRow(x,y,z,i);
       }
     }
 
@@ -161,12 +156,11 @@ class Cubit
 
   int computeAssociation()
     {
-    int row, result = 0, accumulativeShift = 0;
+    int result = 0, accumulativeShift = 0;
 
     for(int axis=0; axis<mNumAxis; axis++)
       {
-      row = (int)(mRotationRow[axis]+0.5f);
-      result += (1<<(row+accumulativeShift));
+      result += (1<<(mRotationRow[axis]+accumulativeShift));
       accumulativeShift += ObjectList.MAX_OBJECT_SIZE;
       }
 
diff --git a/src/main/java/org/distorted/objects/TwistyCube.java b/src/main/java/org/distorted/objects/TwistyCube.java
index 0fe5f20d..8478d560 100644
--- a/src/main/java/org/distorted/objects/TwistyCube.java
+++ b/src/main/java/org/distorted/objects/TwistyCube.java
@@ -331,9 +331,7 @@ class TwistyCube extends TwistyObject
                Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 );
                Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 );
 
-               float row1, row2, row3, row4;
-               float ax,ay,az;
-               Static3D axis;
+               float row1, row2;
                float x1 = rotated1.get0();
                float y1 = rotated1.get1();
                float z1 = rotated1.get2();
@@ -343,21 +341,10 @@ class TwistyCube extends TwistyObject
 
                for(int i=0; i<NUM_AXIS; i++)
                  {
-                 axis = ROTATION_AXIS[i];
-                 ax = axis.get0();
-                 ay = axis.get1();
-                 az = axis.get2();
-
-                 row1 = ((x1*ax + y1*ay + z1*az) - mStart) / mStep;
-                 row2 = ((x2*ax + y2*ay + z2*az) - mStart) / mStep;
-                 row3 = row1 - size;
-                 row4 = row2 - size;
-
-                 if( (row1<MAX_ERROR && row1>-MAX_ERROR && row2<MAX_ERROR && row2>-MAX_ERROR) ||
-                     (row3<MAX_ERROR && row3>-MAX_ERROR && row4<MAX_ERROR && row4>-MAX_ERROR)  )
-                   {
-                   return true;
-                   }
+                 row1 = computeRow(x1,y1,z1,i);
+                 row2 = computeRow(x2,y2,z2,i);
+
+                 if( (row1==0 && row2==0) || (row1==size || row2==size) ) return true;
                  }
                return false;
 
diff --git a/src/main/java/org/distorted/objects/TwistyObject.java b/src/main/java/org/distorted/objects/TwistyObject.java
index 647a87aa..327d05b2 100644
--- a/src/main/java/org/distorted/objects/TwistyObject.java
+++ b/src/main/java/org/distorted/objects/TwistyObject.java
@@ -106,13 +106,11 @@ public abstract class TwistyObject extends DistortedNode
   private Dynamic1D mRotationAngle;
   private Static3D mRotationAxis;
   private Static3D mObjectScale;
+  private float mStart, mStep;
 
-  float mStart, mStep;
   float[] mRowChances;
-
   Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
   DistortedTexture mTexture;
-
   MatrixEffectScale mScaleEffect;
   MatrixEffectQuaternion mQuatEffect;
 
@@ -299,6 +297,16 @@ public abstract class TwistyObject extends DistortedNode
     return ((1<<cubitRow)&rowBitmap)!=0;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int computeRow(float x, float y, float z, int rotIndex)
+    {
+    Static3D axis = ROTATION_AXIS[rotIndex];
+    float tmp = x*axis.get0() + y*axis.get1() + z*axis.get2();
+
+    return (int)((tmp-mStart)/mStep +0.5f);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // note the minus in front of the sin() - we rotate counterclockwise
 // when looking towards the direction where the axis increases in values.
diff --git a/src/main/java/org/distorted/objects/TwistyPyraminx.java b/src/main/java/org/distorted/objects/TwistyPyraminx.java
index c5099a95..2dde81d6 100644
--- a/src/main/java/org/distorted/objects/TwistyPyraminx.java
+++ b/src/main/java/org/distorted/objects/TwistyPyraminx.java
@@ -365,9 +365,7 @@ public class TwistyPyraminx extends TwistyObject
                Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 );
                Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 );
 
-               float row1, row2, row3, row4;
-               float ax,ay,az;
-               Static3D axis;
+               float row1, row2;
                float x1 = rotated1.get0();
                float y1 = rotated1.get1();
                float z1 = rotated1.get2();
@@ -377,21 +375,10 @@ public class TwistyPyraminx extends TwistyObject
 
                for(int i=0; i<NUM_AXIS; i++)
                  {
-                 axis = ROTATION_AXIS[i];
-                 ax = axis.get0();
-                 ay = axis.get1();
-                 az = axis.get2();
-
-                 row1 = ((x1*ax + y1*ay + z1*az) - mStart) / mStep;
-                 row2 = ((x2*ax + y2*ay + z2*az) - mStart) / mStep;
-                 row3 = row1 - size;
-                 row4 = row2 - size;
-
-                 if( (row1<MAX_ERROR && row1>-MAX_ERROR && row2<MAX_ERROR && row2>-MAX_ERROR) ||
-                     (row3<MAX_ERROR && row3>-MAX_ERROR && row4<MAX_ERROR && row4>-MAX_ERROR)  )
-                   {
-                   return true;
-                   }
+                 row1 = computeRow(x1,y1,z1,i);
+                 row2 = computeRow(x2,y2,z2,i);
+
+                 if( (row1==0 && row2==0) || (row1==size || row2==size) ) return true;
                  }
                return false;
 
diff --git a/src/main/java/org/distorted/states/RubikStatePlay.java b/src/main/java/org/distorted/states/RubikStatePlay.java
index 97a98919..7efa3c1c 100644
--- a/src/main/java/org/distorted/states/RubikStatePlay.java
+++ b/src/main/java/org/distorted/states/RubikStatePlay.java
@@ -573,8 +573,8 @@ public class RubikStatePlay extends RubikStateAbstract implements RubikPreRender
 
   public void restorePreferences(SharedPreferences preferences)
     {
-    mObject     = preferences.getInt("statePlay_object", DEF_OBJECT);
-    mSize       = preferences.getInt("statePlay_size"  , DEF_SIZE  );
+    mObject= preferences.getInt("statePlay_object", DEF_OBJECT);
+    mSize  = preferences.getInt("statePlay_size"  , DEF_SIZE  );
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
