commit aec5cc9143ab56ec65e271aaa2f9386473cafede
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Sep 6 22:42:03 2021 +0200

    Remove statics from the Diamond classes.

diff --git a/src/main/java/org/distorted/objects/TwistyDiamond.java b/src/main/java/org/distorted/objects/TwistyDiamond.java
index 9e2067e9..d7ea3871 100644
--- a/src/main/java/org/distorted/objects/TwistyDiamond.java
+++ b/src/main/java/org/distorted/objects/TwistyDiamond.java
@@ -37,8 +37,6 @@ import java.util.Random;
 
 public class TwistyDiamond extends TwistyObject
 {
-  private static final int FACES_PER_CUBIT =8;
-
   // the four rotation axis of a Diamond. Must be normalized.
   static final Static3D[] ROT_AXIS = new Static3D[]
          {
@@ -48,8 +46,6 @@ public class TwistyDiamond extends TwistyObject
            new Static3D(     0,-SQ3/3,+SQ6/3)
          };
 
-  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
-
   private static final int[] FACE_COLORS = new int[]
          {
            COLOR_ORANGE, COLOR_VIOLET,
@@ -58,89 +54,19 @@ public class TwistyDiamond extends TwistyObject
            COLOR_GREEN , COLOR_GREY
          };
 
-  private static final int[] mFaceMap = new int[] {4,0,6,2,7,3,5,1};
-
-  // All legal rotation quats of a Diamond: unit + three 180 deg turns + 8 generators
-  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.0f, -SQ2/2,  0.0f ),
-           new Static4D(-SQ2/2,  0.0f, -SQ2/2,  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 )
-         };
-
   private static final float DIST = 0.50f;
-
-  private static final int[] mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
-
-  private static final double[][] VERTICES_TETRA = new double[][]
-          {
-             {-0.5, SQ2/4, 0.0},
-             { 0.5, SQ2/4, 0.0},
-             { 0.0,-SQ2/4, 0.5},
-             { 0.0,-SQ2/4,-0.5}
-          };
-
-  private static final int[][] VERT_INDEXES_TETRA = new int[][]
-          {
-             {2,1,0},   // counterclockwise!
-             {2,3,1},
-             {3,2,0},
-             {3,0,1}
-          };
-
-  private static final double[][] VERTICES_OCTA = new double[][]
-          {
-             { 0.5,   0.0, 0.5},
-             { 0.5,   0.0,-0.5},
-             {-0.5,   0.0,-0.5},
-             {-0.5,   0.0, 0.5},
-             { 0.0, SQ2/2, 0.0},
-             { 0.0,-SQ2/2, 0.0}
-          };
-
-  private static final int[][] VERT_INDEXES_OCTA = new int[][]
-          {
-             {3,0,4},   // counterclockwise!
-             {0,1,4},
-             {1,2,4},
-             {2,3,4},
-             {5,0,3},
-             {5,1,0},
-             {5,2,1},
-             {5,3,2}
-          };
-
-  private static final float[][] STICKERS = new float[][]
-          {
-             { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f }
-          };
-
-  private static final ObjectSticker[] mStickers;
-
-  static
-    {
-    float radius = 0.06f;
-    float stroke = 0.07f;
-    float[] radii = new float[] {radius,radius,radius};
-    mStickers = new ObjectSticker[STICKERS.length];
-    mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
-    }
+  private static final int FACES_PER_CUBIT =8;
 
   private int mCurrState;
   private int mIndexExcluded;
   private final ScrambleState[] mStates;
   private int[][] mScrambleTable;
   private int[] mNumOccurences;
