commit 1e22c2484ae39920e4fb3520c30aec22b5811416
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Fri Oct 21 12:34:40 2016 +0100

    Fix 4D and 5D noise, make noise N dimensional.

diff --git a/src/main/java/org/distorted/library/type/Dynamic.java b/src/main/java/org/distorted/library/type/Dynamic.java
index e7d3eb7..0134123 100644
--- a/src/main/java/org/distorted/library/type/Dynamic.java
+++ b/src/main/java/org/distorted/library/type/Dynamic.java
@@ -78,7 +78,6 @@ public abstract class Dynamic
   protected int mMode;          // LOOP, PATH or JUMP
   protected long mDuration;     // number of milliseconds it takes to do a full loop/path from first vector to the last and back to the first
   protected float mCount;       // number of loops/paths we will do; mCount = 1.5 means we go from the first vector to the last, back to first, and to the last again. 
-  protected float mNoise;       // how 'smooth' our path form each vector to the next is. mNoise = 0.0 (min) --> completely smooth; mNoise==1.0 (max) --> very uneven
 
   protected class VectorNoise
     {
@@ -102,6 +101,7 @@ public abstract class Dynamic
 
   protected Vector<VectorNoise> vn;
   protected float[] mFactor;
+  protected float[] mNoise;
   protected float[][] baseV;
   private float[] buffer;
 
@@ -218,11 +218,11 @@ public abstract class Dynamic
 
     switch(index)
       {
-      case 0        : for(int i=0;i<mDimension-1;i++) mFactor[i] = mNoise*tmpN.n[i+1][0]*t;
-                      return time + mNoise*(d*tmpN.n[0][0]-time);
-      case NUM_NOISE: for(int i=0;i<mDimension-1;i++) mFactor[i] = mNoise*tmpN.n[i+1][NUM_NOISE-1]*(1-t);
+      case 0        : for(int i=0;i<mDimension-1;i++) mFactor[i] = mNoise[i+1]*tmpN.n[i+1][0]*t;
+                      return time + mNoise[0]*(d*tmpN.n[0][0]-time);
+      case NUM_NOISE: for(int i=0;i<mDimension-1;i++) mFactor[i] = mNoise[i+1]*tmpN.n[i+1][NUM_NOISE-1]*(1-t);
                       len = ((float)NUM_NOISE)/(NUM_NOISE+1);
-                      lower = len + mNoise*(tmpN.n[0][NUM_NOISE-1]-len);
+                      lower = len + mNoise[0]*(tmpN.n[0][NUM_NOISE-1]-len);
                       return (1.0f-lower)*(d-NUM_NOISE) + lower;
       default       : float ya,yb;
 
@@ -230,13 +230,13 @@ public abstract class Dynamic
                         {
                         yb = tmpN.n[i+1][index  ];
                         ya = tmpN.n[i+1][index-1];
-                        mFactor[i] = mNoise*((yb-ya)*t+ya);
+                        mFactor[i] = mNoise[i+1]*((yb-ya)*t+ya);
                         }
 
                       len = ((float)index)/(NUM_NOISE+1);
-                      lower = len + mNoise*(tmpN.n[0][index-1]-len);
+                      lower = len + mNoise[0]*(tmpN.n[0][index-1]-len);
                       len = ((float)index+1)/(NUM_NOISE+1);
-                      upper = len + mNoise*(tmpN.n[0][index  ]-len);
+                      upper = len + mNoise[0]*(tmpN.n[0][index  ]-len);
 
                       return (upper-lower)*(d-index) + lower;
       }
@@ -562,36 +562,6 @@ public abstract class Dynamic
     mDuration = duration;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Sets the 'smoothness' of interpolation. 
- * <p>
- * When Noise=0 (the default), we interpolate between our Points through the most smooth path possible. 
- * Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding
- * up and slowing down, etc.
- * 
- * @param noise The noise level. Permitted range: 0 <= noise <= 1.
- */
-  
-  public synchronized void setNoise(float noise)
-    {
-    if( mNoise==0.0f && noise != 0.0f && vn==null )
-      {
-      vn = new Vector<>();
-      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
-
-      if( mDimension>=2 )
-        {
-        mFactor = new float[mDimension-1];
-        }
-      }
-   
-    if( mNoise<0.0f ) mNoise = 0.0f;
-    if( mNoise>1.0f ) mNoise = 1.0f;
-   
-    mNoise = noise;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // end of DistortedInterpolator
   }
diff --git a/src/main/java/org/distorted/library/type/Dynamic1D.java b/src/main/java/org/distorted/library/type/Dynamic1D.java
index 396a570..9759759 100644
--- a/src/main/java/org/distorted/library/type/Dynamic1D.java
+++ b/src/main/java/org/distorted/library/type/Dynamic1D.java
@@ -341,7 +341,39 @@ public class Dynamic1D extends Dynamic implements Data1D
    
     if( vn!=null ) vn.removeAllElements();
     }
