commit fa640198f93496ca2e767c2efbea3c95f6e94ad5
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Oct 28 16:48:14 2021 +0200

    Add to MeshPolygon a special modee to create a 2-band polygon with dense corners (needed to reduce number of vertices in side faces of the TwisttyPuzzle cubits)

diff --git a/src/main/java/org/distorted/library/mesh/MeshPolygon.java b/src/main/java/org/distorted/library/mesh/MeshPolygon.java
index 122cb76..987b8ab 100644
--- a/src/main/java/org/distorted/library/mesh/MeshPolygon.java
+++ b/src/main/java/org/distorted/library/mesh/MeshPolygon.java
@@ -45,8 +45,15 @@ public class MeshPolygon extends MeshBase
 
   private void computeNumberOfVertices()
      {
-     numVertices = (mNumPolygonVertices*mNumPolygonBands+2)*(mNumPolygonBands-1) - 1;
-     numVertices+= 2*mNumPolygonVertices*(2*extraIndex*extraVertices);
+     if( mNumPolygonBands==2 && extraIndex>0 )
+       {
+       numVertices = 1 + 2*mNumPolygonVertices*(1+extraIndex+2*extraVertices);
+       }
+     else
+       {
+       numVertices = (mNumPolygonVertices*mNumPolygonBands+2)*(mNumPolygonBands-1) - 1;
+       numVertices+= 2*mNumPolygonVertices*(2*extraIndex*extraVertices);
+       }
 
      remainingVert = numVertices;
      }
@@ -68,6 +75,20 @@ public class MeshPolygon extends MeshBase
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private float getSpecialQuot(int index)
+    {
+    int num = 1 + extraIndex + 2*extraVertices;
+    int change1 = extraVertices+1;
+    int change2 = num-change1;
+    float quot = 1.0f/(extraIndex+1);
+
+    if( index<change1 )      return index*quot/change1;
+    else if( index>change2 ) return 1-quot + (index-change2)*quot/change1;
+    else                     return (index-change1+1)*quot;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private float getQuot(int index, int band, boolean isExtra)
@@ -164,21 +185,26 @@ public class MeshPolygon extends MeshBase
         }
       }
 
-    int numPairs = mNumPolygonBands-1-polyBand;
+    boolean specialCase = mNumPolygonBands==2 && polyBand==0 && extraIndex>0;
     boolean isExtra = polyBand<extraIndex;
-
-    if( isExtra )
-      {
-      numPairs += 2*extraVertices;
-      }
+    int numPairs = specialCase ? extraIndex+1 : mNumPolygonBands-1-polyBand;
+    if( isExtra ) numPairs += 2*extraVertices;
 
     int polyEndVer = polyVertex==mNumPolygonVertices-1 ? 0 : polyVertex+1;
     float quot1, quot2;
 
     for(int index=0; index<numPairs; index++)
       {
-      quot1 = getQuot(index  ,polyBand+1, isExtra);
-      quot2 = getQuot(index+1,polyBand  , isExtra);
+      if( specialCase )
+        {
+        quot1 = 1.0f;
+        quot2 = getSpecialQuot(index+1);
+        }
+      else
+        {
+        quot1 = getQuot(index  ,polyBand+1, isExtra);
+        quot2 = getQuot(index+1,polyBand  , isExtra);
+        }
 
       vertex = addVertex(vertex,polyBand+1,polyVertex,polyEndVer,quot1,attribs1,attribs2);
       vertex = addVertex(vertex,polyBand  ,polyVertex,polyEndVer,quot2,attribs1,attribs2);