+  private int[] mBasicAngle;
+  private int[] mFaceMap;
+  private Static4D[] mQuats;
+  private int[] mTetraToFaceMap;
+  private ObjectSticker[] mStickers;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -164,12 +90,36 @@ public class TwistyDiamond 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.0f, -SQ2/2,  0.0f ),
+          new Static4D(-SQ2/2,  0.0f, -SQ2/2,  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 )
+         };
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   int[] getSolvedQuats(int cubit, int numLayers)
     {
+    if( mQuats==null ) initializeQuats();
+    if( mFaceMap==null ) mFaceMap = new int[] {4,0,6,2,7,3,5,1};
     int status = retCubitSolvedStatus(cubit,numLayers);
-    return status<0 ? null : buildSolvedQuats(MovementDiamond.FACE_AXIS[mFaceMap[status]],QUATS);
+    return status<0 ? null : buildSolvedQuats(MovementDiamond.FACE_AXIS[mFaceMap[status]],mQuats);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -183,7 +133,8 @@ public class TwistyDiamond extends TwistyObject
 
   Static4D[] getQuats()
     {
-    return QUATS;
+    if( mQuats==null ) initializeQuats();
+    return mQuats;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -211,7 +162,7 @@ public class TwistyDiamond extends TwistyObject
 
   int getNumStickerTypes(int numLayers)
     {
-    return STICKERS.length;
+    return 1;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -391,6 +342,8 @@ public class TwistyDiamond extends TwistyObject
 
   private int retFaceTetraBelongsTo(int tetra, int numLayers)
     {
+    if( mTetraToFaceMap==null ) mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
+
     for(int i=numLayers-1; i>0; i--)
       {
       if( tetra < 8*i ) return mTetraToFaceMap[tetra/i];
@@ -410,23 +363,47 @@ public class TwistyDiamond extends TwistyObject
 
     if( variant==0 )
       {
+      double[][] vertices = new double[][]
+          {
+             { 0.5,   0.0, 0.5},
+             { 0.5,   0.0,-0.5},
+             {-0.5,   0.0,-0.5},
+             {-0.5,   0.0, 0.5},
+             { 0.0, SQ2/2, 0.0},
+             { 0.0,-SQ2/2, 0.0}
+          };
+
+      int[][] vert_indices = new int[][]
+          {
+             {3,0,4},
+             {0,1,4},
+             {1,2,4},
+             {2,3,4},
+             {5,0,3},
+             {5,1,0},
+             {5,2,1},
+             {5,3,2}
+          };
+
       float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
       int[] bandIndices   = new int[] { 0,0,0,0,0,0,0,0 };
       float[][] corners   = new float[][] { {0.04f,0.20f} };
       int[] cornerIndices = new int[] { 0,0,0,0,0,0 };
       float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
       int[] centerIndices = new int[] { 0,0,0,0,0,0 };
-      return new ObjectShape(VERTICES_OCTA,VERT_INDEXES_OCTA,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.5, SQ2/4, 0.0}, { 0.5, SQ2/4, 0.0}, { 0.0,-SQ2/4, 0.5}, { 0.0,-SQ2/4,-0.5} };
+      int[][] vert_indices = new int[][]  { {2,1,0}, {2,3,1}, {3,2,0}, {3,0,1} };
       float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
       int[] bandIndices   = new int[] { 0,0,0,0 };
       float[][] corners   = new float[][] { {0.08f,0.15f} };
       int[] cornerIndices = new int[] { 0,0,0,0 };
       float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
       int[] centerIndices = new int[] { 0,0,0,0 };
-      return new ObjectShape(VERTICES_TETRA,VERT_INDEXES_TETRA,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
+      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
       }
     }
 
@@ -434,15 +411,16 @@ public class TwistyDiamond extends TwistyObject
 
   Static4D getQuat(int cubit, int numLayers)
     {
+    if( mQuats==null ) initializeQuats();
     int numO = getNumOctahedrons(numLayers);
 
-    if( cubit<numO ) return QUATS[0];
+    if( cubit<numO ) return mQuats[0];
 
     switch( retFaceTetraBelongsTo(cubit-numO, numLayers) )
       {
-      case 0: return QUATS[0];                          // unit quat
+      case 0: return mQuats[0];                         // unit quat
       case 1: return new Static4D(0,-SQ2/2,0,SQ2/2);    //  90 along Y
-      case 2: return QUATS[1];                          // 180 along Y
+      case 2: return mQuats[1];                         // 180 along Y
       case 3: return new Static4D(0,+SQ2/2,0,SQ2/2);    //  90 along
       case 4: return new Static4D(0,     0,1,    0);    // 180 along Z
       case 5: return new Static4D(SQ2/2, 0,SQ2/2,0);    //
@@ -509,6 +487,16 @@ public class TwistyDiamond extends TwistyObject
 
   ObjectSticker retSticker(int face)
     {
+    if( mStickers==null )
+      {
+      float[][] STICKERS = new float[][] { { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f } };
+      float radius = 0.06f;
+      float stroke = 0.07f;
+      float[] radii = new float[] {radius,radius,radius};
+      mStickers     = new ObjectSticker[STICKERS.length];
+      mStickers[0]  = new ObjectSticker(STICKERS[0],null,radii,stroke);
+      }
+
     return mStickers[face/NUM_FACES];
     }
 
@@ -579,7 +567,8 @@ public class TwistyDiamond extends TwistyObject
 
   public int[] getBasicAngle()
     {
-    return BASIC_ANGLE;
+    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
+    return mBasicAngle;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
