Index: /issm/trunk/src/c/Bamgx/include/macros.h
===================================================================
--- /issm/trunk/src/c/Bamgx/include/macros.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/include/macros.h	(revision 3280)
@@ -0,0 +1,29 @@
+#ifndef _BAMGMACROS_H
+#define _BAMGMACROS_H
+
+#include "./typedefs.h"
+
+namespace bamg {
+
+	const double Pi =3.141592653589793238462643383279502884197169399375105820974944592308;
+	const float  fPi=3.141592653589793238462643383279502884197169399375105820974944592308;
+	const  int   IsVertexOnGeom = 8;
+	const  int   IsVertexOnVertex = 16;
+	const  int   IsVertexOnEdge = 32;
+	static const short VerticesOfTriangularEdge[3][2] = {{1,2},{2,0},{0,1}};
+	static const short EdgesVertexTriangle[3][2] = {{1,2},{2,0},{0,1}};
+	static const short OppositeVertex[3] = {0,1,2};
+	static const short OppositeEdge[3] =  {0,1,2};
+	static const short NextEdge[3] = {1,2,0};
+	static const short PreviousEdge[3] = {2,0,1};
+	static const short NextVertex[3] = {1,2,0};
+	static const short PreviousVertex[3] = {2,0,1};
+#if LONG_BIT > 63
+	const  Icoor1 MaxICoor   = 1073741823; // 2^30-1 =111...111 (29 times)
+#else
+	const  Icoor1 MaxICoor   = 8388608;    // 2^23
+#endif
+	const  Icoor2 MaxICoor22 = Icoor2(2)*Icoor2(MaxICoor) * Icoor2(MaxICoor) ;
+}
+
+#endif
Index: /issm/trunk/src/c/Bamgx/include/typedefs.h
===================================================================
--- /issm/trunk/src/c/Bamgx/include/typedefs.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/include/typedefs.h	(revision 3280)
@@ -0,0 +1,20 @@
+#ifndef _BAMGTYPEDEFS_H
+#define _BAMGTYPEDEFS_H
+
+#include "../objects/R2.h"
+
+namespace bamg {
+
+	typedef int  Icoor1;  
+#if LONG_BIT > 63 //64 bits or more
+	typedef long Icoor2;
+#else //32 bits
+	typedef double Icoor2;
+#endif
+	typedef P2<Icoor1,Icoor2>  I2;
+	typedef P2xP2<short,long>  I2xI2;
+	typedef P2<double,double>  R2;
+	typedef P2<double,double>  R2xR2;
+}
+
+#endif
Index: sm/trunk/src/c/Bamgx/meshtype.h
===================================================================
--- /issm/trunk/src/c/Bamgx/meshtype.h	(revision 3279)
+++ 	(revision )
@@ -1,141 +1,0 @@
-#ifndef MESHTYPE_H
-#define MESHTYPE_H
-
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <cmath>
-#include <ctime>
-
-#include "objects/R2.h"
-#include "../shared/shared.h"
-#include "../include/macros.h"
-#include "../toolkits/toolkits.h"
-
-
-namespace bamg {
-
-	//typedefs
-	typedef int  Icoor1;  
-#if LONG_BIT > 63 //64 bits or more
-	typedef long Icoor2;
-#else //32 bits
-	typedef double Icoor2;
-#endif
-	typedef P2<Icoor1,Icoor2>  I2;
-	typedef P2xP2<short,long>  I2xI2;
-	typedef P2<double,double>  R2;
-	typedef P2<double,double>  R2xR2;
-
-	//Some parameters
-	const double Pi =3.141592653589793238462643383279502884197169399375105820974944592308;
-	const float  fPi=3.141592653589793238462643383279502884197169399375105820974944592308;
-	const  int   IsVertexOnGeom = 8;
-	const  int   IsVertexOnVertex = 16;
-	const  int   IsVertexOnEdge = 32;
-	static const short VerticesOfTriangularEdge[3][2] = {{1,2},{2,0},{0,1}};
-	static const short EdgesVertexTriangle[3][2] = {{1,2},{2,0},{0,1}};
-	static const short OppositeVertex[3] = {0,1,2};
-	static const short OppositeEdge[3] =  {0,1,2};
-	static const short NextEdge[3] = {1,2,0};
-	static const short PreviousEdge[3] = {2,0,1};
-	static const short NextVertex[3] = {1,2,0};
-	static const short PreviousVertex[3] = {2,0,1};
-#if LONG_BIT > 63
-	const  Icoor1 MaxICoor   = 1073741823; // 2^30-1 =111...111 (29 times)
-#else
-	const  Icoor1 MaxICoor   = 8388608;    // 2^23
-#endif
-	const  Icoor2 MaxICoor22 = Icoor2(2)*Icoor2(MaxICoor) * Icoor2(MaxICoor) ;
-
-	//template functions
-	template<class T> inline T Square (const T &a) { return a*a;} 
-	template<class T> inline T Min (const T &a,const T &b){return a < b ? a : b;}
-	template<class T> inline T Max (const T &a,const T & b){return a > b ? a : b;}
-	template<class T> inline T Abs (const T &a){return a <0 ? -a : a;}
-	template<class T> inline double Norme (const T &a){return sqrt(a*a);}
-	template<class T> inline void Exchange (T& a,T& b) {T c=a;a=b;b=c;}
-	template<class T> inline T Max3 (const T &a,const T & b,const T & c){return Max(Max(a,b),c);}
-	template<class T> inline T Min3 (const T &a,const T & b,const T & c){return Min(Min(a,b),c);}
-	template<class T> inline void  HeapSort(T *c,long n){
-		int l,j,r,i;
-		T   crit;
-		c--;                    //the array must starts at 1 and not 0 
-		if(n<=1) return;        //return if size <=1
-		l=n/2+1;                //initialize l and r
-		r=n;
-		for(;;){
-			if(l<=1){
-				crit  =c[r];
-				c[r--]=c[1];
-				if (r==1){c[1]=crit; return;}
-			}
-			else  crit = c[--l]; 
-			j=l;
-			for(;;){
-				i=j;
-				j=2*j;
-				if  (j>r) {c[i]=crit;break;}
-				if ((j<r) && (c[j] < c[j+1])) j++;//c[j+1]> c[j] -> take j+1 instead of j (larger value)
-				if (crit < c[j]) c[i]=c[j];       //c[j]  > crit -> stock this large value in i(<j)
-				else{c[i]=crit;break;}            //c[j]  < crit -> stock crit in i (<j)
-			}
-		}
-	}
-	template<class T> inline void  HeapSort(int** porder,T* c,int n){
-		int  l,j,r,i;
-		T    crit;
-		int  pos;
-		int* order=NULL;
-		order=(int*)xmalloc(n*sizeof(int));
-		for(i=0;i<n;i++) order[i]=i+1;
-		c--;                    //the array must starts at 1 and not 0 
-		order--;
-		if(n<=1) return;        //return if size <=1
-		l=n/2+1;                //initialize l and r
-		r=n;
-		for(;;){
-			if(l<=1){
-				crit  =c[r]; pos=order[r];
-				c[r--]=c[1]; order[r+1]=order[1];
-				if (r==1){
-					c[1]=crit; order[1]=pos;
-					order++;
-					*porder=order;
-					return;
-				}
-			}
-			else  {crit=c[--l]; pos=order[l];}
-			j=l;
-			for(;;){
-				i=j;
-				j=2*j;
-				if  (j>r) {c[i]=crit;order[i]=pos;break;}
-				if ((j<r) && (c[j] < c[j+1]))j++;
-				if (crit < c[j]) {c[i]=c[j];order[i]=order[j];} 
-				else{c[i]=crit;order[i]=pos;break;}
-			}
-		}
-	}
-
-	//Inline functions
-	inline int BinaryRand(){
-#ifdef RAND_MAX
-		/*RAND_MAX is defined by stdlib.h and is usually 32767*/
-		const long HalfRandMax = RAND_MAX/2;
-		return rand() < HalfRandMax;
-#else
-		/*For sun machines, RAND_MAX is not defined, use 2^24*/
-		return rand() & 16384;
-#endif
-	} 
-	inline float  OppositeAngle(float  a){return a<0 ? fPi+a:a-fPi;}
-	inline double OppositeAngle(double a){return a<0 ?  Pi+a:a- Pi;}
-
-	Icoor2 inline det(const I2 &a,const I2 & b,const I2 &c){
-		register  Icoor2 bax = b.x - a.x ,bay = b.y - a.y; 
-		register  Icoor2 cax = c.x - a.x ,cay = c.y - a.y; 
-		return  bax*cay - bay*cax;
-	}
-}
-#endif
Index: /issm/trunk/src/c/Bamgx/objects/CrackedEdge.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/CrackedEdge.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/CrackedEdge.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Vertex.h"
 #include "TriangleAdjacent.h"
