commit f6d06256f9db63a639d3a6fac32f6cb324d6bfa7
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sat Aug 8 00:09:33 2020 +0100

    Move the knowledge about colors of individual cubit faces down to each Object subclass.

diff --git a/src/main/java/org/distorted/objects/RubikCube.java b/src/main/java/org/distorted/objects/RubikCube.java
index 4c48de1d..5700343a 100644
--- a/src/main/java/org/distorted/objects/RubikCube.java
+++ b/src/main/java/org/distorted/objects/RubikCube.java
@@ -166,6 +166,14 @@ class RubikCube extends RubikObject
     return 0.5f;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getFaceColor(int cubit, int cubitface, int size)
+    {
+    boolean belongs = isOnFace(cubit, cubitface/2, cubitface%2==0 ? size-1:0 );
+    return belongs ? cubitface : NUM_FACES;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   MeshBase createCubitMesh(int cubit)
diff --git a/src/main/java/org/distorted/objects/RubikDino.java b/src/main/java/org/distorted/objects/RubikDino.java
index d769814c..882ef97a 100644
--- a/src/main/java/org/distorted/objects/RubikDino.java
+++ b/src/main/java/org/distorted/objects/RubikDino.java
@@ -100,6 +100,10 @@ public class RubikDino extends RubikObject
            new Static3D(-0.5f, 0.0f,-0.5f )
          };
 
+  private static final int[] mFaceMap = {2,4, 4,0, 3,4, 4,1,
+                                         0,2, 0,3, 1,3, 1,2,
+                                         2,5, 5,0, 3,5, 5,1 };
+
   private static MeshBase mMesh;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -273,6 +277,18 @@ public class RubikDino extends RubikObject
     return mesh;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getFaceColor(int cubit, int cubitface, int size)
+    {
+    switch(cubitface)
+      {
+      case 0 : return mFaceMap[2*cubit];
+      case 1 : return mFaceMap[2*cubit+1];
+      default: return NUM_FACES;
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)
diff --git a/src/main/java/org/distorted/objects/RubikObject.java b/src/main/java/org/distorted/objects/RubikObject.java
index 1ba3f196..619d6d45 100644
--- a/src/main/java/org/distorted/objects/RubikObject.java
+++ b/src/main/java/org/distorted/objects/RubikObject.java
@@ -274,18 +274,6 @@ public abstract class RubikObject extends DistortedNode
     return ((1<<cubitRow)&rowBitmap)!=0;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// we cannot use belongsToRotation for deciding if to texture a face. Counterexample: the 'rotated'
-// tetrahedrons of Pyraminx nearby the edge: they belong to rotation but their face which is rotated
-// away from the face of the Pyraminx shouldn't be textured.
-
-  private boolean isOnFace( int cubit, int axis, int row)
-    {
-    final float MAX_ERROR = 0.0001f;
-    float diff = mCubits[cubit].mRotationRow[axis] - row;
-    return diff*diff < MAX_ERROR;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // note the minus in front of the sin() - we rotate counterclockwise
 // when looking towards the direction where the axis increases in values.
@@ -330,6 +318,18 @@ public abstract class RubikObject extends DistortedNode
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// we cannot use belongsToRotation for deciding if to texture a face. Counterexample: the 'rotated'
+// tetrahedrons of Pyraminx nearby the edge: they belong to rotation but their face which is rotated
+// away from the face of the Pyraminx shouldn't be textured.
+
+  boolean isOnFace( int cubit, int axis, int row)
+    {
+    final float MAX_ERROR = 0.0001f;
+    float diff = mCubits[cubit].mRotationRow[axis] - row;
+    return diff*diff < MAX_ERROR;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   int getCubitFaceColorIndex(int cubit, int face)
@@ -491,49 +491,17 @@ public abstract class RubikObject extends DistortedNode
 
   public void resetAllTextureMaps()
     {
-    boolean belongs;
     final float ratio = 1.0f/(NUM_FACES+1);
-
-    if( 3*ROTATION_AXIS.length == 2*NUM_FACES ) // Dino
-      {
-      final Static4D[] maps = new Static4D[NUM_CUBITS*NUM_CUBIT_FACES];
-
-      final int[] map = {2,4, 4,0, 3,4, 4,1,
-                         0,2, 0,3, 1,3, 1,2,
-                         2,5, 5,0, 3,5, 5,1 };
-
-      for(int i=0; i<NUM_CUBITS; i++)
-        {
-        maps[NUM_CUBIT_FACES*i    ] = new Static4D( map[2*i  ]*ratio, 0.0f, ratio, 1.0f);
-        maps[NUM_CUBIT_FACES*i + 1] = new Static4D( map[2*i+1]*ratio, 0.0f, ratio, 1.0f);
-        maps[NUM_CUBIT_FACES*i + 2] = new Static4D( NUM_FACES *ratio, 0.0f, ratio, 1.0f);
-        maps[NUM_CUBIT_FACES*i + 3] = new Static4D( NUM_FACES *ratio, 0.0f, ratio, 1.0f);
-        }
-
-      mMesh.setTextureMap(maps,0);
-      return;
-      }
-
+    int color;
 
     for(int cubit=0; cubit<NUM_CUBITS; cubit++)
       {
       final Static4D[] maps = new Static4D[NUM_CUBIT_FACES];
 
-      if( 2*ROTATION_AXIS.length == NUM_FACES )  // i.e. there are faces on both ends of the axis (cube)
-        {
-        for(int i=0; i<NUM_CUBIT_FACES; i++)
-          {
-          belongs = isOnFace(cubit, i/2, i%2==0 ? mSize-1:0 );
-          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
-          }
-        }
-      else if( ROTATION_AXIS.length == NUM_FACES )  // just a single face on the right end of an axis (pyraminx)
+      for(int cubitface=0; cubitface<NUM_CUBIT_FACES; cubitface++)
         {
-        for(int i=0; i<NUM_CUBIT_FACES; i++)
-          {
-          belongs = isOnFace(cubit, i, 0 );
-          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
-          }
+        color = getFaceColor(cubit,cubitface,mSize);
+        maps[cubitface] = new Static4D( color*ratio, 0.0f, ratio, 1.0f);
         }
 
       mMesh.setTextureMap(maps,NUM_CUBIT_FACES*cubit);
@@ -726,6 +694,7 @@ public abstract class RubikObject extends DistortedNode
   abstract int getNumCubitFaces();
   abstract MeshBase createCubitMesh(int cubit);
   abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side);
+  abstract int getFaceColor(int cubit, int cubitface, int size);
   public abstract Static3D[] getRotationAxis();
   public abstract int getBasicAngle();
   public abstract float returnMultiplier();
diff --git a/src/main/java/org/distorted/objects/RubikPyraminx.java b/src/main/java/org/distorted/objects/RubikPyraminx.java
index 5edd1dd0..08e32a51 100644
--- a/src/main/java/org/distorted/objects/RubikPyraminx.java
+++ b/src/main/java/org/distorted/objects/RubikPyraminx.java
@@ -223,6 +223,14 @@ public class RubikPyraminx extends RubikObject
     return 0.82f;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getFaceColor(int cubit, int cubitface, int size)
+    {
+    boolean belongs = isOnFace(cubit, cubitface, 0 );
+    return belongs ? cubitface : NUM_FACES;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private MeshBase createStaticMesh(int cubit)
