commit 8c3148e2b792657509f69f5182ef61b00aa3e7a7
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Sep 7 01:25:06 2021 +0200

    Remove statics from the Skewb class.

diff --git a/src/main/java/org/distorted/objects/TwistySkewb.java b/src/main/java/org/distorted/objects/TwistySkewb.java
index 4a891927..011f585f 100644
--- a/src/main/java/org/distorted/objects/TwistySkewb.java
+++ b/src/main/java/org/distorted/objects/TwistySkewb.java
@@ -37,8 +37,6 @@ import java.util.Random;
 
 public class TwistySkewb extends TwistyObject
 {
-  private static final int FACES_PER_CUBIT =6;
-
   // the four rotation axis of a RubikSkewb. Must be normalized.
   static final Static3D[] ROT_AXIS = new Static3D[]
          {
@@ -48,8 +46,6 @@ public class TwistySkewb extends TwistyObject
            new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
          };
 
-  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
-
   private static final int[] FACE_COLORS = new int[]
          {
            COLOR_YELLOW, COLOR_WHITE,
@@ -57,144 +53,15 @@ public class TwistySkewb extends TwistyObject
            COLOR_RED   , COLOR_ORANGE
          };
 
-  // All legal rotation quats of a RubikSkewb
-  private static final Static4D[] QUATS = new Static4D[]
-         {
-           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
-           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
-           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
-           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
-
-           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
-           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
-           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
-           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
-           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
-           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
-           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
-           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
-         };
-
-  private static final int[][] mCornerMap =
-         {
-           {  4, 2, 0, 18,18,18 },
-           {  2, 5, 0, 18,18,18 },
-           {  3, 4, 0, 18,18,18 },
-           {  5, 3, 0, 18,18,18 },
-           {  1, 2, 4, 18,18,18 },
-           {  5, 2, 1, 18,18,18 },
-           {  4, 3, 1, 18,18,18 },
-           {  1, 3, 5, 18,18,18 },
-         };
-
-  private static final int[][] mEdgeMap =
-         {
-           { 10, 8, 18,18,18,18 },
-           {  6,10, 18,18,18,18 },
-           { 10, 9, 18,18,18,18 },
-           {  7,10, 18,18,18,18 },
-           {  8, 6, 18,18,18,18 },
-           {  9, 6, 18,18,18,18 },
-           {  9, 7, 18,18,18,18 },
-           {  8, 7, 18,18,18,18 },
-           { 11, 8, 18,18,18,18 },
-           {  6,11, 18,18,18,18 },
-           { 11, 9, 18,18,18,18 },
-           {  7,11, 18,18,18,18 }
-         };
-
-  private static final int[][] mCenterMap =
-         {
-           { 12, 18,18,18,18,18 },
-           { 13, 18,18,18,18,18 },
-           { 14, 18,18,18,18,18 },
-           { 15, 18,18,18,18,18 },
-           { 16, 18,18,18,18,18 },
-           { 17, 18,18,18,18,18 },
-         };
-
-  private static final double[][] VERTICES_CORNER = new double[][]
-          {
-              {-0.5f, 0.0f, 0.0f},
-              { 0.0f,-0.5f, 0.0f},
-              { 0.0f, 0.0f,-0.5f},
-              {-0.5f,-0.5f,-0.5f},
-              { 0.0f, 0.0f, 0.0f}
-          };
-
-  private static final int[][] VERT_INDEXES_CORNER = new int[][]
-          {
-              {0,1,4},
-              {2,0,4},
-              {1,2,4},
-              {3,1,0},
-              {3,2,1},
-              {3,0,2}
-          };
-
-  private static final double[][] VERTICES_EDGE = new double[][]
-          {
-             {-0.5, 0.0, 0.0},
-             { 0.5, 0.0, 0.0},
-             { 0.0,-0.5, 0.0},
-             { 0.0, 0.0,-0.5}
-          };
-
-  private static final int[][] VERT_INDEXES_EDGE = new int[][]
-          {
-             {2,1,0},   // counterclockwise!
-             {3,0,1},
-             {2,3,1},
-             {3,2,0},
-          };
-
-  private static final double[][] VERTICES_FACE = new double[][]
-          {
-             {-0.5f, 0.0f, 0.0f },
-             { 0.0f,-0.5f, 0.0f },
-             { 0.5f, 0.0f, 0.0f },
-             { 0.0f, 0.5f, 0.0f },
-             { 0.0f, 0.0f,-0.5f }
-          };
-
-  private static final int[][] VERT_INDEXES_FACE = new int[][]
-          {
-             {0,1,2,3},
-             {4,1,0},
-             {4,2,1},
-             {4,3,2},
-             {4,0,3}
-          };
-
-  private static final float[][] STICKERS = new float[][]
-          {
-             { -0.5f, 0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
-             { -0.5f, 0.00f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
-          };
-
-  private static final ObjectSticker[] mStickers;
-
-  static
-    {
-    mStickers = new ObjectSticker[STICKERS.length+1];
-    final float R1 = 0.025f;
-    final float R2 = 0.025f;
-    final float R3 = 0.055f;
-    final float[][] radii  = { { R1,R1,R1 },{ R2,R2,R2 },{ R3,R3,R3,R3 } };
-    final float[] strokes = { 0.045f, 0.035f, 0.035f };
-
-    for(int s=0; s<STICKERS.length+1; s++)
-      {
-      int index = s<2 ? 0:1;
-      mStickers[s] = new ObjectSticker(STICKERS[index],null,radii[s],strokes[s]);
-      }
-    }
-
   private int mCurrState;
   private int mIndexExcluded;
   private final ScrambleState[] mStates;
   private int[][] mScrambleTable;
   private int[] mNumOccurences;
+  private int[] mBasicAngle;
+  private Static4D[] mQuats;
+  private int[][] mCornerMap,mEdgeMap,mCenterMap;
+  private ObjectSticker[] mStickers;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -211,12 +78,35 @@ public class TwistySkewb extends TwistyObject
       };
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void initializeQuats()
+    {
+    mQuats = new Static4D[]
+         {
+         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
+         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
+         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
+         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
+
+         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
+         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
+         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
+         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
+         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
+         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
+         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
+         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
+         };
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   int[] getSolvedQuats(int cubit, int numLayers)
     {
+    if( mQuats==null ) initializeQuats();
     int status = retCubitSolvedStatus(cubit,numLayers);
-    return status<0 ? null : buildSolvedQuats(MovementSkewb.FACE_AXIS[status],QUATS);
+    return status<0 ? null : buildSolvedQuats(MovementSkewb.FACE_AXIS[status],mQuats);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -251,7 +141,8 @@ public class TwistySkewb extends TwistyObject
 
   Static4D[] getQuats()
     {
-    return QUATS;
+    if( mQuats==null ) initializeQuats();
+    return mQuats;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -300,7 +191,7 @@ public class TwistySkewb extends TwistyObject
 
   int getNumCubitFaces()
     {
-    return FACES_PER_CUBIT;
+    return 6;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -435,6 +326,7 @@ public class TwistySkewb extends TwistyObject
 
   Static4D getQuat(int cubit, int numLayers)
     {
+    if( mQuats==null ) initializeQuats();
     int numCorners = getNumCorners();
     int numEdges   = getNumEdges(numLayers);
 
@@ -442,13 +334,13 @@ public class TwistySkewb extends TwistyObject
       {
       switch(cubit)
         {
-        case  0: return QUATS[0];                          //  unit quat
+        case  0: return mQuats[0];                         //  unit quat
         case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
         case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
-        case  3: return QUATS[1];                          // 180 along X
+        case  3: return mQuats[1];                         // 180 along X
         case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
-        case  5: return QUATS[2];                          // 180 along Y
-        case  6: return QUATS[3];                          // 180 along Z
+        case  5: return mQuats[2];                         // 180 along Y
+        case  6: return mQuats[3];                         // 180 along Z
         case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
         }
       }
@@ -458,18 +350,18 @@ public class TwistySkewb extends TwistyObject
 
       switch(edge)
         {
-        case  0: return QUATS[ 0];
-        case  1: return QUATS[ 5];
-        case  2: return QUATS[ 3];
-        case  3: return QUATS[11];
-        case  4: return QUATS[ 4];
-        case  5: return QUATS[ 7];
-        case  6: return QUATS[ 9];
-        case  7: return QUATS[10];
-        case  8: return QUATS[ 2];
-        case  9: return QUATS[ 8];
-        case 10: return QUATS[ 1];
-        case 11: return QUATS[ 6];
+        case  0: return mQuats[ 0];
+        case  1: return mQuats[ 5];
+        case  2: return mQuats[ 3];
+        case  3: return mQuats[11];
+        case  4: return mQuats[ 4];
+        case  5: return mQuats[ 7];
+        case  6: return mQuats[ 9];
+        case  7: return mQuats[10];
+        case  8: return mQuats[ 2];
+        case  9: return mQuats[ 8];
+        case 10: return mQuats[ 1];
+        case 11: return mQuats[ 6];
         }
       }
     else
@@ -482,8 +374,8 @@ public class TwistySkewb extends TwistyObject
         case 1: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
         case 2: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
         case 3: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
-        case 4: return QUATS[0];                          //  unit quaternion
-        case 5: return QUATS[1];                          // 180 along X
+        case 4: return mQuats[0];                         //  unit quaternion
+        case 5: return mQuats[1];                         // 180 along X
         }
       }
 
@@ -498,6 +390,8 @@ public class TwistySkewb extends TwistyObject
 
     if( variant==0 )
       {
+      double[][] vertices = new double[][] { {-0.5f, 0.0f, 0.0f},{ 0.0f,-0.5f, 0.0f},{ 0.0f, 0.0f,-0.5f},{-0.5f,-0.5f,-0.5f},{ 0.0f, 0.0f, 0.0f} };
+      int[][] vert_indices = new int[][] { {0,1,4},{2,0,4},{1,2,4},{3,1,0},{3,2,1},{3,0,2} };
       int N = numLayers==2 ? 7:5;
       int E1= numLayers==2 ? 3:2;
       int E2= numLayers==2 ? 5:3;
@@ -507,10 +401,12 @@ public class TwistySkewb extends TwistyObject
       int[] cornerIndices = new int[] { 1,1,1,0,0 };
       float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.25f} };
       int[] centerIndices = new int[] { 0,0,0,-1,0 };
-      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
+      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
       }
     else if( variant==1 )
       {
+      double[][] vertices = new double[][] { {-0.5, 0.0, 0.0},{ 0.5, 0.0, 0.0},{ 0.0,-0.5, 0.0},{ 0.0, 0.0,-0.5} };
+      int[][] vert_indices = new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
       int N = numLayers==2 ? 7:5;
       int E = numLayers==2 ? 5:2;
       float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,N,2,E}, {0.020f,45,0.16f,0.2f,3,1,2} };
@@ -519,10 +415,12 @@ public class TwistySkewb extends TwistyObject
       int[] cornerIndices = new int[] { 0,0,1,1 };
       float[][] centers   = new float[][] { {0.0f, -0.25f, -0.25f} };
       int[] centerIndices = new int[] { 0,0,0,0 };
-      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
+      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
       }
     else
       {
+      double[][] vertices = new double[][] { {-0.5f, 0.0f, 0.0f },{ 0.0f,-0.5f, 0.0f },{ 0.5f, 0.0f, 0.0f },{ 0.0f, 0.5f, 0.0f },{ 0.0f, 0.0f,-0.5f } };
+      int[][] vert_indices = new int[][] { {0,1,2,3},{4,1,0},{4,2,1},{4,3,2},{4,0,3} };
       int N = numLayers==2 ? 7:6;
       int E = numLayers==2 ? 3:1;
       float[][] bands     = new float[][] { {0.051f,35,SQ2/8,0.9f,N,E,E}, {0.000f,0,1,0.0f,3,0,0} };
@@ -531,7 +429,7 @@ public class TwistySkewb extends TwistyObject
       int[] cornerIndices = new int[] { 0,0,0,0,0 };
       float[][] centers   = new float[][] { {0,0,-0.2f} };
       int[] centerIndices = new int[] { 0,0,0,0,-1 };
-      return new ObjectShape(VERTICES_FACE,VERT_INDEXES_FACE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
+      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
       }
     }
 
