Index: src/border.cpp
===================================================================
--- src/border.cpp	(revision 03648b9b7a0304a1d85f5faf7250acf9fcbbbe04)
+++ src/border.cpp	(revision 1ffa216657b5beb85210757a5d292a8b64bd5b79)
@@ -1,8 +1,4 @@
 #include "molecules.hpp"
 #include "boundary.hpp"
-
-
-
-
 
 
@@ -12,21 +8,21 @@
    * d1 ist der Vektor, der normal auf der Kante und d2 steht.
    */
-  Vector *dif_a;
-  Vector *dif_b;
-  Vector *Chord;
-  Vector *AngleCheck;
+  Vector dif_a;
+  Vector dif_b;
+  Vector Chord;
+  Vector AngleCheck;
   atom *Walker;
 
-  dif_a.CopyVector(a.x);
-  dif_a.SubtractVector(Candidate->x);
-  dif_b.CopyVector(b.x);
-  dif.b.SubtractVector(Candidate->x);
-  Chord.CopyVector(a.x);
-  Chord.SubtractVector(b.x);
-  AngleCheck.CopyVector(dif_a);
-  AngleCheck.ProjectOntoPlane(Chord);
+  dif_a.CopyVector(&a.x);
+  dif_a.SubtractVector(&Candidate.x);
+  dif_b.CopyVector(&b.x);
+  dif_b.SubtractVector(&Candidate.x);
+  Chord.CopyVector(&a.x);
+  Chord.SubtractVector(&b.x);
+  AngleCheck.CopyVector(&dif_a);
+  AngleCheck.ProjectOntoPlane(&Chord);
 
   //Storage eintrag fuer aktuelles Atom
-  if (Chord.Norm/(2*sin(dif_a.Angle(dif.b)))<RADIUS) //Using Formula for relation of chord length with inner angle to find of Ball will touch atom
+  if (Chord.Norm()/(2*sin(dif_a.Angle(&dif_b)))<RADIUS) //Using Formula for relation of chord length with inner angle to find of Ball will touch atom
   {
 
@@ -44,5 +40,5 @@
 	  {
 	    Storage[0]=(double)Candidate.nr;
-	    Storage[1]=dif_a.ScalarProduct(d1)/fabs(dif.ScalarProduct(d1));
+	    Storage[1]=dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1));
 	    Storage[2]=AngleCheck.Angle(d2);
 	  }
