commit 1dd8d3af035ceaf1e2fe27be641b8726ddf6e9c5
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Sep 7 01:02:18 2021 +0200

    Remove statics from the Redi class.

diff --git a/src/main/java/org/distorted/objects/TwistyRedi.java b/src/main/java/org/distorted/objects/TwistyRedi.java
index 0b213eb9..dd9ffce9 100644
--- a/src/main/java/org/distorted/objects/TwistyRedi.java
+++ b/src/main/java/org/distorted/objects/TwistyRedi.java
@@ -37,9 +37,7 @@ import java.util.Random;
 
 public class TwistyRedi extends TwistyObject
 {
-  private static final int FACES_PER_CUBIT =9;
-
-  // the four rotation axis of a RubikRedi. Must be normalized.
+  // the four rotation axis of a Redi. Must be normalized.
   static final Static3D[] ROT_AXIS = new Static3D[]
          {
            new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
@@ -48,8 +46,6 @@ public class TwistyRedi 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,156 +53,18 @@ public class TwistyRedi extends TwistyObject
            COLOR_RED   , COLOR_ORANGE
          };
 
-  // All legal rotation quats of a RubikRedi
-  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 float DIST_CORNER = 1.0f;
-  private static final float DIST_EDGE   = 1.5f;
-
-  // centers of the 8 corners + 12 edges ( i.e. of the all 20 cubits)
-  private static final float[][] CENTERS = new float[][]
-         {
-             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
-             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
-             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
-             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
-             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
-             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
-             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
-             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
-
-             {      0.0f, DIST_EDGE, DIST_EDGE },
-             { DIST_EDGE,      0.0f, DIST_EDGE },
-             {      0.0f,-DIST_EDGE, DIST_EDGE },
-             {-DIST_EDGE,      0.0f, DIST_EDGE },
-             { DIST_EDGE, DIST_EDGE,      0.0f },
-             { DIST_EDGE,-DIST_EDGE,      0.0f },
-             {-DIST_EDGE,-DIST_EDGE,      0.0f },
-             {-DIST_EDGE, DIST_EDGE,      0.0f },
-             {      0.0f, DIST_EDGE,-DIST_EDGE },
-             { DIST_EDGE,      0.0f,-DIST_EDGE },
-             {      0.0f,-DIST_EDGE,-DIST_EDGE },
-             {-DIST_EDGE,      0.0f,-DIST_EDGE }
-         };
-
-  // Colors of the faces of cubits.
-  // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4  ORANGE 5
-  // YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 ORANGE 11
-  private static final int[][] mFaceMap = new int[][]
-         {
-           {  4, 2, 0 },
-           {  2, 5, 0 },
-           {  3, 4, 0 },
-           {  5, 3, 0 },
-           {  1, 2, 4 },
-           {  5, 2, 1 },
-           {  4, 3, 1 },
-           {  1, 3, 5 },
-
-           { 10, 8,12 },
-           {  6,10,12 },
-           { 10, 9,12 },
-           {  7,10,12 },
-           {  8, 6,12 },
-           {  9, 6,12 },
-           {  9, 7,12 },
-           {  8, 7,12 },
-           { 11, 8,12 },
-           {  6,11,12 },
-           { 11, 9,12 },
-           {  7,11,12 },
-         };
-
-  private static final double[][] VERTICES_CORNER = new double[][]
-          {
-             { 0.0f, 0.0f, 0.0f },
-             {-0.5f, 0.5f, 0.5f },
-             {-0.5f,-0.5f, 0.5f },
-             { 0.5f, 0.5f, 0.5f },
-             { 0.5f,-0.5f, 0.5f },
-             { 0.5f, 0.5f,-0.5f },
-             { 0.5f,-0.5f,-0.5f },
-             {-0.5f, 0.5f,-0.5f },
-          };
-
-  private static final int[][] VERT_INDEXES_CORNER = new int[][]
-          {
-             { 2,4,3,1 },
-             { 1,3,5,7 },
-             { 4,6,5,3 },
-
-             { 2,4,0 },
-             { 5,7,0 },
-             { 4,6,0 },
-             { 7,1,0 },
-             { 1,2,0 },
-             { 6,5,0 }
-          };
-
-  private static final double[][] VERTICES_EDGE = new double[][]
-          {
-             {-0.5f, 0.0f, 0.0f},
-             { 0.5f, 0.0f, 0.0f},
-             {-0.5f,-1.0f, 0.0f},
-             { 0.5f,-1.0f, 0.0f},
-             { 0.0f,-1.5f, 0.0f},
-             {-0.5f, 0.0f,-1.0f},
-             { 0.5f, 0.0f,-1.0f},
-             { 0.0f, 0.0f,-1.5f},
-          };
-
-  private static final int[][] VERT_INDEXES_EDGE = new int[][]
-          {
-             { 0,2,4,3,1 },
-             { 0,1,6,7,5 },
-             { 1,3,6 },
-             { 0,2,5 },
-             { 4,7,6,3 },
-             { 4,7,5,2 }
-          };
-
-  private static final float[][] STICKERS = new float[][]
-          {
-             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
-             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
-          };
-
-  private static final ObjectSticker[] mStickers;
-
-  static
-    {
-    mStickers = new ObjectSticker[STICKERS.length];
-    final float R0 = 0.09f;
-    final float R1 = 0.06f;
-    final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
-    final float[] strokes = { 0.09f,0.06f };
-
-    for(int s=0; s<STICKERS.length; s++)
-      {
-      mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
-      }
-    }
+  private static final int FACES_PER_CUBIT =9;
 
   private int mCurrState;
   private int mIndexExcluded;
   private final ScrambleState[] mStates;
   private int[][] mScrambleTable;
   private int[] mNumOccurences;
+  private int[] mBasicAngle;
+  private Static4D[] mQuats;
+  private float[][] mCenters;
+  private int[][] mFaceMap;
+  private ObjectSticker[] mStickers;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -229,12 +87,35 @@ public class TwistyRedi 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(MovementRedi.FACE_AXIS[status],QUATS);
+    return status<0 ? null : buildSolvedQuats(MovementRedi.FACE_AXIS[status],mQuats);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -248,7 +129,8 @@ public class TwistyRedi extends TwistyObject
 
   Static4D[] getQuats()
     {
-    return QUATS;
+    if( mQuats==null ) initializeQuats();
+    return mQuats;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -276,7 +158,7 @@ public class TwistyRedi extends TwistyObject
 
   int getNumStickerTypes(int numLayers)
     {
-    return STICKERS.length;
+    return 2;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -299,7 +181,38 @@ public class TwistyRedi extends TwistyObject
 
   float[][] getCubitPositions(int size)
     {
-    return CENTERS;
+    if( mCenters==null )
+      {
+      final float DIST_CORNER = 1.0f;
+      final float DIST_EDGE   = 1.5f;
+
+      mCenters = new float[][]
+         {
+             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
+             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
+             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
+             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
+             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
+             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
+             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
+             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
+
+             {      0.0f, DIST_EDGE, DIST_EDGE },
+             { DIST_EDGE,      0.0f, DIST_EDGE },
+             {      0.0f,-DIST_EDGE, DIST_EDGE },
+             {-DIST_EDGE,      0.0f, DIST_EDGE },
+             { DIST_EDGE, DIST_EDGE,      0.0f },
+             { DIST_EDGE,-DIST_EDGE,      0.0f },
+             {-DIST_EDGE,-DIST_EDGE,      0.0f },
+             {-DIST_EDGE, DIST_EDGE,      0.0f },
+             {      0.0f, DIST_EDGE,-DIST_EDGE },
+             { DIST_EDGE,      0.0f,-DIST_EDGE },
+             {      0.0f,-DIST_EDGE,-DIST_EDGE },
+             {-DIST_EDGE,      0.0f,-DIST_EDGE }
+         };
+      }
+
+    return mCenters;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -310,23 +223,71 @@ public class TwistyRedi extends TwistyObject
 
     if( variant==0 )
       {
+      double[][] vertices = new double[][]
+          {
+             { 0.0f, 0.0f, 0.0f },
+             {-0.5f, 0.5f, 0.5f },
+             {-0.5f,-0.5f, 0.5f },
+             { 0.5f, 0.5f, 0.5f },
+             { 0.5f,-0.5f, 0.5f },
+             { 0.5f, 0.5f,-0.5f },
+             { 0.5f,-0.5f,-0.5f },
+             {-0.5f, 0.5f,-0.5f },
+          };
+
+      int[][] vert_indices = new int[][]
+          {
+             { 2,4,3,1 },
+             { 1,3,5,7 },
+             { 4,6,5,3 },
+
+             { 2,4,0 },
+             { 5,7,0 },
+             { 4,6,0 },
+             { 7,1,0 },
+             { 1,2,0 },
+             { 6,5,0 }
+          };
+
       float[][] bands     = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
       int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
       float[][] corners   = new float[][] { {0.06f,0.12f} };
       int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
       float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
       int[] centerIndices = new int[] { -1,0,-1,0,0,0,-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
       {
+      double[][] vertices = new double[][]
+          {
+             {-0.5f, 0.0f, 0.0f},
+             { 0.5f, 0.0f, 0.0f},
+             {-0.5f,-1.0f, 0.0f},
+             { 0.5f,-1.0f, 0.0f},
+             { 0.0f,-1.5f, 0.0f},
+             {-0.5f, 0.0f,-1.0f},
+             { 0.5f, 0.0f,-1.0f},
+             { 0.0f, 0.0f,-1.5f},
+          };
+
+      int[][] vert_indices = new int[][]
+          {
+             { 0,2,4,3,1 },
+             { 0,1,6,7,5 },
+             { 1,3,6 },
+             { 0,2,5 },
+             { 4,7,6,3 },
+             { 4,7,5,2 }
+          };
+
       float[][] bands     = new float[][] { {0.038f,35,0.250f,0.7f,7,2,2}, {0.020f,35,0.125f,0.2f,3,1,2}, {0.020f,35,0.125f,0.2f,3,1,1} };
       int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
       float[][] corners   = new float[][] { {0.06f,0.20f} };
       int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
       float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
       int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
-      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);
       }
     }
 
@@ -334,29 +295,31 @@ public class TwistyRedi extends TwistyObject
 
   Static4D getQuat(int cubit, int numLayers)
     {
+    if( mQuats==null ) initializeQuats();
+
     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)
 
-      case  8: return QUATS[0];
-      case  9: return QUATS[5];
-      case 10: return QUATS[3];
-      case 11: return QUATS[11];
-      case 12: return QUATS[4];
-      case 13: return QUATS[7];
-      case 14: return QUATS[9];
-      case 15: return QUATS[10];
-      case 16: return QUATS[2];
-      case 17: return QUATS[8];
-      case 18: return QUATS[1];
-      case 19: return QUATS[6];
+      case  8: return mQuats[0];
+      case  9: return mQuats[5];
+      case 10: return mQuats[3];
+      case 11: return mQuats[11];
+      case 12: return mQuats[4];
+      case 13: return mQuats[7];
+      case 14: return mQuats[9];
+      case 15: return mQuats[10];
+      case 16: return mQuats[2];
+      case 17: return mQuats[8];
+      case 18: return mQuats[1];
+      case 19: return mQuats[6];
       }
 
     return null;
@@ -380,7 +343,38 @@ public class TwistyRedi extends TwistyObject
 
   int getFaceColor(int cubit, int cubitface, int size)
     {
-    return cubitface<3 ? mFaceMap[cubit][cubitface] : STICKERS.length*FACE_COLORS.length;
+    if( mFaceMap==null )
+      {
+      // Colors of the faces of cubits.
+      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4  ORANGE 5
+      // YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 ORANGE 11
+      mFaceMap = new int[][]
+         {
+           {  4, 2, 0 },
+           {  2, 5, 0 },
+           {  3, 4, 0 },
+           {  5, 3, 0 },
+           {  1, 2, 4 },
+           {  5, 2, 1 },
+           {  4, 3, 1 },
+           {  1, 3, 5 },
+
+           { 10, 8,12 },
+           {  6,10,12 },
+           { 10, 9,12 },
+           {  7,10,12 },
+           {  8, 6,12 },
+           {  9, 6,12 },
+           {  9, 7,12 },
+           {  8, 7,12 },
+           { 11, 8,12 },
+           {  6,11,12 },
+           { 11, 9,12 },
+           {  7,11,12 },
+         };
+      }
+
+    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -394,6 +388,27 @@ public class TwistyRedi extends TwistyObject
 
   ObjectSticker retSticker(int face)
     {
+    if( mStickers==null )
+      {
+      float[][] STICKERS = new float[][]
+          {
+             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
+             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
+          };
+
+      final float R0 = 0.09f;
+      final float R1 = 0.06f;
+      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
+      final float[] strokes = { 0.09f,0.06f };
+
+      mStickers = new ObjectSticker[STICKERS.length];
+
+      for(int s=0; s<STICKERS.length; s++)
+        {
+        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
+        }
+      }
+
     return mStickers[face/NUM_FACES];
     }
 
@@ -464,7 +479,8 @@ public class TwistyRedi extends TwistyObject
 
   public int[] getBasicAngle()
     {
-    return BASIC_ANGLE;
+    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
+    return mBasicAngle;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
