commit fee0865c3b38ce79f1765e08ad8e442fd0fccbc2
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Mon Jun 20 11:31:50 2016 +0100

    Fix for adding a single DistortedObject to a DistortedNode tree multiple times.

diff --git a/src/main/java/org/distorted/library/DistortedNode.java b/src/main/java/org/distorted/library/DistortedNode.java
index 27ec28e..0e35aff 100644
--- a/src/main/java/org/distorted/library/DistortedNode.java
+++ b/src/main/java/org/distorted/library/DistortedNode.java
@@ -234,16 +234,18 @@ public class DistortedNode
 
   private void adjustNodeData(ArrayList<Long> oldList, ArrayList<Long> newList)
     {
-    if( mData.numPointingNodes>1 ) mData.numPointingNodes--;
-    else                           mMapNodeID.remove(oldList);  
+    boolean otherNodesPoint = (mData.numPointingNodes>1);
+
+    if( otherNodesPoint ) mData.numPointingNodes--;
+    else                  mMapNodeID.remove(oldList);
    
     NodeData newData = mMapNodeID.get(newList);
     
     if( newData==null )
       {
-      mData.ID = ++mNextNodeID;  
-      mData.numPointingNodes = 1;
-     
+      if( otherNodesPoint )  mData = new NodeData(++mNextNodeID);
+      else                   mData.ID = ++mNextNodeID;  // numPointingNodes must be 1 already
+
       if( newList.size()>1 && mData.mProjection==null )
         {     
         mData.mProjection = new DistortedProjection(true);
@@ -255,7 +257,7 @@ public class DistortedNode
       mMapNodeID.put(newList, mData);
       }
     else
-      {  
+      {
       newData.numPointingNodes++;
       mData = newData;
       }
@@ -280,7 +282,39 @@ public class DistortedNode
         }
       }
     }
-  
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Debug - print all the Node IDs
+
+  void debug(int depth)
+    {
+    String tmp="";
+    int i;
+
+    for(i=0; i<depth; i++) tmp +="   ";
+    tmp += (""+mData.ID);
+
+    android.util.Log.e("node", tmp);
+
+    for(i=0; i<mNumChildren[0]; i++)
+      mChildren.get(i).debug(depth+1);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Debug - print contents of the HashMap
+
+  static void debugMap()
+    {
+    NodeData tmp;
+
+    for(ArrayList<Long> key: mMapNodeID.keySet())
+      {
+      tmp = mMapNodeID.get(key);
+
+      android.util.Log.e("NODE", "key="+key+" NodeID: "+tmp.ID);
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -392,7 +426,7 @@ public class DistortedNode
     mNumChildren[0]++;
    
     RecomputeNodeID(prev);
-   
+
     return node;
     }
   
@@ -503,23 +537,6 @@ public class DistortedNode
     {
     return mObject;
     }
-  
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Debug - print all the Node IDs
-
-  public void debug(int depth)
-    {
-    String tmp="";  
-    int i;
-   
-    for(i=0; i<depth; i++) tmp +="   ";
-    tmp += (""+mData.ID);
-   
-    android.util.Log.e("node", tmp);
-   
-    for(i=0; i<mNumChildren[0]; i++)
-      mChildren.get(i).debug(depth+1);
-    }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
   }
