commit 398f2870ff60dcc38e5470c15fad292393e83451
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Apr 24 15:06:10 2023 +0200

    CU_323 solver: corrections.

diff --git a/src/main/java/org/distorted/objectlib/tablebases/TBCuboid323.java b/src/main/java/org/distorted/objectlib/tablebases/TBCuboid323.java
index 61fa5b2f..ccd07cf3 100644
--- a/src/main/java/org/distorted/objectlib/tablebases/TBCuboid323.java
+++ b/src/main/java/org/distorted/objectlib/tablebases/TBCuboid323.java
@@ -188,6 +188,8 @@ public class TBCuboid323 extends TablebasesPruning
     if( axis==2 && layer==2 ) mFixedEdgeIsDown = !mFixedEdgeIsDown;
     if( axis==1 )
       {
+      if( angle==3 ) angle=-1;
+
       if( layer==0 &&  mFixedEdgeIsDown ) return new int[] { axis, 2, angle };
       if( layer==1 && !mFixedEdgeIsDown ) return new int[] { axis, 1, angle };
       }
@@ -195,6 +197,7 @@ public class TBCuboid323 extends TablebasesPruning
     int maxAngle = mAngles[axis][layer];
     angle = maxAngle-angle;
     if( angle> 0.5f*maxAngle ) angle -= maxAngle;
+
     return new int[] { axis, (1<<layer), angle };
     }
 
@@ -243,7 +246,7 @@ public class TBCuboid323 extends TablebasesPruning
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private int findIndex(int[] table, int value)
+  private static int findIndex(int[] table, int value)
     {
     for(int i=0; i<8; i++)
       if( table[i]==value ) return i;
@@ -260,7 +263,7 @@ public class TBCuboid323 extends TablebasesPruning
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private void correctQuats(int[] quats)
+  private void normalizeQuats(int[] quats)
     {
     int mult=0;
 
@@ -275,6 +278,40 @@ public class TBCuboid323 extends TablebasesPruning
     for(int i=0; i<16; i++) quats[i] = getMultQuat(mult,quats[i]);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static int[] quatsFromPermutations(int[] corner, int[] edge8)
+    {
+    int[] quats = new int[18];
+
+    for(int i=0; i<8; i++)
+      {
+      int q = CORNER_MAP[i][corner[i]];
+      quats[i] = q;
+      }
+    for(int i=0; i<8; i++)
+      {
+      int q = EDGE_MAP[i][edge8[i]];
+      quats[i+8] = q;
+      }
+
+    return quats;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void cornerFromQuats(int[] corner_perm, int[] quats)
+    {
+    for(int i=0; i<8; i++) corner_perm[i] = findIndex( CORNER_MAP[i], quats[i]);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void edgeFromQuats(int[] edge_perm, int[] quats)
+    {
+    for(int i=0; i<8; i++) edge_perm[i] = findIndex( EDGE_MAP[i], quats[i+8]);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public int[] getQuats(int index)
@@ -295,38 +332,21 @@ TablebaseHelpers.displayTable(edge_perm8, "EDGE8");
 TablebaseHelpers.displayTable(edge_perm7, "EDGE7");
 android.util.Log.e("D", "inPlace="+inPlace);
 */
-    int[] quats = new int[18];
 
-    for(int i=0; i<8; i++)
-      {
-      int q = CORNER_MAP[i][corner_perm[i]];
-      quats[i] = q;
-      }
-    for(int i=0; i<8; i++)
-      {
-      int q = EDGE_MAP[i][edge_perm8[i]];
-      quats[i+8] = q;
-      }
-
-    return quats;
+    return quatsFromPermutations(corner_perm,edge_perm8);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public int getIndex(int[] quats)
     {
+    normalizeQuats(quats);
+
     int[] corner_perm = new int[8];
+    cornerFromQuats(corner_perm,quats);
     int[] edge_perm8  = new int[8];
-
-    correctQuats(quats);
-
-    for(int i=0; i<8; i++)
-      {
-      corner_perm[i] = findIndex( CORNER_MAP[i], quats[i  ]);
-      edge_perm8[i]  = findIndex( EDGE_MAP[i]  , quats[i+8]);
-      }
-
-    int[] edge_perm7 = edgePermTo7(edge_perm8);
+    edgeFromQuats(edge_perm8,quats);
+    int[] edge_perm7  = edgePermTo7(edge_perm8);
 
     int corner_perm_num = TablebaseHelpers.computePermutationNum(corner_perm);
     int edge_perm_num = TablebaseHelpers.computePermutationNum(edge_perm7);
diff --git a/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java b/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
index 69470e2f..fd17bd35 100644
--- a/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
+++ b/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
@@ -166,9 +166,10 @@ public abstract class TablebasesAbstract
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // remember about the double cover or unit quaternions!
 
-  private int mulQuat(int q1, int q2)
+  public static int mulQuat(int q1, int q2, Static4D[] quats)
     {
-    Static4D result = QuatHelper.quatMultiply(mQuats[q1],mQuats[q2]);
+    int numQuats = quats.length;
+    Static4D result = QuatHelper.quatMultiply(quats[q1],quats[q2]);
 
     float rX = result.get0();
     float rY = result.get1();
@@ -178,22 +179,22 @@ public abstract class TablebasesAbstract
     final float MAX_ERROR = 0.1f;
     float dX,dY,dZ,dW;
 
-    for(int i=0; i<mNumQuats; i++)
+    for(int i=0; i<numQuats; i++)
       {
-      dX = mQuats[i].get0() - rX;
-      dY = mQuats[i].get1() - rY;
-      dZ = mQuats[i].get2() - rZ;
-      dW = mQuats[i].get3() - rW;
+      dX = quats[i].get0() - rX;
+      dY = quats[i].get1() - rY;
+      dZ = quats[i].get2() - rZ;
+      dW = quats[i].get3() - rW;
 
       if( dX<MAX_ERROR && dX>-MAX_ERROR &&
           dY<MAX_ERROR && dY>-MAX_ERROR &&
           dZ<MAX_ERROR && dZ>-MAX_ERROR &&
           dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
 
-      dX = mQuats[i].get0() + rX;
-      dY = mQuats[i].get1() + rY;
-      dZ = mQuats[i].get2() + rZ;
-      dW = mQuats[i].get3() + rW;
+      dX = quats[i].get0() + rX;
+      dY = quats[i].get1() + rY;
+      dZ = quats[i].get2() + rZ;
+      dW = quats[i].get3() + rW;
 
       if( dX<MAX_ERROR && dX>-MAX_ERROR &&
           dY<MAX_ERROR && dY>-MAX_ERROR &&
@@ -218,7 +219,7 @@ public abstract class TablebasesAbstract
 
     if( index1<mNumQuats && index2<mNumQuats )
       {
-      if( mQuatMult[index1][index2]==-1 ) mQuatMult[index1][index2] = mulQuat(index1,index2);
+      if( mQuatMult[index1][index2]==-1 ) mQuatMult[index1][index2] = mulQuat(index1,index2, mQuats);
       return mQuatMult[index1][index2];
       }
 
