commit ab31cf6fb144330d9888688658cd4aaac21c692b
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Oct 12 23:45:17 2021 +0200

    Cuboids: movement.

diff --git a/src/main/java/org/distorted/objectlib/main/Movement.java b/src/main/java/org/distorted/objectlib/main/Movement.java
index 7df8b2ff..fd4d0357 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement.java
@@ -41,7 +41,7 @@ public abstract class Movement
   private final float[] mPoint, mCamera, mTouch;
   private final float[] mPoint2D, mMove2D;
   private final int[] mEnabledRotAxis;
-  private final float mDistanceCenterFace3D;
+  private final float[] mDistanceCenterFace3D;
   private final Static3D[] mFaceAxis;
 
   private int mLastTouchedFace;
@@ -61,7 +61,7 @@ public abstract class Movement
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   Movement(Static3D[] rotAxis, Static3D[] faceAxis, float[][] cuts, boolean[][] rotatable,
-           float distance3D, float size, int type, int[][][] enabled)
+           float[] distance3D, float size, int type, int[][][] enabled)
     {
     mPoint = new float[3];
     mCamera= new float[3];
@@ -82,7 +82,7 @@ public abstract class Movement
 
     computeCastedAxis(rotAxis);
     computeBorders(cuts,rotatable,size);
-    computeLinear(distance3D,rotAxis,faceAxis);
+    computeLinear(rotAxis,faceAxis);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -180,7 +180,7 @@ public abstract class Movement
     {
     Static3D faceAxis = mFaceAxis[index];
     float castCameraOnAxis = mCamera[0]*faceAxis.get0() + mCamera[1]*faceAxis.get1() + mCamera[2]*faceAxis.get2();
-    return castCameraOnAxis > mDistanceCenterFace3D;
+    return castCameraOnAxis > mDistanceCenterFace3D[index];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -207,7 +207,7 @@ public abstract class Movement
     if( denom != 0.0f )
       {
       float axisCam = a0*mCamera[0] + a1*mCamera[1] + a2*mCamera[2];
-      float alpha = (mDistanceCenterFace3D-axisCam)/denom;
+      float alpha = (mDistanceCenterFace3D[index]-axisCam)/denom;
 
       output[0] = mCamera[0] + d0*alpha;
       output[1] = mCamera[1] + d1*alpha;
@@ -356,7 +356,7 @@ public abstract class Movement
 // the 3D 'cuts' to translate it from 3D (i.e. with respect to the rotAxis) to 2D in-face (i.e. with
 // respect to the 2D rotAxis cast into a particular face)
 
-  private void computeLinear(float distance3D, Static3D[] rotAxis, Static3D[] faceAxis)
+  private void computeLinear(Static3D[] rotAxis, Static3D[] faceAxis)
     {
     int numFaces = faceAxis.length;
     int numRot   = rotAxis.length;
@@ -373,7 +373,7 @@ public abstract class Movement
           {
           float coeff = (float)Math.sqrt(1/(mA[i][j]*mA[i][j]) -1);
           int sign = computeSign(faceAxis[i],rotAxis[j]);
-          mB[i][j] = sign*distance3D*coeff;
+          mB[i][j] = sign*coeff*mDistanceCenterFace3D[i];
           }
         else mB[i][j] = 0.0f;
         }
diff --git a/src/main/java/org/distorted/objectlib/main/Movement12.java b/src/main/java/org/distorted/objectlib/main/Movement12.java
index 7460c704..e913c9df 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement12.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement12.java
@@ -35,6 +35,8 @@ public class Movement12 extends Movement
 
   public  static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5);
   private static final float DIST2D = (SIN54/COS54)/2;
+  private static final float[] D3D  = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
+                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
 
   public static final Static3D[] FACE_AXIS = new Static3D[]
          {
@@ -56,7 +58,7 @@ public class Movement12 extends Movement
 
   public Movement12(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
     {
-    super(rotAxis, FACE_AXIS, cuts,rotatable,DIST3D, size, type, enabled);
+    super(rotAxis, FACE_AXIS, cuts,rotatable,D3D, size, type, enabled);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objectlib/main/Movement4.java b/src/main/java/org/distorted/objectlib/main/Movement4.java
index f300e1fd..90265b1e 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement4.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement4.java
@@ -29,6 +29,8 @@ public class Movement4 extends Movement
   private static final float DIST3D = SQ6/12;
   private static final float DIST2D = SQ3/6;
 
+  private static final float[] D3D  = { DIST3D,DIST3D,DIST3D,DIST3D };
+
   public static final Static3D[] FACE_AXIS = new Static3D[]
          {
            new Static3D(     0,+SQ3/3,+SQ6/3),
@@ -41,7 +43,7 @@ public class Movement4 extends Movement
 
   public Movement4(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
     {
-    super(rotAxis, FACE_AXIS, cuts, rotatable, DIST3D, size, type, enabled);
+    super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objectlib/main/Movement6.java b/src/main/java/org/distorted/objectlib/main/Movement6.java
index 0aca77cf..37b0c55b 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement6.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement6.java
@@ -29,6 +29,8 @@ public class Movement6 extends Movement
   private static final float DIST3D = 0.5f;
   private static final float DIST2D = 0.5f;
 
+  private static final float[] D3D  = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
+
   public static final Static3D[] FACE_AXIS = new Static3D[]
          {
            new Static3D(1,0,0), new Static3D(-1,0,0),
@@ -40,7 +42,7 @@ public class Movement6 extends Movement
 
   public Movement6(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
     {
-    super(rotAxis, FACE_AXIS, cuts, rotatable, DIST3D, size, type, enabled);
+    super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objectlib/main/Movement8.java b/src/main/java/org/distorted/objectlib/main/Movement8.java
index 559db5ac..73d10b2d 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement8.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement8.java
@@ -29,6 +29,8 @@ public class Movement8 extends Movement
   private static final float DIST3D = SQ6/6;
   private static final float DIST2D = SQ3/6;
 
+  private static final float[] D3D  = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
+
   public static final Static3D[] FACE_AXIS = new Static3D[]
          {
            new Static3D(+SQ6/3,+SQ3/3,     0), new Static3D(-SQ6/3,-SQ3/3,     0),
@@ -41,7 +43,7 @@ public class Movement8 extends Movement
 
   public Movement8(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
     {
-    super(rotAxis, FACE_AXIS, cuts, rotatable, DIST3D, size, type, enabled);
+    super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objectlib/main/MovementC.java b/src/main/java/org/distorted/objectlib/main/MovementC.java
new file mode 100644
index 00000000..859b6dd9
--- /dev/null
+++ b/src/main/java/org/distorted/objectlib/main/MovementC.java
@@ -0,0 +1,74 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2020 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Magic Cube.                                                              //
+//                                                                                               //
+// Magic Cube is free software: you can redistribute it and/or modify                            //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Magic Cube is distributed in the hope that it will be useful,                                 //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.objectlib.main;
+
+import org.distorted.library.type.Static3D;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Cuboids
+
+public class MovementC extends Movement
+{
+  private final float[] mDist3D;
+
+  public static final Static3D[] FACE_AXIS = new Static3D[]
+         {
+           new Static3D(1,0,0), new Static3D(-1,0,0),
+           new Static3D(0,1,0), new Static3D(0,-1,0),
+           new Static3D(0,0,1), new Static3D(0,0,-1)
+         };
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public MovementC(Static3D[] rotAxis, float[][] cuts, boolean[][] rotatable, float size, int type,
+                   int[][][] enabled, float[] dist3D)
+    {
+    super(rotAxis, FACE_AXIS, cuts, rotatable, dist3D, size, type, enabled);
+
+    mDist3D = dist3D;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int returnPart(int type, int face, float[] touchPoint)
+    {
+    return 0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public float returnRotationFactor(int[] numLayers, int row)
+    {
+    return 1.0f;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  boolean isInsideFace(int face, float[] p)
+    {
+    switch(face/2)
+      {
+      case 0: return ( p[0]<=mDist3D[4] && p[0]>=-mDist3D[4] && p[1]<=mDist3D[2] && p[1]>=-mDist3D[2] );
+      case 1: return ( p[0]<=mDist3D[0] && p[0]>=-mDist3D[0] && p[1]<=mDist3D[4] && p[1]>=-mDist3D[4] );
+      case 2: return ( p[0]<=mDist3D[0] && p[0]>=-mDist3D[0] && p[1]<=mDist3D[2] && p[1]>=-mDist3D[2] );
+      }
+    return false;
+    }
+}
diff --git a/src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java b/src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
index 048ce2a3..e430919a 100644
--- a/src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
+++ b/src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
@@ -31,7 +31,7 @@ import org.distorted.library.type.Static4D;
 
 import org.distorted.objectlib.R;
 import org.distorted.objectlib.main.Movement;
-import org.distorted.objectlib.main.Movement6;
+import org.distorted.objectlib.main.MovementC;
 import org.distorted.objectlib.main.ObjectControl;
 import org.distorted.objectlib.main.ObjectType;
 import org.distorted.objectlib.helpers.ObjectShape;
@@ -244,7 +244,7 @@ public class TwistyCuboid extends Twisty6
     {
     if( mQuats ==null ) initializeQuats();
     int status = retCubitSolvedStatus(cubit,numLayers);
-    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status], mQuats);
+    return status<0 ? null : buildSolvedQuats(MovementC.FACE_AXIS[status], mQuats);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -608,7 +608,6 @@ public class TwistyCuboid extends Twisty6
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// TODO
 
   public Movement getMovement()
     {
@@ -618,7 +617,18 @@ public class TwistyCuboid extends Twisty6
       if( mCuts==null ) getCuts(numLayers);
       getLayerRotatable(numLayers);
       float avg = (numLayers[0]+numLayers[1]+numLayers[2])/3.0f;
-      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,avg,TYPE_NOT_SPLIT,ENABLED);
+
+      float[] dist3D =
+        {
+        0.5f*numLayers[0]/avg,
+        0.5f*numLayers[0]/avg,
+        0.5f*numLayers[1]/avg,
+        0.5f*numLayers[1]/avg,
+        0.5f*numLayers[2]/avg,
+        0.5f*numLayers[2]/avg,
+        };
+
+      mMovement = new MovementC(ROT_AXIS,mCuts,mLayerRotatable,avg,TYPE_NOT_SPLIT,ENABLED,dist3D);
       }
     return mMovement;
     }