- 
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Sets the 'smoothness' of interpolation.
+ * <p>
+ * When Noise=0 (the default), we interpolate between our Points through the most smooth path possible.
+ * Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding
+ * up and slowing down, etc.
+ *
+ * @param noise The noise level. Permitted range: 0 <= noise <= 1.
+ */
+
+  public synchronized void setNoise(Static1D noise)
+    {
+    if( vn==null )
+      {
+      vn = new Vector<>();
+      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
+
+      if( mDimension>=2 )
+        {
+        mFactor = new float[mDimension-1];
+        }
+
+      mNoise = new float[mDimension];
+      }
+
+    if( noise.x<0.0f ) noise.x = 0.0f;
+    if( noise.x>1.0f ) noise.x = 1.0f;
+
+    mNoise[0] = noise.x;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Writes the results of interpolation between the Points at time 'time' to the passed float buffer.
diff --git a/src/main/java/org/distorted/library/type/Dynamic2D.java b/src/main/java/org/distorted/library/type/Dynamic2D.java
index c43df07..7cf99d8 100644
--- a/src/main/java/org/distorted/library/type/Dynamic2D.java
+++ b/src/main/java/org/distorted/library/type/Dynamic2D.java
@@ -360,6 +360,41 @@ public class Dynamic2D extends Dynamic implements Data2D
     if( vn!=null ) vn.removeAllElements();
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Sets the 'smoothness' of interpolation.
+ * <p>
+ * When Noise=0 (the default), we interpolate between our Points through the most smooth path possible.
+ * Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding
+ * up and slowing down, etc.
+ *
+ * @param noise The noise level. Permitted range: 0 <= noise <= 1.
+ */
+
+  public synchronized void setNoise(Static2D noise)
+    {
+    if( vn==null )
+      {
+      vn = new Vector<>();
+      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
+
+      if( mDimension>=2 )
+        {
+        mFactor = new float[mDimension-1];
+        }
+
+      mNoise = new float[mDimension];
+      }
+
+    if( noise.x<0.0f ) noise.x = 0.0f;
+    if( noise.x>1.0f ) noise.x = 1.0f;
+    if( noise.y<0.0f ) noise.y = 0.0f;
+    if( noise.y>1.0f ) noise.y = 1.0f;
+
+    mNoise[0] = noise.x;
+    mNoise[1] = noise.y;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Writes the results of interpolation between the Points at time 'time' to the passed float buffer.
diff --git a/src/main/java/org/distorted/library/type/Dynamic3D.java b/src/main/java/org/distorted/library/type/Dynamic3D.java
index 58f8cfc..bcec7a6 100644
--- a/src/main/java/org/distorted/library/type/Dynamic3D.java
+++ b/src/main/java/org/distorted/library/type/Dynamic3D.java
@@ -379,7 +379,45 @@ public class Dynamic3D extends Dynamic implements Data3D
    
     if( vn!=null ) vn.removeAllElements();
     }
-  
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Sets the 'smoothness' of interpolation.
+ * <p>
+ * When Noise=0 (the default), we interpolate between our Points through the most smooth path possible.
+ * Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding
+ * up and slowing down, etc.
+ *
+ * @param noise The noise level. Permitted range: 0 <= noise <= 1.
+ */
+
+  public synchronized void setNoise(Static3D noise)
+    {
+    if( vn==null )
+      {
+      vn = new Vector<>();
+      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
+
+      if( mDimension>=2 )
+        {
+        mFactor = new float[mDimension-1];
+        }
+
+      mNoise = new float[mDimension];
+      }
+
+    if( noise.x<0.0f ) noise.x = 0.0f;
+    if( noise.x>1.0f ) noise.x = 1.0f;
+    if( noise.y<0.0f ) noise.y = 0.0f;
+    if( noise.y>1.0f ) noise.y = 1.0f;
+    if( noise.z<0.0f ) noise.z = 0.0f;
+    if( noise.z>1.0f ) noise.z = 1.0f;
+
+    mNoise[0] = noise.x;
+    mNoise[1] = noise.y;
+    mNoise[2] = noise.z;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Writes the results of interpolation between the Points at time 'time' to the passed float buffer.
diff --git a/src/main/java/org/distorted/library/type/Dynamic4D.java b/src/main/java/org/distorted/library/type/Dynamic4D.java
index fb21502..e7ed51e 100644
--- a/src/main/java/org/distorted/library/type/Dynamic4D.java
+++ b/src/main/java/org/distorted/library/type/Dynamic4D.java
@@ -395,7 +395,48 @@ public class Dynamic4D extends Dynamic implements Data4D
    
     if( vn!=null ) vn.removeAllElements();
     }
-  
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Sets the 'smoothness' of interpolation.
+ * <p>
+ * When Noise=0 (the default), we interpolate between our Points through the most smooth path possible.
+ * Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding
+ * up and slowing down, etc.
+ *
+ * @param noise The noise level. Permitted range: 0 <= noise <= 1.
+ */
+
+  public synchronized void setNoise(Static4D noise)
+    {
+    if( vn==null )
+      {
+      vn = new Vector<>();
+      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
+
+      if( mDimension>=2 )
+        {
+        mFactor = new float[mDimension-1];
+        }
+
+      mNoise = new float[mDimension];
+      }
+
+    if( noise.x<0.0f ) noise.x = 0.0f;
+    if( noise.x>1.0f ) noise.x = 1.0f;
+    if( noise.y<0.0f ) noise.y = 0.0f;
+    if( noise.y>1.0f ) noise.y = 1.0f;
+    if( noise.z<0.0f ) noise.z = 0.0f;
+    if( noise.z>1.0f ) noise.z = 1.0f;
+    if( noise.w<0.0f ) noise.w = 0.0f;
+    if( noise.w>1.0f ) noise.w = 1.0f;
+
+    mNoise[0] = noise.x;
+    mNoise[1] = noise.y;
+    mNoise[2] = noise.z;
+    mNoise[3] = noise.w;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Writes the results of interpolation between the Points at time 'time' to the passed float buffer.
@@ -435,7 +476,7 @@ public class Dynamic4D extends Dynamic implements Data4D
                 buffer[offset  ] = (next.x-curr.x)*time + curr.x + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1] + baseV[3][0]*mFactor[2]);
                 buffer[offset+1] = (next.y-curr.y)*time + curr.y + (baseV[1][1]*mFactor[0] + baseV[2][1]*mFactor[1] + baseV[3][1]*mFactor[2]);
                 buffer[offset+2] = (next.z-curr.z)*time + curr.z + (baseV[1][2]*mFactor[0] + baseV[2][2]*mFactor[1] + baseV[3][2]*mFactor[2]);
