Index: /issm/trunk/src/c/Bamgx/QuadTree.h
===================================================================
--- /issm/trunk/src/c/Bamgx/QuadTree.h	(revision 2909)
+++ /issm/trunk/src/c/Bamgx/QuadTree.h	(revision 2910)
@@ -7,5 +7,5 @@
 	const int MaxDeep = 30;
 	typedef  long  IntQuad;
-	const IntQuad MaxISize = ( 1L << MaxDeep);
+	const IntQuad MaxISize = ( 1L << MaxDeep); //long int 1, bitwise operation: 8L = 00001000 << 2L -> 00100000 shifted left by 2
 	class Triangles;
 	class Vertex;
Index: /issm/trunk/src/c/Bamgx/objects/Geometry.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Geometry.cpp	(revision 2909)
+++ /issm/trunk/src/c/Bamgx/objects/Geometry.cpp	(revision 2910)
@@ -504,5 +504,5 @@
 		for (i=0;i<nbv;i++) vertices[i].link = vertices+i;
 
-		//build quadtree for this geometry (error if we have duplicates (k>0))
+		//build quadtree for this geometry
 		for (i=0;i<nbv;i++){
 
@@ -515,6 +515,8 @@
 			vertices[i].i=toI2(vertices[i].r); 
 
-			//Build the quadtree:
+			//find nearest vertex already present in the quadtree (NULL if empty)
 			Vertex* v=quadtree.NearestVertex(vertices[i].i.x,vertices[i].i.y); 
+
+			//if there is a vertex found that is to close to vertices[i] -> error
 			if( v && Norme1(v->r - vertices[i]) < eps ){
 				// mama's old trick to get j 
@@ -528,6 +530,11 @@
 				k++;	      
 			}
-			else  quadtree.Add(vertices[i]); //Add vertices[i] to the quadtree
-		}
+
+			//The nearest vertex was non existent or far enough from vertices[i]
+			//Add vertices[i] to the quadtree
+			else  quadtree.Add(vertices[i]);
+		}
+
+		//if k>0, there are some duplicate vertices -> error
 		if (k) {
 			printf("number of distinct vertices= %i, over %i\n",nbv - k,nbv);
Index: /issm/trunk/src/c/Bamgx/objects/QuadTree.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/QuadTree.cpp	(revision 2909)
+++ /issm/trunk/src/c/Bamgx/objects/QuadTree.cpp	(revision 2910)
@@ -15,11 +15,17 @@
 namespace bamg {
 
+	//INTER_SEG(a,b,x,y) returns 1 if [x y] is included in [a b]
 #define INTER_SEG(a,b,x,y) (((y) > (a)) && ((x) <(b)))
+	//ABS(i) retruns |i|
 #define ABS(i) ((i)<0 ?-(i) :(i))
+	//MAX1(i,j) returns max(i,j)
 #define MAX1(i,j) ((i)>(j) ?(i) :(j))
+	//NORM(i1,j1,i2,j2) returns max(|i1-j1|,|i2-j2|)
 #define NORM(i1,j1,i2,j2) MAX1(ABS((i1)-(j1)),ABS((i2)-(j2)))
-
+	//IJ(i,j,l) returns 3 if (1,1,1), 2 if (0,1,1), 1 if (1,0,1), else 0
 #define IJ(i,j,l) ( ( j & l) ? (( i & l) ? 3 : 2 ) :( ( i & l)? 1 : 0 ))
+	//I_IJ(k,l) retruns l if first  bit of k is 1, else 0
 #define I_IJ(k,l)  (( k&1) ? l : 0)
+	//J_IJ(k,l) retruns l if second bit of k is 1, else 0
 #define J_IJ(k,l)  (( k&2) ? l : 0)
 
@@ -46,11 +52,13 @@
 	/*FUNCTION QuadTree::QuadTree(){{{1*/
 	QuadTree::QuadTree() : 
-		lenStorageQuadTreeBox(100),
-		th(0),
-		NbQuadTreeBox(0),
-		NbVertices(0),
-		NbQuadTreeBoxSearch(0),
-		NbVerticesSearch(0){
-			sb =new StorageQuadTreeBox(lenStorageQuadTreeBox);
+		lenStorageQuadTreeBox(100), // by default 100 vertices by box
+		th(0),                      // initial mesh = NULL
+		NbQuadTreeBox(0),           // initial number of quadtree boxes = 0
+		NbVertices(0),              // initial number of vertices = 0
+		NbQuadTreeBoxSearch(0),     // initial ?? = 0
+		NbVerticesSearch(0){        // initial ?? = 0
+			//create lenStorageQuadTreeBox (100) StorageQuadTreeBox elements
+			sb  =new StorageQuadTreeBox(lenStorageQuadTreeBox); 
+			//root=QuadTreeBox* pointer roward ??
 			root=NewQuadTreeBox();
 		}
@@ -71,7 +79,7 @@
 		pb = &root;
 		while((b=*pb) && (b->n<0)){ 
-			b->n--;
-			l >>= 1;
-			pb = &b->b[IJ(i,j,l)];
+			b->n--;                //n=n-1 in b->n
+			l >>= 1;               //shifted righ by one bit: l=00000010 -> 00000001
+			pb = &b->b[IJ(i,j,l)]; //pointer toward b
 		}
 		if  (b) {      
@@ -81,6 +89,8 @@
 			if (b->n > 0 &&  b->v[0] == &w) return;
 		}
+
+		//check that l is still non zero
 		if (l==0){
-			throw ErrorException(__FUNCT__,exprintf("l==0"));
+			throw ErrorException(__FUNCT__,exprintf("l==0 cannot be true as it has been initialized as MaxISize = %i",MaxISize));
 		}
 		while ((b= *pb) && (b->n == 4)){ // the QuadTreeBox is full
@@ -121,8 +131,10 @@
 		IntQuad  hb=MaxISize;
 		Icoor1   i0=0,j0=0;
+		//iplus= i projected in [0,MaxISize-1] (example: if i<0, i=0)
 		Icoor1   iplus( i<MaxISize?(i<0?0:i):MaxISize-1);
+		//jplus= j projected in [0,MaxISize-1] (example: if j>=MaxISize, j=MaxISize-1)
 		Icoor1   jplus( j<MaxISize?(j<0?0:j):MaxISize-1);
-
-		Vertex *vn=0;
+		//initial nearest vertex pointer
+		Vertex*  vn=NULL;
 
 		//initialization for optimization
@@ -130,20 +142,22 @@
 		register Int4 n0;
 
-		if (!root->n) return vn; // empty tree 
-
+		//if the tree is empty, return NULL pointer
+		if (!root->n) return vn; 
+
+		//else: find the index n of the non empty
+		//QuadTreeBox containing  the point (i,j)
 		while( (n0 = b->n) < 0){
-			// search the non empty 
-			// QuadTreeBox containing  the point (i,j)
 			register Icoor1 hb2 = hb >> 1 ;
-			register  int k = IJ(iplus,jplus,hb2);// QuadTreeBox number of size hb2 contening i;j
-			register QuadTreeBox * b0= b->b[k];
-			if ( ( b0 == 0) || (b0->n == 0) ) break; // null box or empty   => break 	    
+			register  int k = IJ(iplus,jplus,hb2);// QuadTreeBox number of size hb2 containing i;j (Macro)
+			register QuadTreeBox* b0= b->b[k];
+			if (( b0 == 0) || (b0->n == 0)) break;// null box or empty   => break 	    
 			NbQuadTreeBoxSearch++;
 			b=b0;	
-			i0 += I_IJ(k,hb2); // i orign of QuadTreeBox
+			i0 += I_IJ(k,hb2); // i orign of QuadTreeBox (macro)
 			j0 += J_IJ(k,hb2); // j orign of QuadTreeBox 
 			hb = hb2; 
 		}
 
+		// if n0>0 ???
 		if ( n0 > 0){  
 			for(register int k=0;k<n0;k++){
@@ -169,5 +183,5 @@
 				register int k = pi[l];
 
-				if (b->n>0){ // Vertex QuadTreeBox none empty
+				if (b->n>0){ // Vertex QuadTreeBox not empty
 					NbVerticesSearch++;
 					I2 i2 =  b->v[k]->i;
@@ -179,5 +193,5 @@
 					  }
 				}
-				else{ // Pointer QuadTreeBox 
+				else{ // Pointer QuadTreeBox
 					register QuadTreeBox *b0=b;
 					NbQuadTreeBoxSearch++;