Index: /issm/trunk/src/c/Bamgx/objects/Curve.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Curve.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/Curve.h	(revision 3280)
@@ -7,5 +7,7 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
+#include "../shared/shared.h"
 #include "GeometricalEdge.h"
 
Index: /issm/trunk/src/c/Bamgx/objects/Direction.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Direction.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/Direction.h	(revision 3280)
@@ -2,5 +2,7 @@
 #define _DIRECTION_H_
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
+#include "../shared/shared.h"
 
 namespace bamg {
Index: /issm/trunk/src/c/Bamgx/objects/DoubleAndInt.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/DoubleAndInt.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/DoubleAndInt.h	(revision 3280)
@@ -2,5 +2,6 @@
 #define _DOUBLEANDINT_H_
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 
 namespace bamg {
Index: /issm/trunk/src/c/Bamgx/objects/Edge.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Edge.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/Edge.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Vertex.h"
 #include "TriangleAdjacent.h"
Index: /issm/trunk/src/c/Bamgx/objects/GeometricalEdge.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/GeometricalEdge.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/GeometricalEdge.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Edge.h"
 #include "GeometricalVertex.h"
Index: /issm/trunk/src/c/Bamgx/objects/GeometricalSubDomain.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/GeometricalSubDomain.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/GeometricalSubDomain.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "GeometricalEdge.h"
 
Index: /issm/trunk/src/c/Bamgx/objects/GeometricalVertex.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/GeometricalVertex.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/GeometricalVertex.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Vertex.h"
 
Index: /issm/trunk/src/c/Bamgx/objects/Geometry.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Geometry.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/Geometry.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Vertex.h"
 #include "Edge.h"
Index: /issm/trunk/src/c/Bamgx/objects/ListofIntersectionTriangles.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/ListofIntersectionTriangles.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/ListofIntersectionTriangles.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Metric.h"
 #include "Vertex.h"
Index: /issm/trunk/src/c/Bamgx/objects/Metric.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Metric.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/Metric.h	(revision 3280)
@@ -7,5 +7,7 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
+#include "../shared/shared.h"
 #include "R2.h"
 
Index: /issm/trunk/src/c/Bamgx/objects/QuadTree.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/QuadTree.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/QuadTree.h	(revision 3280)
@@ -7,4 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 
 namespace bamg {
Index: /issm/trunk/src/c/Bamgx/objects/SubDomain.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/SubDomain.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/SubDomain.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Edge.h"
 #include "Triangle.h"
Index: /issm/trunk/src/c/Bamgx/objects/Triangle.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Triangle.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/Triangle.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Vertex.h"
 #include "TriangleAdjacent.h"
Index: /issm/trunk/src/c/Bamgx/objects/TriangleAdjacent.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/TriangleAdjacent.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/TriangleAdjacent.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Vertex.h"
 
Index: /issm/trunk/src/c/Bamgx/objects/Triangles.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Triangles.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/Triangles.h	(revision 3280)
@@ -7,5 +7,7 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
+#include "../shared/shared.h"
 #include "Metric.h"
 #include "SetOfE4.h"
Index: /issm/trunk/src/c/Bamgx/objects/Vertex.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Vertex.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/Vertex.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Direction.h"
 #include "Metric.h"
Index: /issm/trunk/src/c/Bamgx/objects/VertexOnEdge.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/VertexOnEdge.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/VertexOnEdge.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Vertex.h"
 #include "Edge.h"
Index: /issm/trunk/src/c/Bamgx/objects/VertexOnGeom.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/VertexOnGeom.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/VertexOnGeom.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Vertex.h"
 #include "GeometricalVertex.h"
Index: /issm/trunk/src/c/Bamgx/objects/VertexOnVertex.h
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/VertexOnVertex.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/objects/VertexOnVertex.h	(revision 3280)
@@ -7,5 +7,6 @@
 #include "../../toolkits/toolkits.h"
 
-#include "../meshtype.h"
+#include "../include/typedefs.h"
+#include "../include/macros.h"
 #include "Vertex.h"
 
Index: /issm/trunk/src/c/Bamgx/shared/Abs.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/Abs.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/shared/Abs.h	(revision 3280)
@@ -0,0 +1,9 @@
+#ifndef _BAMGABS_H_
+#define _BAMGABS_H_
+
+namespace bamg {
+
+	template<class T> inline T Abs (const T &a){return a <0 ? -a : a;}
+
+}
+#endif
Index: /issm/trunk/src/c/Bamgx/shared/BigPrimeNumber.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/BigPrimeNumber.cpp	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/shared/BigPrimeNumber.cpp	(revision 3280)
@@ -26,5 +26,5 @@
 
 			/*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)));
+			long oo =Min(Min(r,n-r),Min(Abs(n-2*r),Abs(n-3*r)));
 			if ( o < oo){
 				o=oo;
Index: /issm/trunk/src/c/Bamgx/shared/BigPrimeNumber.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/BigPrimeNumber.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/shared/BigPrimeNumber.h	(revision 3280)
@@ -2,5 +2,6 @@
 #define _BIGPRIMENUMBER_H_
 
-#include "../meshtype.h"
+#include "./Abs.h"
+#include "./extrema.h"
 
 namespace bamg {
Index: /issm/trunk/src/c/Bamgx/shared/BinaryRand.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/BinaryRand.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/shared/BinaryRand.h	(revision 3280)
@@ -0,0 +1,18 @@
+#ifndef _BINARYRAND_H_
+#define _BINARYRAND_H_
+
+#include <cstdlib>
+
+/*Return 1 or 0 randomly*/
+inline int BinaryRand(){
+	#ifdef RAND_MAX
+		/*RAND_MAX is defined by stdlib.h and is usually 32767*/
+		const long HalfRandMax = RAND_MAX/2;
+		return rand() < HalfRandMax;
+	#else
+		/*For sun machines, RAND_MAX is not defined, use 2^24*/
+		return rand() & 16384;
+	#endif
+} 
+
+#endif
Index: /issm/trunk/src/c/Bamgx/shared/Exchange.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/Exchange.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/shared/Exchange.h	(revision 3280)
@@ -0,0 +1,6 @@
+#ifndef _EXCHANGE_H_
+#define _EXCHANGE_H_
+
+template<class T> inline void Exchange (T &a,T &b) {T c=a;a=b;b=c;}
+
+#endif
Index: /issm/trunk/src/c/Bamgx/shared/HeapSort.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/HeapSort.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/shared/HeapSort.h	(revision 3280)
@@ -0,0 +1,67 @@
+#ifndef _HEAPSORT_H_
+#define _HEAPSORT_H_
+
+/*Sort a list of size n*/
+template<class T> inline void  HeapSort(T *c,long n){
+	int l,j,r,i;
+	T   crit;
+	c--;                    //the array must starts at 1 and not 0 
+	if(n<=1) return;        //return if size <=1
+	l=n/2+1;                //initialize l and r
+	r=n;
+	for(;;){
+		if(l<=1){
+			crit  =c[r];
+			c[r--]=c[1];
+			if (r==1){c[1]=crit; return;}
+		}
+		else  crit = c[--l]; 
+		j=l;
+		for(;;){
+			i=j;
+			j=2*j;
+			if  (j>r) {c[i]=crit;break;}
+			if ((j<r) && (c[j] < c[j+1])) j++;//c[j+1]> c[j] -> take j+1 instead of j (larger value)
+			if (crit < c[j]) c[i]=c[j];       //c[j]  > crit -> stock this large value in i(<j)
+			else{c[i]=crit;break;}            //c[j]  < crit -> stock crit in i (<j)
+		}
+	}
+}
+
+/*Sort a list of size n and returns ordering*/
+template<class T> inline void  HeapSort(int** porder,T* c,int n){
+	int  l,j,r,i;
+	T    crit;
+	int  pos;
+	int* order = new int[n];
+	for(i=0;i<n;i++) order[i]=i+1;
+	c--;                    //the array must starts at 1 and not 0 
+	order--;
+	if(n<=1) return;        //return if size <=1
+	l=n/2+1;                //initialize l and r
+	r=n;
+	for(;;){
+		if(l<=1){
+			crit  =c[r]; pos=order[r];
+			c[r--]=c[1]; order[r+1]=order[1];
+			if (r==1){
+				c[1]=crit; order[1]=pos;
+				order++;
+				*porder=order;
+				return;
+			}
+		}
+		else  {crit=c[--l]; pos=order[l];}
+		j=l;
+		for(;;){
+			i=j;
+			j=2*j;
+			if  (j>r) {c[i]=crit;order[i]=pos;break;}
+			if ((j<r) && (c[j] < c[j+1]))j++;
+			if (crit < c[j]) {c[i]=c[j];order[i]=order[j];}
+			else{c[i]=crit;order[i]=pos;break;}
+		}
+	}
+}
+
+#endif
Index: /issm/trunk/src/c/Bamgx/shared/Norm.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/Norm.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/shared/Norm.h	(revision 3280)
@@ -0,0 +1,8 @@
+#ifndef _BAMGNORM_H_
+#define _BAMGNORM_H_
+
+#include <math.h>
+
+template<class T> inline double Norm(const T &a){return sqrt(a*a);}
+
+#endif
Index: /issm/trunk/src/c/Bamgx/shared/OppositeAngle.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/OppositeAngle.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/shared/OppositeAngle.h	(revision 3280)
@@ -0,0 +1,12 @@
+#ifndef _OPPOSITEANGLE_H_
+#define _OPPOSITEANGLE_H_
+
+#include "../include/macros.h"
+
+/*Return the opposite angle modulo 2 Pi*/
+namespace bamg {
+	inline float  OppositeAngle(float  a){return a<0 ? fPi+a:a-fPi;}
+	inline double OppositeAngle(double a){return a<0 ?  Pi+a:a- Pi;}
+}
+
+#endif
Index: /issm/trunk/src/c/Bamgx/shared/det.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/det.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/shared/det.h	(revision 3280)
@@ -0,0 +1,15 @@
+#ifndef _BAMGDET_H_
+#define _BAMGDET_H_
+
+#include "../include/typedefs.h"
+
+namespace bamg {
+
+	Icoor2 inline det(const I2 &a,const I2 & b,const I2 &c){
+		register  Icoor2 bax = b.x - a.x ,bay = b.y - a.y; 
+		register  Icoor2 cax = c.x - a.x ,cay = c.y - a.y; 
+		return  bax*cay - bay*cax;
+	}
+
+}
+#endif
Index: /issm/trunk/src/c/Bamgx/shared/extrema.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/extrema.h	(revision 3280)
+++ /issm/trunk/src/c/Bamgx/shared/extrema.h	(revision 3280)
@@ -0,0 +1,13 @@
+#ifndef _EXTREMA_H_
+#define _EXTREMA_H_
+
+namespace bamg {
+
+	template<class T> inline T Min (const T &a,const T &b){return a < b ? a : b;}
+	template<class T> inline T Max (const T &a,const T & b){return a > b ? a : b;}
+	template<class T> inline T Max3 (const T &a,const T & b,const T & c){return Max(Max(a,b),c);}
+	template<class T> inline T Min3 (const T &a,const T & b,const T & c){return Min(Min(a,b),c);}
+
+}
+
+#endif
Index: /issm/trunk/src/c/Bamgx/shared/shared.h
===================================================================
--- /issm/trunk/src/c/Bamgx/shared/shared.h	(revision 3279)
+++ /issm/trunk/src/c/Bamgx/shared/shared.h	(revision 3280)
@@ -7,5 +7,12 @@
 #define _SHAREDBamg_H_
 
+#include "Abs.h"
 #include "BigPrimeNumber.h"
+#include "BinaryRand.h"
+#include "det.h"
+#include "Exchange.h"
+#include "extrema.h"
+#include "HeapSort.h"
+#include "OppositeAngle.h"
 
 #endif
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 3279)
+++ /issm/trunk/src/c/Makefile.am	(revision 3280)
@@ -329,8 +329,8 @@
 					./OutputRiftsx/OutputRiftsx.h\
 					./OutputRiftsx/OutputRiftsx.cpp\
-					./Bamgx/BamgObjects.h\
 					./Bamgx/Bamgx.cpp\
 					./Bamgx/Bamgx.h\
-					./Bamgx/meshtype.h\
+					./Bamgx/include/macros.h \
+					./Bamgx/include/typedefs.h \
 					./Bamgx/objects/CrackedEdge.h\
 					./Bamgx/objects/CrackedEdge.cpp\
@@ -380,4 +380,12 @@
 					./Bamgx/objects/VertexOnVertex.h\
 					./Bamgx/objects/VertexOnVertex.cpp\
+					./Bamgx/shared/Abs.h \
+					./Bamgx/shared/BinaryRand.h \
+					./Bamgx/shared/det.h \
+					./Bamgx/shared/Exchange.h \
+					./Bamgx/shared/extrema.h \
+					./Bamgx/shared/HeapSort.h \
+					./Bamgx/shared/Norm.h \
+					./Bamgx/shared/OppositeAngle.h \
 					./Bamgx/shared/shared.h
 
@@ -708,8 +716,8 @@
 					./parallel/steadystate_core.cpp\
 					./parallel/OutputResults.cpp\
-					./Bamgx/BamgObjects.h\
 					./Bamgx/Bamgx.cpp\
 					./Bamgx/Bamgx.h\
-					./Bamgx/meshtype.h\
+					./Bamgx/include/macros.h \
+					./Bamgx/include/typedefs.h \
 					./Bamgx/objects/CrackedEdge.h\
 					./Bamgx/objects/CrackedEdge.cpp\
@@ -759,4 +767,12 @@
 					./Bamgx/objects/VertexOnVertex.h\
 					./Bamgx/objects/VertexOnVertex.cpp\
+					./Bamgx/shared/Abs.h \
+					./Bamgx/shared/BinaryRand.h \
+					./Bamgx/shared/det.h \
+					./Bamgx/shared/Exchange.h \
+					./Bamgx/shared/extrema.h \
+					./Bamgx/shared/HeapSort.h \
+					./Bamgx/shared/Norm.h \
+					./Bamgx/shared/OppositeAngle.h \
 					./Bamgx/shared/shared.h
 
Index: /issm/trunk/src/c/include/typedefs.h
===================================================================
--- /issm/trunk/src/c/include/typedefs.h	(revision 3279)
+++ /issm/trunk/src/c/include/typedefs.h	(revision 3280)
@@ -12,3 +12,6 @@
 #define PI 3.141592653589793238462643383279502884197169399375105820974944592308
 
+const double Pi =3.141592653589793238462643383279502884197169399375105820974944592308;
+const float  fPi=3.141592653589793238462643383279502884197169399375105820974944592308;
+
 #endif //ifndef _ISSMTYPEDEFS_H_
Index: /issm/trunk/src/c/shared/Alloc/alloc.cpp
===================================================================
--- /issm/trunk/src/c/shared/Alloc/alloc.cpp	(revision 3279)
+++ /issm/trunk/src/c/shared/Alloc/alloc.cpp	(revision 3280)
@@ -68,6 +68,5 @@
 }
 
-void xfree( void* *pv)
-{
+void xfree( void* *pv){
 
 	if (pv && *pv) {
Index: /issm/trunk/src/c/shared/Alloc/alloc.h
===================================================================
--- /issm/trunk/src/c/shared/Alloc/alloc.h	(revision 3279)
+++ /issm/trunk/src/c/shared/Alloc/alloc.h	(revision 3280)
@@ -3,8 +3,6 @@
  */
 
-
 #ifndef _ALLOC_H_
 #define _ALLOC_H_
-
 
 void* xmalloc(int size);