-                buffer[offset+3] = (next.z-curr.z)*time + curr.z + (baseV[1][3]*mFactor[0] + baseV[2][3]*mFactor[1] + baseV[3][3]*mFactor[2]);
+                buffer[offset+3] = (next.w-curr.w)*time + curr.w + (baseV[1][3]*mFactor[0] + baseV[2][3]*mFactor[1] + baseV[3][3]*mFactor[2]);
                 }
               else
                 {
diff --git a/src/main/java/org/distorted/library/type/Dynamic5D.java b/src/main/java/org/distorted/library/type/Dynamic5D.java
index a16e7a5..01846be 100644
--- a/src/main/java/org/distorted/library/type/Dynamic5D.java
+++ b/src/main/java/org/distorted/library/type/Dynamic5D.java
@@ -411,7 +411,51 @@ public class Dynamic5D extends Dynamic implements Data5D
    
     if( vn!=null ) vn.removeAllElements();
     }
-  
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Sets the 'smoothness' of interpolation.
+ * <p>
+ * When Noise=0 (the default), we interpolate between our Points through the most smooth path possible.
+ * Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding
+ * up and slowing down, etc.
+ *
+ * @param noise The noise level. Permitted range: 0 <= noise <= 1.
+ */
+
+  public synchronized void setNoise(Static5D noise)
+    {
+    if( vn==null )
+      {
+      vn = new Vector<>();
+      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
+
+      if( mDimension>=2 )
+        {
+        mFactor = new float[mDimension-1];
+        }
+
+      mNoise = new float[mDimension];
+      }
+
+    if( noise.x<0.0f ) noise.x = 0.0f;
+    if( noise.x>1.0f ) noise.x = 1.0f;
+    if( noise.y<0.0f ) noise.y = 0.0f;
+    if( noise.y>1.0f ) noise.y = 1.0f;
+    if( noise.z<0.0f ) noise.z = 0.0f;
+    if( noise.z>1.0f ) noise.z = 1.0f;
+    if( noise.w<0.0f ) noise.w = 0.0f;
+    if( noise.w>1.0f ) noise.w = 1.0f;
+    if( noise.v<0.0f ) noise.v = 0.0f;
+    if( noise.v>1.0f ) noise.v = 1.0f;
+
+    mNoise[0] = noise.x;
+    mNoise[1] = noise.y;
+    mNoise[2] = noise.z;
+    mNoise[3] = noise.w;
+    mNoise[4] = noise.v;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Writes the results of interpolation between the Points at time 'time' to the passed float buffer.
@@ -453,8 +497,8 @@ public class Dynamic5D extends Dynamic implements Data5D
                 buffer[offset  ] = (next.x-curr.x)*time + curr.x + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1] + baseV[3][0]*mFactor[2] + baseV[4][0]*mFactor[3]);
                 buffer[offset+1] = (next.y-curr.y)*time + curr.y + (baseV[1][1]*mFactor[0] + baseV[2][1]*mFactor[1] + baseV[3][1]*mFactor[2] + baseV[4][1]*mFactor[3]);
                 buffer[offset+2] = (next.z-curr.z)*time + curr.z + (baseV[1][2]*mFactor[0] + baseV[2][2]*mFactor[1] + baseV[3][2]*mFactor[2] + baseV[4][2]*mFactor[3]);