@@ -52,36 +48,37 @@
   if (n<5)
     {
-      for(i=0; i<mol.NumberOfBondsPerAtom[Candidate.nr];i++)
-	{
-	  while (Candidate.nr != mol->ListOfBonds[Candidate.nr][i])
+      for(int i=0; i<mol.NumberOfBondsPerAtom[Candidate.nr];i++)
+	{
+	  while (Candidate.nr != (mol.ListOfBondsPerAtom[Candidate.nr][i]->leftatom->nr ==Candidate.nr ? mol.ListOfBondsPerAtom[Candidate.nr][i]->leftatom->nr : mol.ListOfBondsPerAtom[Candidate.nr][i]->rightatom->nr))
 	    {
-	      Walker = Walker.next;
+	      Walker = Walker->next;
 	    }
 
-	  Find_next_suitable_point(a, b, Walker, n+1, d1, d2, RADIUS, mol);
-	}
-    }
-}
-
-
-void Find_next_suitable_triangle(molecule mol, BoundaryLineSet Line, BoundaryTriangleSet T)
-{
-  Vector CenterOfLine = Line->endpoints.node[0].x;
+	  Find_next_suitable_point(a, b, *Walker, n+1, d1, d2, Storage, RADIUS, mol);
+	}
+    }
+};
+
+
+void Tesselation::Find_next_suitable_triangle(molecule *mol, BoundaryLineSet Line, BoundaryTriangleSet T, const double& RADIUS)
+{
+  Vector CenterOfLine = Line.endpoints[0]->node->x;
   Vector direction1;
   Vector direction2;
   Vector helper;
-
-  double *Storage[3];
-  Storage[0]=-1;   // Id must be positive, we see should nothing be done
-  Storage[1]=-1;   // This direction is either +1 or -1 one, so any result will take precedence over initial values
-  Storage[2]=-10;  // This is also lower then any value produced by an eligible atom, which are all positive
-
-  
-  helper.CopyVector(Line->endpoints[0].x);
+  atom* Walker;
+
+  double Storage[3];
+  Storage[0]=-1.;   // Id must be positive, we see should nothing be done
+  Storage[1]=-1.;   // This direction is either +1 or -1 one, so any result will take precedence over initial values
+  Storage[2]=-10.;  // This is also lower then any value produced by an eligible atom, which are all positive
+
+  
+  helper.CopyVector(&(Line.endpoints[0]->node->x));
   for (int i =0; i<3; i++)
     {
-      if (T->endpoints[i].node.nr != Line->endpoints[0].node.nr && T->endpoints[i].node.nr!=Line->endpoints[1].node.nr)
-	{
-	  helper.SubtractVector(T->endpoints[i].x);
+      if (T.endpoints[i]->node->nr != Line.endpoints[0]->node->nr && T.endpoints[i]->node->nr!=Line.endpoints[1]->node->nr)
+	{
+	  helper.SubtractVector(&T.endpoints[i]->node->x);
 	  break;
 	}
@@ -89,20 +86,20 @@
 
 
-  direction1.CopyVector(Line->endpoints.node[0].x);
-  direction1.Subtract(Line->endpoints.node[1].x);
-  direction1.Crossproduct(T.NormalVector);
-
-  if (direction1.ScalarProduct(helper)>0)
+  direction1.CopyVector(&Line.endpoints[0]->node->x);
+  direction1.SubtractVector(&Line.endpoints[1]->node->x);
+  direction1.VectorProduct(T.NormalVector);
+
+  if (direction1.ScalarProduct(&helper)>0)
     {
       direction1.Scale(-1);
     }
 
-  Find_next_suitable_point(Line->endpoints.node[0], Line->endpoints.node[1], Line->endpoints->node[0], 0, direction1, T.NormalVector, Storage, RADIUS);
+  Find_next_suitable_point(*Line.endpoints[0]->node, *Line.endpoints[1]->node, *Line.endpoints[0]->node, 0, &direction1, T.NormalVector, Storage, RADIUS, *mol);
   
   // Konstruiere nun neues Dreieck am Ende der Liste der Dreiecke
   // Next Triangle is Line, atom with number in Storage[0]
 
-  Walker=mol->start;
-  while (Walker.nr != (int)Storage[0])
+  Walker= mol->start;
+  while (Walker->nr != (int)Storage[0])
     {
       Walker = Walker->next;
@@ -111,11 +108,11 @@
   AddPoint(Walker);
 
-  BPS[0] = BoundaryPointSet(Walker);
-  BPS[1] = Line->enpoints.node[0];
+  BPS[0] = new class BoundaryPointSet(Walker);
+  BPS[1] = new class BoundaryPointSet(Line.endpoints[0]->node);
   BLS[0] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
-  BPS[0] = Walker;
-  BPS[1] = Line->endpoints.node[1];
+  BPS[0] = new class BoundaryPointSet(Walker);
+  BPS[1] = new class BoundaryPointSet(Line.endpoints[1]->node);
   BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
-  BLS[2] = line;
+  BLS[2] = new class BoundaryLineSet(Line);
 
   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
@@ -125,5 +122,5 @@
   for(int i=0;i<NDIM;i++) // sind Linien bereits vorhanden ???
     {
-      if (LinesOnBoundary.find(BTS->lines[i]) == LinesOnBoundary->end)
+      if (LinesOnBoundary.find(BTS->lines[i]) == LinesOnBoundary.end)
 	{
 	  LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BTS->lines[i]) );
@@ -131,17 +128,50 @@
 	}
     }
-  GetNormalVector(BTS.NormalVector);
-
-  if( (BTS.NormalVector.ScalarProduct(T.NormalVecotr)<0 && Storage[1]>0) || \
-      (BTS.NormalVector.ScalarProduct(T.NormalVecotr)>0 && Storage[1]<0))
-    {
-      BTS.NormalVector.Scale(-1);
-    }
-  
-}
-
-
-void Find_starting_triangle(molecule mol)
-{
+  BTS->GetNormalVector(*BTS->NormalVector);
+
+  if( (BTS->NormalVector->ScalarProduct(T.NormalVector)<0 && Storage[1]>0) || \
+      (BTS->NormalVector->ScalarProduct(T.NormalVector)>0 && Storage[1]<0))
+    {
+      BTS->NormalVector->Scale(-1);
+    }
+  
+};
+
+
+void Find_second_point_for_Tesselation(atom a, atom Candidate, int n, Vector Oben, double* Storage, molecule mol)
+{
+  int i;
+  Vector *AngleCheck;
+  atom* Walker;
+
+  AngleCheck->CopyVector(&Candidate.x);
+  AngleCheck->SubtractVector(&a.x);
+  if (AngleCheck->ScalarProduct(&Oben) < Storage[1])
+    {
+      Storage[0]=(double)(Candidate.nr);
+      Storage[1]=AngleCheck->ScalarProduct(&Oben);
+    };
+
+  if (n<5)
+    {
+      for (i = 0; i< mol.NumberOfBondsPerAtom[Candidate.nr]; i++)
+	{
+	  Walker = mol.start;
+	  while (Candidate.nr != (mol.ListOfBondsPerAtom[Candidate.nr][i]->leftatom->nr ==Candidate.nr ? mol.ListOfBondsPerAtom[Candidate.nr][i]->leftatom->nr : mol.ListOfBondsPerAtom[Candidate.nr][i]->rightatom->nr))
+	    {
+	      Walker = Walker->next;
+	    };
+	  
+	  Find_second_point_for_Tesselation(a, *Walker, n+1, Oben, Storage, mol);
+	    };
+    };
+  
+
+};
+
+
+void Tesselation::Find_starting_triangle(molecule mol, const double RADIUS)
+{
+  int i=0;
   atom Walker;
   atom Walker2;
@@ -152,8 +182,8 @@
   Vector helper;
 
-  Oben.Zero;
-
-
-  for(int i =0; i<3; i++)
+  Oben.Zero();
+
+
+  for(i =0; i<3; i++)
     {
       max_index[i] =-1;
@@ -161,12 +191,12 @@
     }
 
-  Walker = mol->start;
-  while (Walker->next != NULL)
+  Walker = *mol.start;
+  while (Walker.next != NULL)
     {
       for (i=0; i<3; i++)
 	{
-	  if (Walker.x[i]>max_coordinate[i])
+	  if (Walker.x.x[i]>max_coordinate[i])
 	    {
-	      max_coordinate[i]=Walker.x[i];
+	      max_coordinate[i]=Walker.x.x[i];
 	      max_index[i]=Walker.nr;
 	    }
@@ -178,60 +208,60 @@
 
   Oben.x[k]=1;
-  Walker = mol->start;
+  Walker = *mol.start;
   while (Walker.nr != max_index[k])
     {
-      Walker =Walker->next;
-    }
-
-  double *Storage[3];
-  Storage[0]=-1;   // Id must be positive, we see should nothing be done
-  Storage[1]=-2;   // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
-  Storage[2]=-10;  // This will be an angle looking for the third point.
-
-
-  for (i=0; i< mol->NumberOfBondsPerAtoms[Walker.nr]; i++)
-    {
-      Walker2 = mol->start;
-      while (Walker2.nr != mol->ListOfBondsPerAtoms[Walker.nr][i])  // Stimmt die Ueberpruefung $$$
-	{
-	  Walker2 =Walker2->next;
-	}
-
-      Find_second_point_for_Tesselation(Walker, Walker2, Oben, Storage);
-    }
-
-  Walker2=mol->start;
+      Walker = *Walker.next;
+    }
+
+  double Storage[3];
+  Storage[0]=-1.;   // Id must be positive, we see should nothing be done
+  Storage[1]=-2.;   // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
+  Storage[2]=-10.;  // This will be an angle looking for the third point.
+
+
+  for (i=0; i< mol.NumberOfBondsPerAtom[Walker.nr]; i++)
+    {
+      Walker2 = *mol.start;
+      while (Walker2.nr != (mol.ListOfBondsPerAtom[Walker.nr][i]->leftatom->nr == Walker.nr ? mol.ListOfBondsPerAtom[Walker.nr][i]->rightatom->nr : mol.ListOfBondsPerAtom[Walker.nr][i]->leftatom->nr) ) 
+	{
+	  Walker2 = *Walker2.next;
+	}
+
+      Find_second_point_for_Tesselation(Walker, Walker2, 0, Oben, Storage, mol);
+    }
+
+  Walker2 = *mol.start;
 
   while (Walker2.nr != int(Storage[0]))
     {
-      Walker = Walker.next;
-    }
-  
-  helper.copyVector(Walker.x);
-  helper.Subtract(Walker2.x);
-  Oben.ProjectOntoPlane(helper.x);
-  helper.VectorProduct(Oben);
-
-  Find_next_suitable_point(Walker, Walker2, Candidate, 0, helper, Oben, Storage, Radius);
-  Walker3 = mol->start;
+      Walker = *Walker.next;
+    }
+  
+  helper.CopyVector(&Walker.x);
+  helper.SubtractVector(&Walker2.x);
+  Oben.ProjectOntoPlane(&helper);
+  helper.VectorProduct(&Oben);
+
+       Find_next_suitable_point(Walker, Walker2, *(mol.ListOfBondsPerAtom[Walker.nr][i]->leftatom->nr == Walker.nr ? mol.ListOfBondsPerAtom[Walker.nr][i]->rightatom : mol.ListOfBondsPerAtom[Walker.nr][i]->leftatom), 0, &helper, &Oben, Storage, RADIUS, mol);
+  Walker3 = *mol.start;
   while (Walker3.nr != int(Storage[0]))
     {
-      Walker3 = Walker3->next;
+      Walker3 = *Walker3.next;
     }
 
   //Starting Triangle is Walker, Walker2, index Storage[0]
 
-  AddPoint(Walker);
-  AddPoint(Walker2);
-  AddPoint(Walker3);
-
-  BPS[0] = BoundaryPointSet(Walker);
-  BPS[1] = BoundaryPointSet(Walker2);
+  AddPoint(&Walker);
+  AddPoint(&Walker2);
+  AddPoint(&Walker3);
+
+  BPS[0] = new class BoundaryPointSet(&Walker);
+  BPS[1] = new class BoundaryPointSet(&Walker2);
   BLS[0] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
-  BPS[0] = Walker;
-  BPS[1] = Walker3;
+  BPS[0] = new class BoundaryPointSet(&Walker);
+  BPS[1] = new class BoundaryPointSet(&Walker3);
   BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
-  BPS[0] = Walker;
-  BPS[1] = Walker2;
+  BPS[0] = new class BoundaryPointSet(&Walker);
+  BPS[1] = new class BoundaryPointSet(&Walker2);
   BLS[2] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);  
 
@@ -244,18 +274,24 @@
       LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BTS->lines[i]) );
       LinesOnBoundaryCount++;
