commit a706f8e06375109d10a39f5d811c4f12446363db
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Sep 30 16:03:21 2021 +0200

    Move QuatHelpeer to distorted-library

diff --git a/src/main/java/org/distorted/objectlib/main/Cubit.java b/src/main/java/org/distorted/objectlib/main/Cubit.java
index 6286ae8b..0484c336 100644
--- a/src/main/java/org/distorted/objectlib/main/Cubit.java
+++ b/src/main/java/org/distorted/objectlib/main/Cubit.java
@@ -21,6 +21,7 @@ package org.distorted.objectlib.main;
 
 import android.content.SharedPreferences;
 
+import org.distorted.library.main.QuatHelper;
 import org.distorted.library.type.Static4D;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objectlib/main/FactoryCubit.java b/src/main/java/org/distorted/objectlib/main/FactoryCubit.java
index 29c5df72..4b27a72d 100644
--- a/src/main/java/org/distorted/objectlib/main/FactoryCubit.java
+++ b/src/main/java/org/distorted/objectlib/main/FactoryCubit.java
@@ -24,6 +24,7 @@ import org.distorted.library.effect.MatrixEffectQuaternion;
 import org.distorted.library.effect.MatrixEffectScale;
 import org.distorted.library.effect.VertexEffect;
 import org.distorted.library.effect.VertexEffectDeform;
+import org.distorted.library.main.QuatHelper;
 import org.distorted.library.mesh.MeshBase;
 import org.distorted.library.mesh.MeshJoined;
 import org.distorted.library.mesh.MeshPolygon;