-                buffer[offset+3] = (next.z-curr.z)*time + curr.z + (baseV[1][3]*mFactor[0] + baseV[2][3]*mFactor[1] + baseV[3][3]*mFactor[2] + baseV[4][3]*mFactor[3]);
-                buffer[offset+4] = (next.z-curr.z)*time + curr.z + (baseV[1][4]*mFactor[0] + baseV[2][4]*mFactor[1] + baseV[3][4]*mFactor[2] + baseV[4][4]*mFactor[3]);
+                buffer[offset+3] = (next.w-curr.w)*time + curr.w + (baseV[1][3]*mFactor[0] + baseV[2][3]*mFactor[1] + baseV[3][3]*mFactor[2] + baseV[4][3]*mFactor[3]);
+                buffer[offset+4] = (next.v-curr.v)*time + curr.v + (baseV[1][4]*mFactor[0] + baseV[2][4]*mFactor[1] + baseV[3][4]*mFactor[2] + baseV[4][4]*mFactor[3]);
                 }
               else
                 {
diff --git a/src/main/java/org/distorted/library/type/DynamicQuat.java b/src/main/java/org/distorted/library/type/DynamicQuat.java
index 152eab7..1b998f6 100644
--- a/src/main/java/org/distorted/library/type/DynamicQuat.java
+++ b/src/main/java/org/distorted/library/type/DynamicQuat.java
@@ -133,7 +133,6 @@ public class DynamicQuat extends Dynamic implements Data4D
     mMode = MODE_LOOP;
     mDuration = duration;
     mCount = count;
-    mNoise = 0.0f;
     mDimension = 4;
     }
 
