commit f242ba049456ec3679fd6703314976ca5acf7fa3
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Sep 7 01:09:36 2021 +0200

    Remove statics from the Rex class.

diff --git a/src/main/java/org/distorted/objects/TwistyRex.java b/src/main/java/org/distorted/objects/TwistyRex.java
index e260dbf1..3cb2b18e 100644
--- a/src/main/java/org/distorted/objects/TwistyRex.java
+++ b/src/main/java/org/distorted/objects/TwistyRex.java
@@ -37,10 +37,6 @@ import java.util.Random;
 
 public class TwistyRex extends TwistyObject
 {
-  private static final int FACES_PER_CUBIT =6;
-
-  public static final float REX_D = 0.2f;
-
   // the four rotation axis of a RubikRex. Must be normalized.
   static final Static3D[] ROT_AXIS = new Static3D[]
          {
@@ -50,8 +46,6 @@ public class TwistyRex 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,
@@ -59,105 +53,17 @@ public class TwistyRex extends TwistyObject
            COLOR_RED   , COLOR_ORANGE
          };
 
-  // All legal rotation quats of a RubikRex
-  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[][] mFaceMap =
-         {
-           {  0, 18,18,18,18,18 },
-           {  0, 18,18,18,18,18 },
-           {  0, 18,18,18,18,18 },
-           {  0, 18,18,18,18,18 },
-           {  1, 18,18,18,18,18 },
-           {  1, 18,18,18,18,18 },
-           {  1, 18,18,18,18,18 },
-           {  1, 18,18,18,18,18 },
-           {  2, 18,18,18,18,18 },
-           {  2, 18,18,18,18,18 },
-           {  2, 18,18,18,18,18 },
-           {  2, 18,18,18,18,18 },
-           {  3, 18,18,18,18,18 },
-           {  3, 18,18,18,18,18 },
-           {  3, 18,18,18,18,18 },
-           {  3, 18,18,18,18,18 },
-           {  4, 18,18,18,18,18 },
-           {  4, 18,18,18,18,18 },
-           {  4, 18,18,18,18,18 },
-           {  4, 18,18,18,18,18 },
-           {  5, 18,18,18,18,18 },
-           {  5, 18,18,18,18,18 },
-           {  5, 18,18,18,18,18 },
-           {  5, 18,18,18,18,18 },
-
-           {  6, 18,18,18,18,18 },
-           {  7, 18,18,18,18,18 },
-           {  8, 18,18,18,18,18 },
-           {  9, 18,18,18,18,18 },
-           { 10, 18,18,18,18,18 },
-           { 11, 18,18,18,18,18 },
-
-           { 16,14, 18,18,18,18 },
-           { 16,12, 18,18,18,18 },
-           { 16,15, 18,18,18,18 },
-           { 16,13, 18,18,18,18 },
-           { 12,14, 18,18,18,18 },
-           { 15,12, 18,18,18,18 },
-           { 15,13, 18,18,18,18 },
-           { 13,14, 18,18,18,18 },
-           { 14,17, 18,18,18,18 },
-           { 12,17, 18,18,18,18 },
-           { 17,15, 18,18,18,18 },
-           { 13,17, 18,18,18,18 },
-         };
-
-  private static final ObjectSticker[] mStickers;
-
-  private static final float[][] STICKERS = new float[][]
-          {
-             { -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
-             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
-             { -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f  }
-          };
-  private static final int NUM_STICKERS = STICKERS.length;
-
-  static
-    {
-    mStickers = new ObjectSticker[NUM_STICKERS];
-
-    final float F = (float)(Math.PI/20);
-    final float R1= 0.02f;
-    final float R2= 0.09f;
-    final float R3= 0.06f;
-    final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
-    final float[][] radii  = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
-    final float[] strokes = { 0.06f, 0.07f, 0.05f };
-
-    for(int s=0; s<NUM_STICKERS; s++)
-      {
-      mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]);
-      }
-    }
+  public static final float REX_D = 0.2f;
 
   private int mCurrState;
   private int mIndexExcluded;
   private final ScrambleState[] mStates;
   private int[][] mScrambleTable;
   private int[] mNumOccurences;