-    }
-
-}
-
-
-void Find_non_convex_border(Tesselation Tess, molecule mol) // this needs input of type molecule
-{
-
-  Tess.Find_starting_triangle(mol);
-
-  for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++) 
+    };
+
+       BTS->GetNormalVector(*BTS->NormalVector);
+
+       if( BTS->NormalVector->ScalarProduct(&Oben)<0)
+	 {
+	   BTS->NormalVector->Scale(-1);
+	 }
+};
+
+
+void Find_non_convex_border(Tesselation* Tess, molecule mol) 
+{
+  const double RADIUS =6;
+  Tess->Find_starting_triangle(mol, RADIUS);
+
+  for (LineMap::iterator baseline = Tess->LinesOnBoundary.begin(); baseline != Tess->LinesOnBoundary.end(); baseline++) 
     if (baseline->second->TrianglesCount == 1) 
       {
-	Find_next_suitable_triangle(mol, baseline->second, baseline->second->triangles.begin()->second); //the line is there, so there is a triangle, but only one.
+	Tess->Find_next_suitable_triangle(&mol, baseline->second, baseline->second->triangles.begin()->second, RADIUS); //the line is there, so there is a triangle, but only one.
 
       }
@@ -264,3 +300,3 @@
 	printf("There is a line with %d triangles adjacent", baseline->second->TrianglesCount);
       }
-}
+};
