commit f4ed769af58d4716e4ba187150a4f6377841feb8
Author: leszek <leszek@koltunski.pl>
Date:   Thu Mar 14 11:25:10 2024 +0100

    minor.

diff --git a/src/main/java/org/distorted/objectlib/helpers/FactoryCubit.java b/src/main/java/org/distorted/objectlib/helpers/FactoryCubit.java
index 7622ed23..0926c74c 100644
--- a/src/main/java/org/distorted/objectlib/helpers/FactoryCubit.java
+++ b/src/main/java/org/distorted/objectlib/helpers/FactoryCubit.java
@@ -182,6 +182,103 @@ public class FactoryCubit
     mBuffer[0] /= len;
     mBuffer[1] /= len;
     mBuffer[2] /= len;
+
+    // this theoretically should be uncommented to combat the same effect like in
+    // TouchControlShapeChanging.FaceInfo, but when I try, the center sticker of
+    // CoinTetrahedron gets inverted. Weird!
+    // Uncommenting this does fix the fact that the convexity of the center cubits
+    // of CoinT and CoinH goes concave
+
+/*
+    if( totalAngle(vertices,mBuffer)<0 )
+      {
+      mBuffer[0] *= -1;
+      mBuffer[1] *= -1;
+      mBuffer[2] *= -1;
+      }
+ */
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// this returns the total angle we get rotated about when we travel from the first vert to the last.
+// It's always should be +2PI or -2PI, depending on if the verts are CW or CCW (when looking at the
+// plane formed by the vertices from the direction the 'normal' vector points towards)
+//
+// The point: this way we can detect if the 'normal' vector is correct, i.e. if it points in the
+// right direction.
+// Sometimes it doesn't, when the first three vertices (from which the vector is computed) are 'concave'.
+
+  public static float totalAngle(float[][] vert, float[] normal)
+    {
+    float ret = 0;
+    int num = vert.length;
+
+    for(int c=0; c<num; c++)
+      {
+      int n = (c==num-1 ? 0 : c+1);
+      int m = (n==num-1 ? 0 : n+1);
+      ret += angle( vert[c],vert[n],vert[m], normal);
+      }
+
+    return ret;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private static float angle(float[] v0, float[] v1, float[] v2, float[] normal)
+    {
+    float px = v1[0] - v0[0];
+    float py = v1[1] - v0[1];
+    float pz = v1[2] - v0[2];
+
+    float rx = v2[0] - v1[0];
+    float ry = v2[1] - v1[1];
+    float rz = v2[2] - v1[2];
+
+    float l1 = (float)Math.sqrt(px*px + py*py + pz*pz);
+    float l2 = (float)Math.sqrt(rx*rx + ry*ry + rz*rz);
+
+    px /= l1;
+    py /= l1;
+    pz /= l1;
+
+    rx /= l2;
+    ry /= l2;
+    rz /= l2;
+
+    float s = px*rx + py*ry + pz*rz;
+
+    if( s> 1 ) s= 1;
+    if( s<-1 ) s=-1;
+
+    float a = (float) Math.acos(s);
+    float[] cross = crossProduct(px,py,pz,rx,ry,rz);
+
+    float ax = cross[0] + normal[0];
+    float ay = cross[1] + normal[1];
+    float az = cross[2] + normal[2];
+
+    float bx = cross[0] - normal[0];
+    float by = cross[1] - normal[1];
+    float bz = cross[2] - normal[2];
+
+    float f1 = ax*ax + ay*ay + az*az;
+    float f2 = bx*bx + by*by + bz*bz;
+
+    return f1>f2 ? a : -a;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private static float[] crossProduct(float a1, float a2, float a3, float b1, float b2, float b3)
+    {
+    float[] ret = new float[3];
+
+    ret[0] = a2*b3 - a3*b2;
+    ret[1] = a3*b1 - a1*b3;
+    ret[2] = a1*b2 - a2*b1;
+
+    return ret;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objectlib/helpers/FactorySticker.java b/src/main/java/org/distorted/objectlib/helpers/FactorySticker.java
index 65f2d4ab..7e08ed34 100644
--- a/src/main/java/org/distorted/objectlib/helpers/FactorySticker.java
+++ b/src/main/java/org/distorted/objectlib/helpers/FactorySticker.java
@@ -258,8 +258,8 @@ public class FactorySticker
 
     float dx = x-vx;
     float dy = y-vy;
-    float d = (float)Math.sqrt(dx*dx+dy*dy);
-    float f = (float)Math.sqrt(r*r-d*d);
+    float d_squared = dx*dx+dy*dy;
+    float f = (float)Math.sqrt(r*r-d_squared);
     float e = f / ((float)Math.sqrt(m*m+1));
 
     if( c==0 )
@@ -561,14 +561,14 @@ public class FactorySticker
       startA *= 180/PI;
       sweepA *= 180/PI;
 
-//android.util.Log.e("D", "drawing arc ox="+oX+" oy="+oY+" R="+R+" startA="+startA+" sweepA="+sweepA+" stopA="+(stopA*(180/PI)));
-//android.util.Log.e("D", "drawing arc v1="+v1x+" , "+v1y+" v2="+v2x+" , "+v2y+" tex: "+mTexHeight);
+// android.util.Log.e("D", "drawing arc ox="+oX+" oy="+oY+" R="+R+" startA="+startA+" sweepA="+sweepA+" stopA="+(stopA*(180/PI)));
+// android.util.Log.e("D", "drawing arc v1="+v1x+" , "+v1y+" v2="+v2x+" , "+v2y+" tex: "+mTexHeight);
 
       canvas.drawArc( left+oX-R, bottom-oY-R, left+oX+R, bottom-oY+R, startA, sweepA, false, paint);
       }
     else
       {
-//android.util.Log.e("D", "drawing line from "+v1x+" , "+v1y+" to "+v2x+" , "+v2y);
+// android.util.Log.e("D", "drawing line from "+v1x+" , "+v1y+" to "+v2x+" , "+v2y);
 
       canvas.drawLine( left+v1x, bottom-v1y, left+v2x, bottom-v2y, paint);
       }
@@ -642,8 +642,6 @@ public class FactorySticker
   public void drawRoundedPolygons(Canvas canvas, Paint paint, int left, int bottom, int color,
                                   int height, ObjectSticker sticker, float borders, float corners)
     {
-    //android.util.Log.d("D", "DRAW ROUNDED POLYGONS");
-
     mTexHeight = height;
 
     float[][] strokes    = sticker.getStrokes();
diff --git a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
index 46e74d3a..cf776a73 100644
--- a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
+++ b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
@@ -12,6 +12,7 @@ package org.distorted.objectlib.touchcontrol;
 import org.distorted.library.helpers.QuatHelper;
 import org.distorted.library.type.Static3D;
 import org.distorted.library.type.Static4D;
+import org.distorted.objectlib.helpers.FactoryCubit;
 import org.distorted.objectlib.helpers.ObjectShape;
 import org.distorted.objectlib.main.TwistyObject;
 
@@ -76,7 +77,7 @@ public class TouchControlShapeChanging extends TouchControl
       normal[2] = vz;
       normal[3] = 0.0f;
 
-      if( totalAngle(vertices,normal)<0 )
+      if( FactoryCubit.totalAngle(vertices,normal)<0 )
         {
         normal[0] *= -1;
         normal[1] *= -1;
@@ -86,92 +87,6 @@ public class TouchControlShapeChanging extends TouchControl
       distance = normal[0]*v0[0] + normal[1]*v0[1] + normal[2]*v0[2];
       }
 
-    //////////////////////////////////////////////////////////
-    // this returns the total angle we get rotated about when
-    // we travel from the first vert to the last.
-    // It's always should be +2PI or -2PI, depending on if the
-    // verts are CW or CCW (when looking at the plane formed by
-    // the vertices from the direction the 'normal' vector
-    // points towards)
-    //
-    // The point: this way we can detect if the 'normal' vector
-    // is correct, i.e. if it points in the right direction.
-    // Sometimes it does not, when the first three vertices
-    // (from which the vector is computed) are 'concave'.
-
-    private float totalAngle(float[][] vert, float[] normal)
-      {
-      float ret = 0;
-      int num = vert.length;
-
-      for(int c=0; c<num; c++)
-        {
-        int n = (c==num-1 ? 0 : c+1);
-        int m = (n==num-1 ? 0 : n+1);
-        ret += angle( vert[c],vert[n],vert[m], normal);
-        }
-
-      return ret;
-      }
-
-    //////////////////////////////////////////////////////////
-
-    private float angle(float[] v0, float[] v1, float[] v2, float[] normal)
-      {
-      float px = v1[0] - v0[0];
-      float py = v1[1] - v0[1];
-      float pz = v1[2] - v0[2];
-
-      float rx = v2[0] - v1[0];
-      float ry = v2[1] - v1[1];
-      float rz = v2[2] - v1[2];
-
-      float l1 = (float)Math.sqrt(px*px + py*py + pz*pz);
-      float l2 = (float)Math.sqrt(rx*rx + ry*ry + rz*rz);
-
-      px /= l1;
-      py /= l1;
-      pz /= l1;
-
-      rx /= l2;
-      ry /= l2;
-      rz /= l2;
-
-      float s = px*rx + py*ry + pz*rz;
-
-      if( s> 1 ) s= 1;
-      if( s<-1 ) s=-1;
-
-      float a = (float) Math.acos(s);
-      float[] cross = crossProduct(px,py,pz,rx,ry,rz);
-
-      float ax = cross[0] + normal[0];
-      float ay = cross[1] + normal[1];
-      float az = cross[2] + normal[2];
-
-      float bx = cross[0] - normal[0];
-      float by = cross[1] - normal[1];
-      float bz = cross[2] - normal[2];
-
-      float f1 = ax*ax + ay*ay + az*az;
-      float f2 = bx*bx + by*by + bz*bz;
-
-      return f1>f2 ? a : -a;
-      }
-
-    //////////////////////////////////////////////////////////
-
-    private float[] crossProduct(float a1, float a2, float a3, float b1, float b2, float b3)
-      {
-      float[] ret = new float[3];
-
-      ret[0] = a2*b3 - a3*b2;
-      ret[1] = a3*b1 - a1*b3;
-      ret[2] = a1*b2 - a2*b1;
-
-      return ret;
-      }
-
     //////////////////////////////////////////////////////////
     public float[] getNormal()
       {
diff --git a/src/main/res/raw/coin_3.dmesh b/src/main/res/raw/coin_3.dmesh
index 1216f701..ad01b7b9 100644
Binary files a/src/main/res/raw/coin_3.dmesh and b/src/main/res/raw/coin_3.dmesh differ