+  private int[] mBasicAngle;
+  private Static4D[] mQuats;
+  private int[][] mFaceMap;
+  private ObjectSticker[] mStickers;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -174,12 +80,35 @@ public class TwistyRex 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(MovementRex.FACE_AXIS[status],QUATS);
+    return status<0 ? null : buildSolvedQuats(MovementRex.FACE_AXIS[status],mQuats);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -193,7 +122,8 @@ public class TwistyRex extends TwistyObject
 
   Static4D[] getQuats()
     {
-    return QUATS;
+    if( mQuats==null ) initializeQuats();
+    return mQuats;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -221,7 +151,7 @@ public class TwistyRex extends TwistyObject
 
   int getNumStickerTypes(int numLayers)
     {
-    return NUM_STICKERS;
+    return 3;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -237,7 +167,7 @@ public class TwistyRex extends TwistyObject
 
   int getNumCubitFaces()
     {
-    return FACES_PER_CUBIT;
+    return 6;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -385,55 +315,57 @@ public class TwistyRex extends TwistyObject
 
   Static4D getQuat(int cubit, int numLayers)
     {
+    if( mQuats==null ) initializeQuats();
+
     switch(cubit)
       {
       case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
-      case  1: return QUATS[5];
+      case  1: return mQuats[5];
       case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
-      case  3: return QUATS[8];
-      case  4: return QUATS[6];
+      case  3: return mQuats[8];
+      case  4: return mQuats[6];
       case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
-      case  6: return QUATS[11];
+      case  6: return mQuats[11];
       case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
       case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
-      case  9: return QUATS[10];
+      case  9: return mQuats[10];
       case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
-      case 11: return QUATS[4];
-      case 12: return QUATS[9];
+      case 11: return mQuats[4];
+      case 12: return mQuats[9];
       case 13: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
-      case 14: return QUATS[7];
+      case 14: return mQuats[7];
       case 15: return new Static4D(     0,-SQ2/2,+SQ2/2,     0);
       case 16: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
-      case 17: return QUATS[0];
+      case 17: return mQuats[0];
       case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
-      case 19: return QUATS[3];
-      case 20: return QUATS[1];
+      case 19: return mQuats[3];
+      case 20: return mQuats[1];
       case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
-      case 22: return QUATS[2];
+      case 22: return mQuats[2];
       case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
 
       case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
       case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
       case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
       case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
-      case 28: return QUATS[0];
-      case 29: return QUATS[1];
+      case 28: return mQuats[0];
+      case 29: return mQuats[1];
 
-      case 30: return QUATS[0];
+      case 30: return mQuats[0];
       case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
-      case 32: return QUATS[3];
+      case 32: return mQuats[3];
       case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
       case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
-      case 35: return QUATS[7];
-      case 36: return QUATS[9];
+      case 35: return mQuats[7];
+      case 36: return mQuats[9];
       case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
       case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
-      case 39: return QUATS[8];
-      case 40: return QUATS[1];
-      case 41: return QUATS[6];
+      case 39: return mQuats[8];
+      case 40: return mQuats[1];
+      case 41: return mQuats[6];
       }
 
-    return QUATS[0];
+    return mQuats[0];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -454,6 +386,57 @@ public class TwistyRex extends TwistyObject
 
   int getFaceColor(int cubit, int cubitface, int numLayers)
     {
+    if( mFaceMap==null )
+      {
+      mFaceMap = new int[][]
+         {
+           {  0, 18,18,18,18,18 },
+           {  0, 18,18,18,18,18 },
+           {  0, 18,18,18,18,18 },
+           {  0, 18,18,18,18,18 },
+           {  1, 18,18,18,18,18 },
+           {  1, 18,18,18,18,18 },
+           {  1, 18,18,18,18,18 },
+           {  1, 18,18,18,18,18 },
+           {  2, 18,18,18,18,18 },
+           {  2, 18,18,18,18,18 },
+           {  2, 18,18,18,18,18 },
+           {  2, 18,18,18,18,18 },
+           {  3, 18,18,18,18,18 },
+           {  3, 18,18,18,18,18 },
+           {  3, 18,18,18,18,18 },
+           {  3, 18,18,18,18,18 },
+           {  4, 18,18,18,18,18 },
+           {  4, 18,18,18,18,18 },
+           {  4, 18,18,18,18,18 },
+           {  4, 18,18,18,18,18 },
+           {  5, 18,18,18,18,18 },
+           {  5, 18,18,18,18,18 },
+           {  5, 18,18,18,18,18 },
+           {  5, 18,18,18,18,18 },
+
+           {  6, 18,18,18,18,18 },
+           {  7, 18,18,18,18,18 },
+           {  8, 18,18,18,18,18 },
+           {  9, 18,18,18,18,18 },
+           { 10, 18,18,18,18,18 },
+           { 11, 18,18,18,18,18 },
+
+           { 16,14, 18,18,18,18 },
+           { 16,12, 18,18,18,18 },
+           { 16,15, 18,18,18,18 },
+           { 16,13, 18,18,18,18 },
+           { 12,14, 18,18,18,18 },
+           { 15,12, 18,18,18,18 },
+           { 15,13, 18,18,18,18 },
+           { 13,14, 18,18,18,18 },
+           { 14,17, 18,18,18,18 },
+           { 12,17, 18,18,18,18 },
+           { 17,15, 18,18,18,18 },
+           { 13,17, 18,18,18,18 },
+         };
+      }
+
     return mFaceMap[cubit][cubitface];
     }
 
@@ -468,6 +451,31 @@ public class TwistyRex extends TwistyObject
 
   ObjectSticker retSticker(int face)
     {
+    if( mStickers==null )
+      {
+      float[][] STICKERS = new float[][]
+          {
+             { -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
+             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
+             { -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f  }
+          };
+
+      final float F = (float)(Math.PI/20);
+      final float R1= 0.02f;
+      final float R2= 0.09f;
+      final float R3= 0.06f;
+      final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
+      final float[][] radii  = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
+      final float[] strokes = { 0.06f, 0.07f, 0.05f };
+
+      mStickers = new ObjectSticker[STICKERS.length];
+
+      for(int s=0; s<STICKERS.length; s++)
+        {
+        mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]);
+        }
+      }
+
     return mStickers[face/NUM_FACES];
     }
 
@@ -538,7 +546,8 @@ public class TwistyRex extends TwistyObject
 
   public int[] getBasicAngle()
     {
-    return BASIC_ANGLE;
+    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
+    return mBasicAngle;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
