commit ffd481052a7b4a34f06941fb013e23148a29fcf6
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Dec 19 00:11:15 2019 +0000

    RubikCube: make finishingRotation more flexible (can now finish any rotation which did finish interpolating (nearly) to the end - and not only the single-static 'manual' rotation)

diff --git a/src/main/java/org/distorted/magic/RubikCube.java b/src/main/java/org/distorted/magic/RubikCube.java
index 72a2af53..50179f8d 100644
--- a/src/main/java/org/distorted/magic/RubikCube.java
+++ b/src/main/java/org/distorted/magic/RubikCube.java
@@ -301,7 +301,7 @@ public class RubikCube extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    void addNewRotation(int vector, float offset )
+    void addNewRotation(int vector, int row )
       {
       Static3D axis = VectX;
 
@@ -313,7 +313,7 @@ public class RubikCube extends DistortedNode
         }
 
       mRotAxis = vector;
-      mRotRow  = (int)(mSize*offset);
+      mRotRow  = row;
 
       mRotationAngleStatic.set1(0.0f);
 
@@ -354,13 +354,8 @@ public class RubikCube extends DistortedNode
     long finishRotationNow(EffectListener listener)
       {
       boolean first = true;
-      float startingAngle = mRotationAngleStatic.get1();
-      int nearestAngleInDegrees = computeNearestAngle(startingAngle);
       long effectID=0;
 
-      mRotationAngleFinal.set1(nearestAngleInDegrees);
-      mRotationAngleMiddle.set1( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f );
-
       for(int x=0; x<mSize; x++)
         for(int y=0; y<mSize; y++)
           for(int z=0; z<mSize; z++)
@@ -368,17 +363,34 @@ public class RubikCube extends DistortedNode
               {
               if( belongsToRotation(x,y,z,mRotAxis,mRotRow) )
                 {
-                mRotationAngle[x][y][z].setDuration(POST_ROTATION_MILLISEC);
-                mRotationAngle[x][y][z].resetToBeginning();
-                mRotationAngle[x][y][z].add(mRotationAngleMiddle);
-                mRotationAngle[x][y][z].add(mRotationAngleFinal);
-
                 if( first )
                   {
                   first = false;
                   mRotateEffect[x][y][z].notifyWhenFinished(listener);
                   effectID = mRotateEffect[x][y][z].getID();
+                  int pointNum = mRotationAngle[x][y][z].getNumPoints();
+
+                  if( pointNum>=1 )
+                    {
+                    float startingAngle = mRotationAngle[x][y][z].getPoint(pointNum-1).get1();
+                    int nearestAngleInDegrees = computeNearestAngle(startingAngle);
+                    mRotationAngleStatic.set1(startingAngle);
+                    mRotationAngleFinal.set1(nearestAngleInDegrees);
+                    mRotationAngleMiddle.set1( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f );
+                    }
+                  else
+                    {
+                    android.util.Log.e("cube", "ERROR finishing rotation!");
+                    return 0;
+                    }
                   }
+
+                mRotationAngle[x][y][z].setDuration(POST_ROTATION_MILLISEC);
+                mRotationAngle[x][y][z].resetToBeginning();
+                mRotationAngle[x][y][z].removeAll();
+                mRotationAngle[x][y][z].add(mRotationAngleStatic);
+                mRotationAngle[x][y][z].add(mRotationAngleMiddle);
+                mRotationAngle[x][y][z].add(mRotationAngleFinal);
                 }
               }
 
diff --git a/src/main/java/org/distorted/magic/RubikSurfaceView.java b/src/main/java/org/distorted/magic/RubikSurfaceView.java
index f89a2acc..c34e2f27 100644
--- a/src/main/java/org/distorted/magic/RubikSurfaceView.java
+++ b/src/main/java/org/distorted/magic/RubikSurfaceView.java
@@ -234,7 +234,8 @@ class RubikSurfaceView extends GLSurfaceView
       mTouchPoint[1] = mPoint[1];
       mTouchPoint[2] = mPoint[2];
 
-      mRenderer.getCube().addNewRotation(mRotationVect,offset);
+      RubikCube cube = mRenderer.getCube();
+      cube.addNewRotation(mRotationVect, (int)(cube.getSize()*offset) );
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
