commit 4f8cda8050c8a02204e8aadca4442dd70391b3f0
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Sep 6 23:45:15 2021 +0200

    Remove statics from the Jing class.

diff --git a/src/main/java/org/distorted/objects/TwistyJing.java b/src/main/java/org/distorted/objects/TwistyJing.java
index f4a3f322..497a9648 100644
--- a/src/main/java/org/distorted/objects/TwistyJing.java
+++ b/src/main/java/org/distorted/objects/TwistyJing.java
@@ -37,10 +37,6 @@ import java.util.Random;
 
 public class TwistyJing extends TwistyObject
 {
-  static final float F = 0.24f;  // length of the edge of the corner cubit divided by
-                                 // the length of the edge of the whole tetrahedron.
-                                 // keep < 0.25.
-
   static final Static3D[] ROT_AXIS = new Static3D[]
          {
            new Static3D(     0,-SQ3/3,-SQ6/3),
@@ -49,178 +45,27 @@ public class TwistyJing extends TwistyObject
            new Static3D(-SQ6/3,+SQ3/3,     0),
          };
 
-  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
-
   private static final int[] FACE_COLORS = new int[]
          {
            COLOR_GREEN , COLOR_YELLOW,
            COLOR_BLUE  , COLOR_RED
          };
 
-  private static final int[] ROT_QUAT = {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
-
-  // computed with res/raw/compute_quats.c
-  private static final Static4D[] QUATS = new Static4D[]
-         {
-           new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
-           new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
-           new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
-           new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
-           new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
-           new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
-           new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
-           new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
-           new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
-           new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
-           new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
-           new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
-         };
-
-  static final float[][] CENTERS = new float[][]
-         {
-           { 0.000f, -SQ2/4, 0.500f },
-           { 0.000f, -SQ2/4,-0.500f },
-           {-0.500f,  SQ2/4, 0.000f },
-           { 0.500f,  SQ2/4, 0.000f },
-
-           { 0.000f, -SQ2/4, 0.000f },
-           {-0.250f, 0.000f, 0.250f },
-           { 0.250f, 0.000f, 0.250f },
-           {-0.250f, 0.000f,-0.250f },
-           { 0.250f, 0.000f,-0.250f },
-           { 0.000f,  SQ2/4, 0.000f },
-
-           { 0.000f, SQ2/12, 1.0f/6 },
-           { 0.000f, SQ2/12,-1.0f/6 },
-           {-1.0f/6,-SQ2/12, 0.000f },
-           { 1.0f/6,-SQ2/12, 0.000f },
-         };
-
-  // Colors of the faces of cubits.
-  // GREEN 0 YELLOW 1 BLUE  2 RED 3
-  // GREEN 4 YELLOW 5 BLUE  6 RED 7
-  // GREEN 8 YELLOW 9 BLUE 10 RED 11
-  private static final int[][] mFaceMap = new int[][]
-         {
-           {  0,  3,  2, 12, 12, 12 },
-           {  1,  2,  3, 12, 12, 12 },
-           {  1,  0,  2, 12, 12, 12 },
-           {  1,  3,  0, 12, 12, 12 },
-
-           {  7,  6, 12, 12, 12, 12 },
-           {  4,  6, 12, 12, 12, 12 },
-           {  7,  4, 12, 12, 12, 12 },
-           {  5,  6, 12, 12, 12, 12 },
-           {  7,  5, 12, 12, 12, 12 },
-           {  4,  5, 12, 12, 12, 12 },
-
-           {  8, 12, 12, 12, 12, 12 },
-           {  9, 12, 12, 12, 12, 12 },
-           { 10, 12, 12, 12, 12, 12 },
-           { 11, 12, 12, 12, 12, 12 },
-         };
-
-  private static final float X = F/2;
-  private static final float Y = F*SQ2/2;
-  private static final float Z =-F/2;
-  private static final float L = (1-3*F);
-  private static final float X2= L/2;
-  private static final float Y2= L*SQ2/2;
-  private static final float Z2=-L/2;
-  private static final float D = F/L;
-
-  private static final double[][] VERTICES_CORNER = new double[][]
-          {
-             { 0.0, 0.0, 0.0 },
-             {   X,   Y,   Z },
-             { 0.0, 2*Y, 2*Z },
-             {  -X,   Y,   Z },
-             { 0.0, 0.0,    -F },
-             {   X,   Y,   Z-F },
-             { 0.0, 2*Y, 2*Z-F },
-             {  -X,   Y,   Z-F },
-          };
-
-  private static final int[][] VERT_INDEXES_CORNER = new int[][]
-          {
-             {0,1,2,3},
-             {1,0,4,5},
-             {7,4,0,3},
-             {1,5,6,2},
-             {7,3,2,6},
-             {4,7,6,5}
-          };
-
-  private static final double[][] VERTICES_EDGE = new double[][]
-          {
-             { 0.0, 0.0,     0.5-F },
-             {   X,   Y,   Z+0.5-F },
-             { 0.0, 2*Y, 2*Z+0.5-F },
-             {  -X,   Y,   Z+0.5-F },
-             { 0.0, 0.0,    -0.5+F },
-             {   X,   Y,  -Z-0.5+F },
-             { 0.0, 2*Y,-2*Z-0.5+F },
-             {  -X,   Y,  -Z-0.5+F },
-          };
-
-  private static final int[][] VERT_INDEXES_EDGE = new int[][]
-          {
-             {0,4,5,1},
-             {3,7,4,0},
-             {0,1,2,3},
-             {4,7,6,5},
-             {1,5,6,2},
-             {2,6,7,3}
-          };
-
-  private static final double[][] VERTICES_FACE = new double[][]
-          {
-             {    0.0,     -2*Y2/3,   -2*Z2/3 },
-             {      X2,       Y2/3,      Z2/3 },
-             {     -X2,       Y2/3,      Z2/3 },
-             {    0.0,     -2*Y2/3,-2*Z2/3+2*D*Z2 },
-             {  X2-D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
-             { -X2+D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
-          };
-
-  private static final int[][] VERT_INDEXES_FACE = new int[][]
-          {
-             {0,1,2},
-             {3,5,4},
-             {0,3,4,1},
-             {5,3,0,2},
-             {4,5,2,1}
-          };
-
-  private static final float[][] STICKERS = new float[][]
-          {
-             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
-             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
-             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
-          };
-
-  private static final ObjectSticker[] mStickers;
-
-  static
-    {
-    mStickers = new ObjectSticker[STICKERS.length];
-    final float R1 = 0.05f;
-    final float R2 = 0.10f;
-    final float R3 = 0.03f;
-    final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
-    final float[] strokes = { 0.06f, 0.03f, 0.05f };
-
-    for(int s=0; s<STICKERS.length; s++)
-      {
-      mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
-      }
-    }
+  static final float F = 0.24f;  // length of the edge of the corner cubit divided by
+                                 // the length of the edge of the whole tetrahedron.
+                                 // keep < 0.25.
 
   private int mCurrState;
   private int mIndexExcluded;
   private final ScrambleState[] mStates;
   private int[][] mScrambleTable;
   private int[] mNumOccurences;
+  private int[] mBasicAngle;
+  private int[] mRotQuat;
+  private Static4D[] mQuats;
+  private float[][] mCenters;
+  private int[][] mFaceMap;
+  private ObjectSticker[] mStickers;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -237,26 +82,72 @@ public class TwistyJing extends TwistyObject
       };
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void initializeQuats()
+    {
+    mQuats = new Static4D[]
+         {
+         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
+         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
+         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
+         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
+         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
+         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
+         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
+         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
+         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
+         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
+         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
+         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
+         };
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   int[] getSolvedQuats(int cubit, int numLayers)
     {
+    if( mQuats==null ) initializeQuats();
     int status = retCubitSolvedStatus(cubit,numLayers);
-    return status<0 ? null : buildSolvedQuats(MovementJing.FACE_AXIS[status],QUATS);
+    return status<0 ? null : buildSolvedQuats(MovementJing.FACE_AXIS[status],mQuats);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   float[][] getCubitPositions(int size)
     {
-    return CENTERS;
+    if( mCenters==null )
+      {
+      mCenters = new float[][]
+         {
+           { 0.000f, -SQ2/4, 0.500f },
+           { 0.000f, -SQ2/4,-0.500f },
+           {-0.500f,  SQ2/4, 0.000f },
+           { 0.500f,  SQ2/4, 0.000f },
+
+           { 0.000f, -SQ2/4, 0.000f },
+           {-0.250f, 0.000f, 0.250f },
+           { 0.250f, 0.000f, 0.250f },
+           {-0.250f, 0.000f,-0.250f },
+           { 0.250f, 0.000f,-0.250f },
+           { 0.000f,  SQ2/4, 0.000f },
+
+           { 0.000f, SQ2/12, 1.0f/6 },
+           { 0.000f, SQ2/12,-1.0f/6 },
+           {-1.0f/6,-SQ2/12, 0.000f },
+           { 1.0f/6,-SQ2/12, 0.000f },
+         };
+      }
+
+    return mCenters;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   Static4D[] getQuats()
     {
-    return QUATS;
+    if( mQuats==null ) initializeQuats();
+    return mQuats;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -277,7 +168,7 @@ public class TwistyJing extends TwistyObject
 
   int getNumStickerTypes(int numLayers)
     {
-    return STICKERS.length;
+    return 3;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -313,6 +204,33 @@ public class TwistyJing extends TwistyObject
 
   int getFaceColor(int cubit, int cubitface, int size)
     {
+    if( mFaceMap==null )
+      {
+      // Colors of the faces of cubits.
+      // GREEN 0 YELLOW 1 BLUE  2 RED 3
+      // GREEN 4 YELLOW 5 BLUE  6 RED 7
+      // GREEN 8 YELLOW 9 BLUE 10 RED 11
+      mFaceMap = new int[][]
+         {
+           {  0,  3,  2, 12, 12, 12 },
+           {  1,  2,  3, 12, 12, 12 },
+           {  1,  0,  2, 12, 12, 12 },
+           {  1,  3,  0, 12, 12, 12 },
+
+           {  7,  6, 12, 12, 12, 12 },
+           {  4,  6, 12, 12, 12, 12 },
+           {  7,  4, 12, 12, 12, 12 },
+           {  5,  6, 12, 12, 12, 12 },
+           {  7,  5, 12, 12, 12, 12 },
+           {  4,  5, 12, 12, 12, 12 },
+
+           {  8, 12, 12, 12, 12, 12 },
+           {  9, 12, 12, 12, 12, 12 },
+           { 10, 12, 12, 12, 12, 12 },
+           { 11, 12, 12, 12, 12, 12 },
+         };
+      }
+
     return mFaceMap[cubit][cubitface];
     }
 
@@ -322,35 +240,104 @@ public class TwistyJing extends TwistyObject
     {
     int variant = getCubitVariant(cubit,numLayers);
 
+    final float X = F/2;
+    final float Y = F*SQ2/2;
+    final float Z =-F/2;
+    final float L = (1-3*F);
+    final float X2= L/2;
+    final float Y2= L*SQ2/2;
+    final float Z2=-L/2;
+    final float D = F/L;
+
     if( variant==0 )
       {
+      double[][] vertices = new double[][]
+          {
+             { 0.0, 0.0, 0.0 },
+             {   X,   Y,   Z },
+             { 0.0, 2*Y, 2*Z },
+             {  -X,   Y,   Z },
+             { 0.0, 0.0,    -F },
+             {   X,   Y,   Z-F },
+             { 0.0, 2*Y, 2*Z-F },
+             {  -X,   Y,   Z-F },
+          };
+      int[][] vert_indices = new int[][]
+          {
+             {0,1,2,3},
+             {1,0,4,5},
+             {7,4,0,3},
+             {1,5,6,2},
+             {7,3,2,6},
+             {4,7,6,5}
+          };
+
       float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
       int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
       float[][] corners   = new float[][] { {0.08f,0.20f*F},{0.07f,0.20f*F} };
       int[] cornerIndices = new int[] { 0,1,1,-1,1,-1,-1,-1 };
       float[][] centers   = new float[][] { { 0.0f, F*SQ2/2, -F} };
       int[] centerIndices = new int[] { 0,0,0,-1,0,-1,-1,-1 };
-      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.0, 0.0,     0.5-F },
+             {   X,   Y,   Z+0.5-F },
+             { 0.0, 2*Y, 2*Z+0.5-F },
+             {  -X,   Y,   Z+0.5-F },
+             { 0.0, 0.0,    -0.5+F },
+             {   X,   Y,  -Z-0.5+F },
+             { 0.0, 2*Y,-2*Z-0.5+F },
+             {  -X,   Y,  -Z-0.5+F },
+          };
+      int[][] vert_indices = new int[][]
+          {
+             {0,4,5,1},
+             {3,7,4,0},
+             {0,1,2,3},
+             {4,7,6,5},
+             {1,5,6,2},
+             {2,6,7,3}
+          };
+
       float[][] bands     = new float[][] { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
       int[] bandIndices   = new int[] { 0,0,1,1,1,1 };
       float[][] corners   = new float[][] { {0.07f,0.20f*F} };
       int[] cornerIndices = new int[] { 0,0,-1,0,0,0,-1,0 };
       float[][] centers   = new float[][] { { 0, F*SQ2/2, 0 } };
       int[] centerIndices = new int[] { 0,0,-1,0,0,0,-1,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.0,     -2*Y2/3,   -2*Z2/3 },
+             {      X2,       Y2/3,      Z2/3 },
+             {     -X2,       Y2/3,      Z2/3 },
+             {    0.0,     -2*Y2/3,-2*Z2/3+2*D*Z2 },
+             {  X2-D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
+             { -X2+D*X2, Y2/3-D*Y2, Z2/3+D*Z2 },
+          };
+      int[][] vert_indices = new int[][]
+          {
+             {0,1,2},
+             {3,5,4},
+             {0,3,4,1},
+             {5,3,0,2},
+             {4,5,2,1}
+          };
+
       float[][] bands     = new float[][] { {0.020f,35,0.20f*(1-3*F),0.6f*(1-3*F),5,1,1}, {0.001f,35,0.05f*(1-3*F),0.1f*(1-3*F),5,1,1} };
       int[] bandIndices   = new int[] { 0,1,1,1,1,1 };
       float[][] corners   = new float[][] { {0.04f,0.15f} };
       int[] cornerIndices = new int[] { 0,0,0,-1,-1,-1 };
       float[][] centers   = new float[][] { { 0, -2*Y/3, 4*Z/3 } };
       int[] centerIndices = new int[] { 0,0,0,-1,-1,-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);
       }
     }
 
@@ -358,7 +345,9 @@ public class TwistyJing extends TwistyObject
 
   Static4D getQuat(int cubit, int numLayers)
     {
-    return QUATS[ROT_QUAT[cubit]];
+    if( mQuats==null ) initializeQuats();
+    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
+    return mQuats[mRotQuat[cubit]];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -386,6 +375,28 @@ public class TwistyJing extends TwistyObject
 
   ObjectSticker retSticker(int face)
     {
+    if( mStickers==null )
+      {
+      float[][] STICKERS = new float[][]
+          {
+             { 0.0f, -0.5f, 0.28867516f, 0.0f, 0.0f, 0.5f, -0.28867516f, 0.0f },
+             { -0.5f, 0.11983269f, 0.27964598f, -0.43146032f, 0.3200817f, 0.007388768f, -0.09972769f, 0.30423886f },
+             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
+          };
+
+      mStickers = new ObjectSticker[STICKERS.length];
+      final float R1 = 0.05f;
+      final float R2 = 0.10f;
+      final float R3 = 0.03f;
+      final float[][] radii  = { { R1,R1,R1,R1 },{ R3,R3,R2,R2 },{ R1,R1,R1 } };
+      final float[] strokes = { 0.06f, 0.03f, 0.05f };
+
+      for(int s=0; s<STICKERS.length; s++)
+        {
+        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
+        }
+      }
+
     return mStickers[face/NUM_FACES];
     }
 
@@ -457,7 +468,8 @@ public class TwistyJing extends TwistyObject
 
   public int[] getBasicAngle()
     {
-    return BASIC_ANGLE;
+    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
+    return mBasicAngle;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
