Index: /issm/trunk/src/c/Bamgx/BamgObjects.h
===================================================================
--- /issm/trunk/src/c/Bamgx/BamgObjects.h	(revision 3251)
+++ /issm/trunk/src/c/Bamgx/BamgObjects.h	(revision 3252)
@@ -34,9 +34,4 @@
 	
 	/*INLINE functions{{{1*/
-	inline double det3x3(double A[3] ,double B[3],double C[3]){
-		return A[0]*( B[1]*C[2]-B[2]*C[1])
-		  - A[1]*( B[0]*C[2]-B[2]*C[0])
-		  + A[2]*( B[0]*C[1]-B[1]*C[0]);
-	}
 	inline  TriangleAdjacent Adj(const TriangleAdjacent & a)
 	  { return  a.Adj();}
@@ -73,9 +68,4 @@
 	/*}}}1*/
 
-	/*INLINE functions of CLASS GeometricalVertex{{{1*/
-	inline void GeometricalVertex::Set(const GeometricalVertex & rec,const Geometry & ,const Geometry & ){ 
-		*this  = rec;
-	  }
-	/*}}}1*/
 	/*INLINE functions of CLASS VertexOnVertex{{{1*/
 	inline void VertexOnVertex::Set(const Triangles & Th ,long i,Triangles & ThNew) { 
@@ -335,5 +325,4 @@
 
 	/*Other prototypes IN TRIANGLES.CPP (TO BE REORGANIZED){{{1*/
-	long AGoodNumberPrimeWith(long n);
 	TriangleAdjacent CloseBoundaryEdge(I2 ,Triangle *, double &,double &) ;
 	TriangleAdjacent CloseBoundaryEdgeV2(I2 A,Triangle *t, double &a,double &b);
Index: /issm/trunk/src/c/Bamgx/objects/GeometricalVertex.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/GeometricalVertex.h	(revision 3251)
+++ /issm/trunk/src/c/Bamgx/objects/GeometricalVertex.h	(revision 3252)
@@ -36,5 +36,7 @@
 
 			//Inline methods
-			inline void Set(const GeometricalVertex & rec,const Geometry & Gh ,const Geometry & GhNew);
+			inline void Set(const GeometricalVertex & rec,const Geometry & ,const Geometry & ){ 
+				*this  = rec;
+			}
 	};
 
Index: /issm/trunk/src/c/Bamgx/objects/R2.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/R2.h	(revision 3251)
+++ /issm/trunk/src/c/Bamgx/objects/R2.h	(revision 3252)
@@ -3,7 +3,5 @@
 #define _R2_H
 