diff --git a/src/main/java/org/distorted/objectlib/main/QuatHelper.java b/src/main/java/org/distorted/objectlib/main/QuatHelper.java
deleted file mode 100644
index 8d069fa3..00000000
--- a/src/main/java/org/distorted/objectlib/main/QuatHelper.java
+++ /dev/null
@@ -1,163 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright 2021 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.Static4D;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-public class QuatHelper
-  {
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return quat1*quat2
-
-  public static Static4D quatMultiply( Static4D quat1, Static4D quat2 )
-    {
-    float qx = quat1.get0();
-    float qy = quat1.get1();
-    float qz = quat1.get2();
-    float qw = quat1.get3();
-
-    float rx = quat2.get0();
-    float ry = quat2.get1();
-    float rz = quat2.get2();
-    float rw = quat2.get3();
-
-    float tx = rw*qx - rz*qy + ry*qz + rx*qw;
-    float ty = rw*qy + rz*qx + ry*qw - rx*qz;
-    float tz = rw*qz + rz*qw - ry*qx + rx*qy;
-    float tw = rw*qw - rz*qz - ry*qy - rx*qx;
-
-    return new Static4D(tx,ty,tz,tw);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// rotate 'vector' by quat  ( i.e. return quat*vector*(quat^-1) )
-
-  public static Static4D rotateVectorByQuat(Static4D vector, Static4D quat)
-    {
-    float qx = quat.get0();
-    float qy = quat.get1();
-    float qz = quat.get2();
-    float qw = quat.get3();
-
-    Static4D quatInverted= new Static4D(-qx,-qy,-qz,qw);
-    Static4D tmp = quatMultiply(quat,vector);
-
-    return quatMultiply(tmp,quatInverted);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// rotate 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
-
-  public static Static4D rotateVectorByInvertedQuat(Static4D vector, Static4D quat)
-    {
-    float qx = quat.get0();
-    float qy = quat.get1();
-    float qz = quat.get2();
-    float qw = quat.get3();
-
-    Static4D quatInverted= new Static4D(-qx,-qy,-qz,qw);
-    Static4D tmp = quatMultiply(quatInverted,vector);
-
-    return quatMultiply(tmp,quat);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static Static4D quatFromDrag(float dragX, float dragY)
-    {
-    float axisX = dragY;  // inverted X and Y - rotation axis is perpendicular to (dragX,dragY)
-    float axisY = dragX;  // Why not (-dragY, dragX) ? because Y axis is also inverted!
-    float axisZ = 0;
-    float axisL = (float)Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
-
-    if( axisL>0 )
-      {
-      axisX /= axisL;
-      axisY /= axisL;
-      axisZ /= axisL;
-
-      float ratio = axisL;
-      ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
-
-      float cosA = (float)Math.cos(Math.PI*ratio);
-      float sinA = (float)Math.sqrt(1-cosA*cosA);
-
-      return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
-      }
-
-    return new Static4D(0f, 0f, 0f, 1f);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static double computeCos(double oldX, double oldY, double newX, double newY, double len1, double len2)
-    {
-    double ret= (oldX*newX+oldY*newY) / (len1*len2);
-    if( ret<-1.0 ) return -1.0;
-    if( ret> 1.0 ) return  1.0;
-
-    return ret;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// sin of (signed!) angle between vectors 'old' and 'new', counterclockwise!
-
-  public static double computeSin(double oldX, double oldY, double newX, double newY, double len1, double len2)
-    {
-    double ret= (newX*oldY-oldX*newY) / (len1*len2);
-    if( ret<-1.0 ) return -1.0;
-    if( ret> 1.0 ) return  1.0;
-
-    return ret;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return quat Q that turns 3D vector A=(ax,ay,az) to another 3D vector B=(bx,by,bz)
-// take care of double-cover by ensuring that always Q.get3() >=0
-
-  public static Static4D retRotationQuat(float ax, float ay, float az, float bx, float by, float bz)
-    {
-    float nx = ay*bz - az*by;
-    float ny = az*bx - ax*bz;
-    float nz = ax*by - ay*bx;
-
-    float sin = (float)Math.sqrt(nx*nx + ny*ny + nz*nz);
-    float cos = ax*bx + ay*by + az*bz;
-
-    if( sin!=0 )
-      {
-      nx /= sin;
-      ny /= sin;
-      nz /= sin;
-      }
-
-    // Why sin<=0 and cos>=0 ?
-    // 0<angle<180 -> 0<halfAngle<90 -> both sin and cos are positive.
-    // But1: quats work counterclockwise -> negate cos.
-    // But2: double-cover, we prefer to have the cos positive (so that unit=(0,0,0,1))
-    // so negate again both cos and sin.
-    float sinHalf =-(float)Math.sqrt((1-cos)/2);
-    float cosHalf = (float)Math.sqrt((1+cos)/2);
-
-    return new Static4D(nx*sinHalf,ny*sinHalf,nz*sinHalf,cosHalf);
-    }
-  }
diff --git a/src/main/java/org/distorted/objectlib/main/TwistyObject.java b/src/main/java/org/distorted/objectlib/main/TwistyObject.java
index 636f8bf7..71dd0ba2 100644
--- a/src/main/java/org/distorted/objectlib/main/TwistyObject.java
+++ b/src/main/java/org/distorted/objectlib/main/TwistyObject.java
@@ -37,6 +37,7 @@ import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedLibrary;
 import org.distorted.library.main.DistortedNode;
 import org.distorted.library.main.DistortedTexture;
+import org.distorted.library.main.QuatHelper;
 import org.distorted.library.mesh.MeshBase;
 import org.distorted.library.mesh.MeshFile;
 import org.distorted.library.mesh.MeshJoined;
diff --git a/src/main/java/org/distorted/objectlib/objects/TwistyKilominx.java b/src/main/java/org/distorted/objectlib/objects/TwistyKilominx.java
index 1cbb8967..ba517c6f 100644
--- a/src/main/java/org/distorted/objectlib/objects/TwistyKilominx.java
+++ b/src/main/java/org/distorted/objectlib/objects/TwistyKilominx.java
@@ -28,12 +28,12 @@ import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.mesh.MeshSquare;
 import org.distorted.library.type.Static4D;
+import org.distorted.library.main.QuatHelper;
 
 import org.distorted.objectlib.R;
 import org.distorted.objectlib.main.ObjectList;
 import org.distorted.objectlib.main.ObjectShape;
 import org.distorted.objectlib.main.ObjectSticker;
-import org.distorted.objectlib.main.QuatHelper;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
diff --git a/src/main/java/org/distorted/objectlib/objects/TwistyMegaminx.java b/src/main/java/org/distorted/objectlib/objects/TwistyMegaminx.java
index ed848039..810d51fa 100644
--- a/src/main/java/org/distorted/objectlib/objects/TwistyMegaminx.java
+++ b/src/main/java/org/distorted/objectlib/objects/TwistyMegaminx.java
@@ -28,12 +28,12 @@ import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.mesh.MeshSquare;
 import org.distorted.library.type.Static4D;
+import org.distorted.library.main.QuatHelper;
 
 import org.distorted.objectlib.R;
 import org.distorted.objectlib.main.ObjectList;
 import org.distorted.objectlib.main.ObjectShape;
 import org.distorted.objectlib.main.ObjectSticker;
-import org.distorted.objectlib.main.QuatHelper;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
