commit 4c864c6829e08f2f4bd0d8abe4b33773c21bb769
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Jun 18 12:05:39 2020 +0100

    Further improve rotations of a Object layer - make them independent of physical screen size (now it depends on the angle of rotation and, if that's 0, on the speed (in inches of second) of the finger swipe done by the user.

diff --git a/src/main/java/org/distorted/main/RubikSurfaceView.java b/src/main/java/org/distorted/main/RubikSurfaceView.java
index 7ceb4d3b..1d86a022 100644
--- a/src/main/java/org/distorted/main/RubikSurfaceView.java
+++ b/src/main/java/org/distorted/main/RubikSurfaceView.java
@@ -79,8 +79,9 @@ public class RubikSurfaceView extends GLSurfaceView
     private int mLastCubitColor, mLastCubitFace, mLastCubit;
     private int mCurrentAxis, mCurrentRow;
     private float mCurrentAngle, mCurrRotSpeed;
-    private float[] mLastAngles;
-    private long[] mLastTimestamps;
+    private float[] mLastX;
+    private float[] mLastY;
+    private long[] mLastT;
     private int mFirstIndex, mLastIndex;
     private int mDensity;
 
@@ -271,7 +272,7 @@ public class RubikSurfaceView extends GLSurfaceView
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    private void addSpeedProbe(float angle)
+    private void addSpeedProbe(float x, float y)
       {
       long currTime = System.currentTimeMillis();
       boolean theSame = mLastIndex==mFirstIndex;
@@ -279,8 +280,9 @@ public class RubikSurfaceView extends GLSurfaceView
       mLastIndex++;
       if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
 
-      mLastTimestamps[mLastIndex] = currTime;
-      mLastAngles[mLastIndex] = angle;
+      mLastT[mLastIndex] = currTime;
+      mLastX[mLastIndex] = x;
+      mLastY[mLastIndex] = y;
 
       if( mLastIndex==mFirstIndex)
         {
@@ -290,26 +292,29 @@ public class RubikSurfaceView extends GLSurfaceView
 
       if( theSame )
         {
-        mLastTimestamps[mFirstIndex] = currTime;
-        mLastAngles[mFirstIndex] = angle;
+        mLastT[mFirstIndex] = currTime;
+        mLastX[mFirstIndex] = x;
+        mLastY[mFirstIndex] = y;
         }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    private void computeCurrentSpeed()
+    private void computeCurrentSpeedInInchesPerSecond()
       {
-      long firstTime = mLastTimestamps[mFirstIndex];
-      long lastTime  = mLastTimestamps[mLastIndex];
-      float firstAngle = mLastAngles[mFirstIndex];
-      float lastAngle  = mLastAngles[mLastIndex];
+      long firstTime = mLastT[mFirstIndex];
+      long lastTime  = mLastT[mLastIndex];
+      float fX = mLastX[mFirstIndex];
+      float fY = mLastY[mFirstIndex];
+      float lX = mLastX[mLastIndex];
+      float lY = mLastY[mLastIndex];
 
       long timeDiff = lastTime-firstTime;
 
       mLastIndex = 0;
       mFirstIndex= 0;
 
-      mCurrRotSpeed = timeDiff>0 ? (lastAngle-firstAngle)/timeDiff : 0;
+      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -427,7 +432,7 @@ public class RubikSurfaceView extends GLSurfaceView
               });
             }
 
-          addSpeedProbe(0.0f);
+          addSpeedProbe(x,y);
 
           mBeginningRotation = false;
           mContinuingRotation= true;
@@ -439,7 +444,7 @@ public class RubikSurfaceView extends GLSurfaceView
         mCurrentAngle = SWIPING_SENSITIVITY*angle;
         mPreRender.getObject().continueRotation(mCurrentAngle);
 
-        addSpeedProbe(mCurrentAngle);
+        addSpeedProbe(x,y);
         }
       else if( mDragging )
         {
@@ -476,7 +481,7 @@ public class RubikSurfaceView extends GLSurfaceView
 
       if( mContinuingRotation )
         {
-        computeCurrentSpeed();
+        computeCurrentSpeedInInchesPerSecond();
         int angle = mPreRender.getObject().computeNearestAngle(mCurrentAngle, mCurrRotSpeed);
         mPreRender.finishRotation(angle);
 
@@ -506,8 +511,9 @@ public class RubikSurfaceView extends GLSurfaceView
         mLastCubitColor = -1;
         mCurrRotSpeed   = 0.0f;
 
-        mLastAngles = new float[NUM_SPEED_PROBES];
-        mLastTimestamps = new long[NUM_SPEED_PROBES];
+        mLastX = new float[NUM_SPEED_PROBES];
+        mLastY = new float[NUM_SPEED_PROBES];
+        mLastT = new long[NUM_SPEED_PROBES];
         mFirstIndex =0;
         mLastIndex  =0;
 
diff --git a/src/main/java/org/distorted/objects/RubikObject.java b/src/main/java/org/distorted/objects/RubikObject.java
index 54c7aeee..4ba67304 100644
--- a/src/main/java/org/distorted/objects/RubikObject.java
+++ b/src/main/java/org/distorted/objects/RubikObject.java
@@ -620,15 +620,12 @@ public abstract class RubikObject extends DistortedNode
     {
     final int NEAREST = 360/getBasicAngle();
 
-    float angleAndSpeed = angle + 100*speed;
+    int tmp = (int)((angle+NEAREST/2)/NEAREST);
+    if( angle< -(NEAREST*0.5) ) tmp-=1;
 
-    int tmp1 = (int)((angle+NEAREST/2)/NEAREST);
-    if( angle< -(NEAREST*0.5) ) tmp1-=1;
+    if( tmp!=0 ) return NEAREST*tmp;
 
-    int tmp2 = (int)((angleAndSpeed+NEAREST/2)/NEAREST);
-    if( angleAndSpeed< -(NEAREST*0.5) ) tmp2-=1;
-
-    return NEAREST*(tmp1==0 ? tmp2 : tmp1);
+    return speed> 1.5f ? NEAREST*(angle>0 ? 1:-1) : 0;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