-#include "../../shared/shared.h"
-#include "../../include/macros.h"
-#include "../../toolkits/toolkits.h"
+#include <cstdio>
 
 namespace bamg {
Index: /issm/trunk/src/c/Bamgx/objects/Triangles.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Triangles.cpp	(revision 3251)
+++ /issm/trunk/src/c/Bamgx/objects/Triangles.cpp	(revision 3252)
@@ -3596,5 +3596,5 @@
 		 *  [0 nbv[ all distincts*/
 		for (i=0;i<nbv;i++) ordre[i]= &vertices[i] ;
-		const long PrimeNumber= AGoodNumberPrimeWith(nbv) ;
+		const long PrimeNumber= BigPrimeNumber(nbv) ;
 		int   k0=rand()%nbv; 
 		for (int is3=0; is3<nbv; is3++){
@@ -3722,5 +3722,5 @@
 
 		/*construction of a random order*/
-		const long PrimeNumber= AGoodNumberPrimeWith(nbv)  ;
+		const long PrimeNumber= BigPrimeNumber(nbv)  ;
 		//remainder of the division of rand() by nbvnew
 		long k3 = rand()%nbvnew;
@@ -4304,5 +4304,5 @@
 		//allocate memory to r
 		r=(int*)xmalloc(nbv*sizeof(int));
-		int PrimeNumber= AGoodNumberPrimeWith(nbv) ;
+		int PrimeNumber= BigPrimeNumber(nbv) ;
 		int k0=rand()%nbv; 
 		for (int i=0; i<nbv; i++){
@@ -5655,34 +5655,4 @@
 	} 
 	/*}}}1*/
-	/*FUNCTION AGoodNumberPrimeWith{{{1*/
-	long AGoodNumberPrimeWith(long n){
-		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/AGoodNumberPrimeWith)*/
-
-		//list of big prime numbers
-		const long BigPrimeNumber[] ={ 567890359L,
-			567890431L,  567890437L,  567890461L,  567890471L,
-			567890483L,  567890489L,  567890497L,  567890507L,
-			567890591L,  567890599L,  567890621L,  567890629L , 0};
-
-		//initialize o and pi
-		long o =0;
-		long pi=BigPrimeNumber[1];
-
-		//loop until BigPrimeNumber[i]==0 (end of BigPrimeNumber)
-		for (int i=0; BigPrimeNumber[i]; i++){
-
-			//compute r, rest of the remainder of the division of BigPrimeNumber[i] by n
-			long r = BigPrimeNumber[i] % n;
-
-			/*compute oo = min ( r , n-r , |n - 2r|, |n-3r|)*/
-			long oo = Min(Min(r,n-r),Min(Abs(n-2*r),Abs(n-3*r)));
-			if ( o < oo){
-				o=oo;
-				pi=BigPrimeNumber[i];
-			}
-		}
-		return pi; 
-	}
-	/*}}}1*/
 	/*FUNCTION SwapForForcingEdge{{{1*/
 	int SwapForForcingEdge(Vertex   *  & pva ,Vertex  * &   pvb ,TriangleAdjacent & tt1,Icoor2 & dets1, Icoor2 & detsa,Icoor2 & detsb, int & NbSwap) {
Index: /issm/trunk/src/c/Bamgx/shared/shared.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/shared.h	(revision 3251)
+++ /issm/trunk/src/c/Bamgx/shared/shared.h	(revision 3252)
@@ -7,4 +7,5 @@
 #define _SHAREDBamg_H_
 
+#include "BigPrimeNumber.h"
 #include "TheVertex.h"
 #include "FindTriangleAdjacent.h"
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 3251)
+++ /issm/trunk/src/c/Makefile.am	(revision 3252)
@@ -358,4 +358,6 @@
 					./Bamgx/objects/Triangle.cpp\
 					./Bamgx/objects/Triangle.h\
+					./Bamgx/shared/BigPrimeNumber.h\
+					./Bamgx/shared/BigPrimeNumber.cpp\
 					./Bamgx/objects/Triangles.cpp\
 					./Bamgx/objects/Triangles.h\
@@ -724,4 +726,6 @@
 					./Bamgx/objects/Triangle.cpp\
 					./Bamgx/objects/Triangle.h\
+					./Bamgx/shared/BigPrimeNumber.h\
+					./Bamgx/shared/BigPrimeNumber.cpp\
 					./Bamgx/objects/Triangles.cpp\
 					./Bamgx/objects/Triangles.h\
Index: /issm/trunk/src/c/include/macros.h
===================================================================
--- /issm/trunk/src/c/include/macros.h	(revision 3251)
+++ /issm/trunk/src/c/include/macros.h	(revision 3252)
@@ -24,5 +24,5 @@
 	catch(ErrorException &exception){\
 		exception.Report(); \
-		mexErrMsgTxt(" ");\
+		mexErrMsgTxt(" "); \
 	}\
 	catch (exception& e) {\
Index: /issm/trunk/src/c/shared/TriMesh/TriMeshUtils.cpp
===================================================================
--- /issm/trunk/src/c/shared/TriMesh/TriMeshUtils.cpp	(revision 3251)
+++ /issm/trunk/src/c/shared/TriMesh/TriMeshUtils.cpp	(revision 3252)
@@ -3,8 +3,12 @@
  */
 
+#include <stdio.h>
+#include <assert.h>
+
 #include "./trimesh.h"
 
 #include "../Alloc/alloc.h"
-
+#include "../../include/macros.h"
+#include "../../include/typedefs.h"
 
 int IsGridOnRift(int* riftsegments, int nriftsegs, int grid){
@@ -985,4 +989,5 @@
 		/*Using the order vector, and the riftsegments_copy and riftspairs_copy, reorder the segments and the pairs: */
 		for (j=0;j<numsegs;j++){
+			assert(order[j]<numsegs);
 			*(riftsegments_copy+3*j+0)=*(riftsegments+3*order[j]+0);
 			*(riftsegments_copy+3*j+1)=*(riftsegments+3*order[j]+1);
