commit 880beeea44cba2289ad1c6fe6755fc78268f5661
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Oct 4 13:39:51 2021 +0200

    Move ObjectControl, the next big chunk of code, to objectlib.

diff --git a/src/main/java/org/distorted/objectlib/helpers/ObjectStateActioner.java b/src/main/java/org/distorted/objectlib/helpers/ObjectStateActioner.java
index f732bcb1..d5033ab4 100644
--- a/src/main/java/org/distorted/objectlib/helpers/ObjectStateActioner.java
+++ b/src/main/java/org/distorted/objectlib/helpers/ObjectStateActioner.java
@@ -21,9 +21,16 @@ package org.distorted.objectlib.helpers;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
+import org.distorted.objectlib.main.ObjectType;
+
 public interface ObjectStateActioner
   {
   void onWinEffectFinished(TwistyActivity act, String debug, int scrambleNum);
   void onScrambleEffectFinished(TwistyActivity act);
+  void onBeginRotation(TwistyActivity act);
+  void onFinishRotation(TwistyActivity act, int axis, int row, int angle);
+  void failedToDrag(TwistyActivity act);
+  int getCurrentColor();
+  int cubitIsLocked(ObjectType type, int cubit);
   void onSolved();
   }
diff --git a/src/main/java/org/distorted/objectlib/helpers/TwistyActivity.java b/src/main/java/org/distorted/objectlib/helpers/TwistyActivity.java
index 2e284afa..6b0b54cb 100644
--- a/src/main/java/org/distorted/objectlib/helpers/TwistyActivity.java
+++ b/src/main/java/org/distorted/objectlib/helpers/TwistyActivity.java
@@ -32,6 +32,7 @@ abstract public class TwistyActivity extends AppCompatActivity
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public abstract ObjectPreRender getPreRender();
+  public abstract boolean isLocked();
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
diff --git a/src/main/java/org/distorted/objectlib/main/ObjectControl.java b/src/main/java/org/distorted/objectlib/main/ObjectControl.java
new file mode 100644
index 00000000..ad846199
--- /dev/null
+++ b/src/main/java/org/distorted/objectlib/main/ObjectControl.java
@@ -0,0 +1,628 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2019 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 java.lang.ref.WeakReference;
+
+import android.util.DisplayMetrics;
+import android.view.MotionEvent;
+
+import org.distorted.library.main.QuatHelper;
+import org.distorted.library.type.Static2D;
+import org.distorted.library.type.Static4D;
+
+import org.distorted.objectlib.helpers.ObjectStateActioner;
+import org.distorted.objectlib.helpers.ObjectSurfaceView;
+import org.distorted.objectlib.helpers.TwistyActivity;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class ObjectControl
+{
+    public static final int NUM_SPEED_PROBES = 10;
+    public static final int INVALID_POINTER_ID = -1;
+
+    public static final int MODE_ROTATE  = 0;
+    public static final int MODE_DRAG    = 1;
+    public static final int MODE_REPLACE = 2;
+
+    // Moving the finger from the middle of the vertical screen to the right edge will rotate a
+    // given face by SWIPING_SENSITIVITY/2 degrees.
+    public final static int SWIPING_SENSITIVITY  = 240;
+    // Moving the finger by 0.3 of an inch will start a Rotation.
+    public final static float ROTATION_SENSITIVITY = 0.3f;
+
+    private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
+
+    private final WeakReference<TwistyActivity> mAct;
+    private final ObjectStateActioner mActioner;
+    private final ObjectPreRender mPreRender;
+    private Movement mMovement;
+    private boolean mDragging, mBeginningRotation, mContinuingRotation;
+    private int mScreenWidth, mScreenHeight, mScreenMin;
+
+    private float mRotAngle, mInitDistance;
+    private float mStartRotX, mStartRotY;
+    private float mAxisX, mAxisY;
+    private float mRotationFactor;
+    private int mLastCubitColor, mLastCubitFace, mLastCubit;
+    private int mCurrentAxis, mCurrentRow;
+    private float mCurrentAngle, mCurrRotSpeed;
+    private final float[] mLastX;
+    private final float[] mLastY;
+    private final long[] mLastT;
+    private int mFirstIndex, mLastIndex;
+    private final int mDensity;
+
+    private int mPointer1, mPointer2;
+    private float mX1, mY1, mX2, mY2, mX, mY;
+    private boolean mIsAutomatic;
+
+    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
+    private static final Static4D mTemp= new Static4D(0,0,0,1);
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
+// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
+
+    private void computeCurrentAxis(Static4D axis)
+      {
+      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
+
+      mAxisX =result.get0();
+      mAxisY =result.get1();
+
+      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
+      mAxisX /= len;
+      mAxisY /= len;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void addSpeedProbe(float x, float y)
+      {
+      long currTime = System.currentTimeMillis();
+      boolean theSame = mLastIndex==mFirstIndex;
+
+      mLastIndex++;
+      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
+
+      mLastT[mLastIndex] = currTime;
+      mLastX[mLastIndex] = x;
+      mLastY[mLastIndex] = y;
+
+      if( mLastIndex==mFirstIndex)
+        {
+        mFirstIndex++;
+        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
+        }
+
+      if( theSame )
+        {
+        mLastT[mFirstIndex] = currTime;
+        mLastX[mFirstIndex] = x;
+        mLastY[mFirstIndex] = y;
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void computeCurrentSpeedInInchesPerSecond()
+      {
+      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 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
+      {
+      float xDist = mScreenWidth*(xFrom-xTo);
+      float yDist = mScreenHeight*(yFrom-yTo);
+      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
+
+      return distInPixels/mDensity;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void setUpDragOrRotate(boolean down, float x, float y, int mode)
+      {
+      if( mode==MODE_DRAG )
+        {
+        mDragging           = true;
+        mBeginningRotation  = false;
+        mContinuingRotation = false;
+        }
+      else
+        {
+        TwistyObject object = mPreRender.getObject();
+        CAMERA_POINT.set2( object==null ? 1.21f : object.getCameraDist() );
+
+        Static4D touchPoint = new Static4D(x, y, 0, 0);
+        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
+        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
+
+        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
+          {
+          mDragging           = false;
+          mContinuingRotation = false;
+
+          if( mode==MODE_ROTATE )
+            {
+            mBeginningRotation= !mPreRender.isTouchBlocked();
+            }
+          else if( mode==MODE_REPLACE )
+            {
+            mBeginningRotation= false;
+
+            if( down )
+              {
+              int color = mActioner.getCurrentColor();
+              mLastCubitFace = mMovement.getTouchedFace();
+              float[] point = mMovement.getTouchedPoint3D();
+              mLastCubit = object.getCubit(point);
+              mPreRender.setTextureMap( mLastCubit, mLastCubitFace, color );
+              mLastCubitColor = mActioner.cubitIsLocked(object.getObjectType(),mLastCubit);
+              }
+            }
+          }
+        else
+          {
+          final TwistyActivity act = mAct.get();
+          final boolean locked= act.isLocked();
+          mDragging           = (!locked || mIsAutomatic);
+          mBeginningRotation  = false;
+          mContinuingRotation = false;
+          if( !mDragging ) mActioner.failedToDrag(act);
+          }
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void drag(float x, float y)
+      {
+      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
+        {
+        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
+        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
+
+        float angleNow = getAngle(x,y,x2,y2);
+        float angleDiff = angleNow-mRotAngle;
+        float sinA =-(float)Math.sin(angleDiff);
+        float cosA = (float)Math.cos(angleDiff);
+
+        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
+        mTemp.set(dragQuat);
+
+        mRotAngle = angleNow;
+
+        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
+        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
+        mInitDistance = distNow;
+        TwistyObject object = mPreRender.getObject();
+        if( object!=null ) object.setObjectRatio(distQuot);
+        }
+      else
+        {
+        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
+        mTemp.set(dragQuat);
+        }
+
+      mPreRender.setQuatOnNextRender();
+      mX = x;
+      mY = y;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void finishRotation()
+      {
+      computeCurrentSpeedInInchesPerSecond();
+      int angle = mPreRender.getObject().computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
+      mPreRender.finishRotation(angle);
+      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
+
+      if( angle!=0 )
+        {
+        TwistyActivity act = mAct.get();
+        mActioner.onFinishRotation(act,mCurrentAxis,mCurrentRow,angle);
+        }
+
+      mContinuingRotation = false;
+      mBeginningRotation  = false;
+      mDragging           = true;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void continueRotation(float x, float y)
+      {
+      float dx = x-mStartRotX;
+      float dy = y-mStartRotY;
+      float alpha = dx*mAxisX + dy*mAxisY;
+      float x2 = dx - alpha*mAxisX;
+      float y2 = dy - alpha*mAxisY;
+
+      float len = (float)Math.sqrt(x2*x2 + y2*y2);
+
+      // we have the length of 1D vector 'angle', now the direction:
+      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
+
+      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
+      mCurrentAngle = SWIPING_SENSITIVITY*angle;
+      mPreRender.getObject().continueRotation(mCurrentAngle);
+
+      addSpeedProbe(x2,y2);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void beginRotation(float x, float y)
+      {
+      mStartRotX = x;
+      mStartRotY = y;
+
+      TwistyObject object = mPreRender.getObject();
+      int numLayers = object.getNumLayers();
+
+      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
+      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
+      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
+
+      mCurrentAxis = (int)res.get0();
+      mCurrentRow  = (int)res.get1();
+
+      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
+      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
+
+      object.beginNewRotation( mCurrentAxis, mCurrentRow );
+
+      TwistyActivity act = mAct.get();
+      mActioner.onBeginRotation(act);
+
+      addSpeedProbe(x,y);
+
+      mBeginningRotation = false;
+      mContinuingRotation= true;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private float getAngle(float x1, float y1, float x2, float y2)
+      {
+      return (float) Math.atan2(y1-y2, x1-x2);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void prepareDown(MotionEvent event)
+      {
+      mPointer1 = event.getPointerId(0);
+      mX1 = event.getX();
+      mY1 = event.getY();
+      mPointer2 = INVALID_POINTER_ID;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void prepareMove(MotionEvent event)
+      {
+      int index1 = event.findPointerIndex(mPointer1);
+
+      if( index1>=0 )
+        {
+        mX1 = event.getX(index1);
+        mY1 = event.getY(index1);
+        }
+
+      int index2 = event.findPointerIndex(mPointer2);
+
+      if( index2>=0 )
+        {
+        mX2 = event.getX(index2);
+        mY2 = event.getY(index2);
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void prepareUp(MotionEvent event)
+      {
+      mPointer1 = INVALID_POINTER_ID;
+      mPointer2 = INVALID_POINTER_ID;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void prepareDown2(MotionEvent event)
+      {
+      int index = event.getActionIndex();
+
+      if( mPointer1==INVALID_POINTER_ID )
+        {
+        mPointer1 = event.getPointerId(index);
+        mX1 = event.getX(index);
+        mY1 = event.getY(index);
+        }
+      else if( mPointer2==INVALID_POINTER_ID )
+        {
+        mPointer2 = event.getPointerId(index);
+        mX2 = event.getX(index);
+        mY2 = event.getY(index);
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void prepareUp2(MotionEvent event)
+      {
+      int index = event.getActionIndex();
+
+           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
+      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void actionMove(float x1, float y1, float x2, float y2, int mode)
+      {
+      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
+      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
+
+      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
+      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
+
+      if( mBeginningRotation )
+        {
+        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
+          {
+          beginRotation(x,y);
+          }
+        }
+      else if( mContinuingRotation )
+        {
+        continueRotation(x,y);
+        }
+      else if( mDragging )
+        {
+        drag(x,y);
+        }
+      else
+        {
+        setUpDragOrRotate(false,x,y,mode);
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void actionDown(float x, float y, int mode)
+      {
+      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
+      mY = (mScreenHeight*0.5f - y)/mScreenMin;
+
+      setUpDragOrRotate(true,mX,mY,mode);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void actionUp()
+      {
+      if( mContinuingRotation )
+        {
+        finishRotation();
+        }
+
+      if( mLastCubitColor>=0 )
+        {
+        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
+        mLastCubitColor = -1;
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void actionDown2(float x1, float y1, float x2, float y2)
+      {
+      mRotAngle = getAngle(x1,-y1, x2,-y2);
+      mInitDistance = -1;
+
+      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
+      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
+
+      if( mBeginningRotation )
+        {
+        mContinuingRotation = false;
+        mBeginningRotation  = false;
+        mDragging           = true;
+        }
+      else if( mContinuingRotation )
+        {
+        finishRotation();
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
+      {
+      if( p1isUp )
+        {
+        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
+        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
+        }
+      if( p2isUp )
+        {
+        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
+        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public ObjectControl(TwistyActivity act, ObjectSurfaceView view, ObjectStateActioner actioner)
+      {
+      mIsAutomatic = false;
+
+      mLastCubitColor = -1;
+      mCurrRotSpeed   = 0.0f;
+
+      mLastX = new float[NUM_SPEED_PROBES];
+      mLastY = new float[NUM_SPEED_PROBES];
+      mLastT = new long[NUM_SPEED_PROBES];
+      mFirstIndex =0;
+      mLastIndex  =0;
+
+      DisplayMetrics dm = new DisplayMetrics();
+      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
+
+      mDensity = dm.densityDpi;
+
+      mPreRender = new ObjectPreRender(view,actioner);
+      mAct = new WeakReference<>(act);
+      mActioner = actioner;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void setScreenSize(int width, int height)
+      {
+      mScreenWidth = width;
+      mScreenHeight= height;
+
+      mScreenMin = Math.min(width, height);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void initialize()
+      {
+      mPointer1 = INVALID_POINTER_ID;
+      mPointer2 = INVALID_POINTER_ID;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void setQuat()
+      {
+      mQuat.set(mTemp);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public Static4D getQuat()
+      {
+      return mQuat;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void setMovement(Movement movement)
+      {
+      mMovement = movement;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public ObjectPreRender getPreRender()
+      {
+      return mPreRender;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void prepareDown()
+      {
+      mIsAutomatic = true;
+      mPointer1 = 0;
+      mPointer2 = INVALID_POINTER_ID;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void prepareDown2()
+      {
+      mPointer2 = 0;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void prepareUp()
+      {
+      mIsAutomatic = false;
+      mPointer1 = INVALID_POINTER_ID;
+      mPointer2 = INVALID_POINTER_ID;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void prepareMove(float x1, float y1, float x2, float y2)
+      {
+      mX1 = x1;
+      mY1 = y1;
+      mX2 = x2;
+      mY2 = y2;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public boolean onTouchEvent(MotionEvent event, int mode)
+      {
+      int action = event.getActionMasked();
+
+      switch(action)
+         {
+         case MotionEvent.ACTION_DOWN        : prepareDown(event);
+                                               actionDown(mX1, mY1, mode);
+                                               break;
+         case MotionEvent.ACTION_MOVE        : prepareMove(event);
+                                               actionMove(mX1, mY1, mX2, mY2, mode);
+                                               break;
+         case MotionEvent.ACTION_UP          : prepareUp(event);
+                                               actionUp();
+                                               break;
+         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
+                                               actionDown2(mX1, mY1, mX2, mY2);
+                                               break;
+         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
+                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
+                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
+                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
+                                               break;
+         }
+
+      return true;
+      }
+}
+
diff --git a/src/main/java/org/distorted/objectlib/main/TwistyObject.java b/src/main/java/org/distorted/objectlib/main/TwistyObject.java
index 9d56114a..3dfca4e3 100644
--- a/src/main/java/org/distorted/objectlib/main/TwistyObject.java
+++ b/src/main/java/org/distorted/objectlib/main/TwistyObject.java
@@ -890,25 +890,9 @@ public abstract class TwistyObject extends DistortedNode
       }
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// INTERNAL API
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
-    {
-    mScrambler.randomizeNewScramble(scramble,rnd,curr,total);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public int getNodeSize()
-    {
-    return mNodeSize;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void initializeObject(int[][] moves)
+  void initializeObject(int[][] moves)
     {
     solve();
     setupPosition(moves);
@@ -916,7 +900,7 @@ public abstract class TwistyObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public synchronized void removeRotationNow()
+  synchronized void removeRotationNow()
     {
     float angle = getAngle();
     double nearestAngleInRadians = angle*Math.PI/180;
@@ -940,7 +924,7 @@ public abstract class TwistyObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
+  long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
     {
     if( wasRotateApplied() )
       {
@@ -965,7 +949,7 @@ public abstract class TwistyObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
+  synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
     {
     if( wasRotateApplied() )
       {
@@ -989,7 +973,37 @@ public abstract class TwistyObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void setTextureMap(int cubit, int face, int newColor)
+  void continueRotation(float angleInDegrees)
+    {
+    mRotationAngleStatic.set0(angleInDegrees);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  synchronized void beginNewRotation(int axis, int row )
+    {
+    if( axis<0 || axis>=NUM_AXIS )
+      {
+      android.util.Log.e("object", "invalid rotation axis: "+axis);
+      return;
+      }
+    if( row<0 || row>=mNumLayers )
+      {
+      android.util.Log.e("object", "invalid rotation row: "+row);
+      return;
+      }
+
+    mRotAxis     = axis;
+    mRotRowBitmap= computeBitmapFromRow( (1<<row),axis );
+    mRotationAngleStatic.set0(0.0f);
+    mRotationAxis.set( mAxis[axis] );
+    mRotationAngle.add(mRotationAngleStatic);
+    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*ObjectType.MAX_OBJECT_SIZE) , -1);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void setTextureMap(int cubit, int face, int newColor)
     {
     final float ratioW = 1.0f/mNumTexCols;
     final float ratioH = 1.0f/mNumTexRows;
@@ -1003,7 +1017,7 @@ public abstract class TwistyObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void resetAllTextureMaps()
+  void resetAllTextureMaps()
     {
     final float ratioW = 1.0f/mNumTexCols;
     final float ratioH = 1.0f/mNumTexRows;
@@ -1027,7 +1041,7 @@ public abstract class TwistyObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void releaseResources()
+  void releaseResources()
     {
     mTexture.markForDeletion();
     mMesh.markForDeletion();
@@ -1041,7 +1055,7 @@ public abstract class TwistyObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public synchronized void restorePreferences(SharedPreferences preferences)
+  synchronized void restorePreferences(SharedPreferences preferences)
     {
     boolean error = false;
 
@@ -1073,29 +1087,22 @@ public abstract class TwistyObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void savePreferences(SharedPreferences.Editor editor)
+  void savePreferences(SharedPreferences.Editor editor)
     {
     for(int i=0; i<NUM_CUBITS; i++) CUBITS[i].savePreferences(editor);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void recomputeScaleFactor(int scrWidth)
+  void recomputeScaleFactor(int scrWidth)
     {
     mNodeScale.set(scrWidth,NODE_RATIO*scrWidth,scrWidth);
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public Static4D getRotationQuat()
-      {
-      return mQuat;
-      }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size)
 
-  public void createTexture()
+  void createTexture()
     {
     Bitmap bitmap;
 
@@ -1130,23 +1137,9 @@ public abstract class TwistyObject extends DistortedNode
       }
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// PUBLIC API
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public boolean isSolved()
-    {
-    if( mSolvedFunctionIndex==0 ) return isSolved0();
-    if( mSolvedFunctionIndex==1 ) return isSolved1();
-    if( mSolvedFunctionIndex==2 ) return isSolved2();
-    if( mSolvedFunctionIndex==3 ) return isSolved3();
-
-    return false;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void setObjectRatio(float sizeChange)
+  void setObjectRatio(float sizeChange)
     {
     mObjectScreenRatio *= (1.0f+sizeChange)/2;
 
@@ -1159,131 +1152,138 @@ public abstract class TwistyObject extends DistortedNode
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public float getObjectRatio()
+  float getObjectRatio()
     {
     return mObjectScreenRatio*mInitScreenRatio;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public int getCubitFaceColorIndex(int cubit, int face)
+  boolean isSolved()
     {
-    Static4D texMap = mMesh.getTextureMap(NUM_FACE_COLORS*cubit + face);
-
-    int x = (int)(texMap.get0()/texMap.get2());
-    int y = (int)(texMap.get1()/texMap.get3());
+    if( mSolvedFunctionIndex==0 ) return isSolved0();
+    if( mSolvedFunctionIndex==1 ) return isSolved1();
+    if( mSolvedFunctionIndex==2 ) return isSolved2();
+    if( mSolvedFunctionIndex==3 ) return isSolved3();
 
-    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
+    return false;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public int getNumLayers()
+  int getCubit(float[] point3D)
     {
-    return mNumLayers;
+    float dist, minDist = Float.MAX_VALUE;
+    int currentBest=-1;
+    float multiplier = returnMultiplier();
+
+    point3D[0] *= multiplier;
+    point3D[1] *= multiplier;
+    point3D[2] *= multiplier;
+
+    for(int i=0; i<NUM_CUBITS; i++)
+      {
+      dist = CUBITS[i].getDistSquared(point3D);
+      if( dist<minDist )
+        {
+        minDist = dist;
+        currentBest = i;
+        }
+      }
+
+    return currentBest;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void continueRotation(float angleInDegrees)
+  int computeNearestAngle(int axis, float angle, float speed)
     {
-    mRotationAngleStatic.set0(angleInDegrees);
+    int[] basicArray = getBasicAngle();
+    int basicAngle   = basicArray[axis>=basicArray.length ? 0 : axis];
+    int nearestAngle = 360/basicAngle;
+
+    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
+    if( angle< -(nearestAngle*0.5) ) tmp-=1;
+
+    if( tmp!=0 ) return nearestAngle*tmp;
+
+    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void apply(Effect effect, int position)
+  float getCameraDist()
     {
-    mEffects.apply(effect, position);
+    return mCameraDist;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// INTERNAL API - those are called from 'effects' package
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void remove(long effectID)
+  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
     {
-    mEffects.abortById(effectID);
+    mScrambler.randomizeNewScramble(scramble,rnd,curr,total);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public synchronized void solve()
+  public int getNodeSize()
     {
-    for(int i=0; i<NUM_CUBITS; i++)
-      {
-      CUBITS[i].solve();
-      mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0);
-      }
+    return mNodeSize;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public synchronized void beginNewRotation(int axis, int row )
-    {
-    if( axis<0 || axis>=NUM_AXIS )
-      {
-      android.util.Log.e("object", "invalid rotation axis: "+axis);
-      return;
-      }
-    if( row<0 || row>=mNumLayers )
+  public Static4D getRotationQuat()
       {
-      android.util.Log.e("object", "invalid rotation row: "+row);
-      return;
+      return mQuat;
       }
 
-    mRotAxis     = axis;
-    mRotRowBitmap= computeBitmapFromRow( (1<<row),axis );
-    mRotationAngleStatic.set0(0.0f);
-    mRotationAxis.set( mAxis[axis] );
-    mRotationAngle.add(mRotationAngleStatic);
-    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*ObjectType.MAX_OBJECT_SIZE) , -1);
-    }
-
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public int getCubit(float[] point3D)
+  public int getCubitFaceColorIndex(int cubit, int face)
     {
-    float dist, minDist = Float.MAX_VALUE;
-    int currentBest=-1;
-    float multiplier = returnMultiplier();
-
-    point3D[0] *= multiplier;
-    point3D[1] *= multiplier;
-    point3D[2] *= multiplier;
+    Static4D texMap = mMesh.getTextureMap(NUM_FACE_COLORS*cubit + face);
 
-    for(int i=0; i<NUM_CUBITS; i++)
-      {
-      dist = CUBITS[i].getDistSquared(point3D);
-      if( dist<minDist )
-        {
-        minDist = dist;
-        currentBest = i;
-        }
-      }
+    int x = (int)(texMap.get0()/texMap.get2());
+    int y = (int)(texMap.get1()/texMap.get3());
 
-    return currentBest;
+    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public int computeNearestAngle(int axis, float angle, float speed)
+  public int getNumLayers()
     {
-    int[] basicArray = getBasicAngle();
-    int basicAngle   = basicArray[axis>=basicArray.length ? 0 : axis];
-    int nearestAngle = 360/basicAngle;
+    return mNumLayers;
+    }
 
-    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
-    if( angle< -(nearestAngle*0.5) ) tmp-=1;
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    if( tmp!=0 ) return nearestAngle*tmp;
+  public void apply(Effect effect, int position)
+    {
+    mEffects.apply(effect, position);
+    }
 
-    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void remove(long effectID)
+    {
+    mEffects.abortById(effectID);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public float getCameraDist()
+  public synchronized void solve()
     {
-    return mCameraDist;
+    for(int i=0; i<NUM_CUBITS; i++)
+      {
+      CUBITS[i].solve();
+      mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0);
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