@@ -556,6 +454,47 @@ public class TwistySkewb extends TwistyObject
 
   int getFaceColor(int cubit, int cubitface, int numLayers)
     {
+    if( mCornerMap==null || mEdgeMap==null || mCenterMap==null )
+      {
+      mCornerMap = new int[][]
+         {
+           {  4, 2, 0, 18,18,18 },
+           {  2, 5, 0, 18,18,18 },
+           {  3, 4, 0, 18,18,18 },
+           {  5, 3, 0, 18,18,18 },
+           {  1, 2, 4, 18,18,18 },
+           {  5, 2, 1, 18,18,18 },
+           {  4, 3, 1, 18,18,18 },
+           {  1, 3, 5, 18,18,18 },
+         };
+
+      mEdgeMap = new int[][]
+         {
+           { 10, 8, 18,18,18,18 },
+           {  6,10, 18,18,18,18 },
+           { 10, 9, 18,18,18,18 },
+           {  7,10, 18,18,18,18 },
+           {  8, 6, 18,18,18,18 },
+           {  9, 6, 18,18,18,18 },
+           {  9, 7, 18,18,18,18 },
+           {  8, 7, 18,18,18,18 },
+           { 11, 8, 18,18,18,18 },
+           {  6,11, 18,18,18,18 },
+           { 11, 9, 18,18,18,18 },
+           {  7,11, 18,18,18,18 }
+         };
+
+      mCenterMap = new int[][]
+         {
+           { 12, 18,18,18,18,18 },
+           { 13, 18,18,18,18,18 },
+           { 14, 18,18,18,18,18 },
+           { 15, 18,18,18,18,18 },
+           { 16, 18,18,18,18,18 },
+           { 17, 18,18,18,18,18 },
+         };
+      }
+
     int numCorners = getNumCorners();
     int numEdges   = getNumEdges(numLayers);
 
@@ -586,6 +525,29 @@ public class TwistySkewb extends TwistyObject
 
   ObjectSticker retSticker(int face)
     {
+    if( mStickers==null )
+      {
+      float[][] STICKERS = new float[][]
+          {
+             { -0.5f, 0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
+             { -0.5f, 0.00f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
+          };
+
+      final float R1 = 0.025f;
+      final float R2 = 0.025f;
+      final float R3 = 0.055f;
+      final float[][] radii  = { { R1,R1,R1 },{ R2,R2,R2 },{ R3,R3,R3,R3 } };
+      final float[] strokes = { 0.045f, 0.035f, 0.035f };
+
+      mStickers = new ObjectSticker[STICKERS.length+1];
+
+      for(int s=0; s<STICKERS.length+1; s++)
+        {
+        int index = s<2 ? 0:1;
+        mStickers[s] = new ObjectSticker(STICKERS[index],null,radii[s],strokes[s]);
+        }
+      }
+
     return mStickers[face/NUM_FACES];
     }
 
@@ -656,7 +618,8 @@ public class TwistySkewb extends TwistyObject
 
   public int[] getBasicAngle()
     {
-    return BASIC_ANGLE;
+    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
+    return mBasicAngle;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
