Index: src/boundary.cpp
===================================================================
--- src/boundary.cpp	(revision f0ebacc6c34010940a9567bc730b83dea125e6cd)
+++ src/boundary.cpp	(revision 018741f1886afdc512cdde2e7bb4e7e5d4f1e041)
@@ -1496,26 +1496,26 @@
 
   if (a->lines.find(b->node->nr) != a->lines.end()) {
-	LineMap::iterator FindLine;
+    LineMap::iterator FindLine;
     pair<LineMap::iterator,LineMap::iterator> FindPair;
     FindPair = a->lines.equal_range(b->node->nr);
 
     for (FindLine = FindPair.first; FindLine != FindPair.second; ++FindLine) {
-	  // If there is a line with less than two attached triangles, we don't need a new line.
-	  if (FindLine->second->TrianglesCount < 2) {
-	    insertNewLine = false;
-	    cout << Verbose(2)
-		  << "Using existing line " << *FindLine->second << endl;
-
- 	    BPS[0] = FindLine->second->endpoints[0];
-	    BPS[1] = FindLine->second->endpoints[1];
-	    BLS[n] = FindLine->second;
-
-	    break;
-	  }
+      // If there is a line with less than two attached triangles, we don't need a new line.
+      if (FindLine->second->TrianglesCount < 2) {
+        insertNewLine = false;
+        cout << Verbose(2)
+        << "Using existing line " << *FindLine->second << endl;
+
+        BPS[0] = FindLine->second->endpoints[0];
+        BPS[1] = FindLine->second->endpoints[1];
+        BLS[n] = FindLine->second;
+
+        break;
+      }
     }
   }
 
   if (insertNewLine) {
-	AlwaysAddTriangleLine(a, b, n);
+    AlwaysAddTriangleLine(a, b, n);
   }
 }
@@ -2890,4 +2890,42 @@
 };
 
+/** Checks for a new special triangle whether one of its edges is already present with one one triangle connected.
+ * This enforces that special triangles (i.e. degenerated ones) should at last close the open-edge frontier and not
+ * make it bigger (i.e. closing one (the baseline) and opening two new ones).
+ * \param TPS[3] nodes of the triangle
+ * \return true - there is such a line (i.e. creation of degenerated triangle is valid), false - no such line (don't create)
+ */
+bool CheckLineCriteriaforDegeneratedTriangle(class BoundaryPointSet *nodes[3])
+{
+  bool result = false;
+  int counter = 0;
+
+  // check all three points
+  for (int i=0;i<3;i++)
+    for (int j=i+1; j<3; j++) {
+      if (nodes[i]->lines.find(nodes[j]->node->nr) != nodes[i]->lines.end()) {  // there already is a line
+        LineMap::iterator FindLine;
+        pair<LineMap::iterator,LineMap::iterator> FindPair;
+        FindPair = nodes[i]->lines.equal_range(nodes[j]->node->nr);
+        for (FindLine = FindPair.first; FindLine != FindPair.second; ++FindLine) {
+          // If there is a line with less than two attached triangles, we don't need a new line.
+          if (FindLine->second->TrianglesCount < 2) {
+            counter++;
+            break;  // increase counter only once per edge
+          }
+        }
+      } else { // no line
+        cout << Verbose(1) << "ERROR: The line between " << nodes[i] << " and " << nodes[j] << " is not yet present, hence no need for a degenerate triangle!" << endl;
+        result = true;
+      }
+    }
+  if (counter > 1) {
+    cout << Verbose(2) << "INFO: Degenerate triangle is ok, there is only at most " << counter << " new line needed." << endl;
+    result = true;
+  }
+  return result;
+};
+
+
 /** This function finds a triangle to a line, adjacent to an existing one.
  * @param out output stream for debugging
@@ -2991,5 +3029,5 @@
 	  cout << Verbose(1) << " Third point candidate is " << *(*it)->point
 		<< " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
-	  cout << Verbose(1) << " Baseline is " << BaseRay << endl;
+	  cout << Verbose(1) << " Baseline is " << *BaseRay << endl;
 
 	  // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
@@ -3025,19 +3063,30 @@
         AddTrianglePoint(BaseRay->endpoints[1]->node, 2);
 
-        AddTriangleLine(TPS[0], TPS[1], 0);
-        AddTriangleLine(TPS[0], TPS[2], 1);
-        AddTriangleLine(TPS[1], TPS[2], 2);
-
-        BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
-        //TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
-        AddTriangleToLines();
-
-        (*it)->OtherOptCenter.Scale(-1.);
-        BTS->GetNormalVector((*it)->OtherOptCenter);
-        (*it)->OtherOptCenter.Scale(-1.);
-
-        cout << "--> WARNING: Special new triangle with " << *BTS << " and normal vector " << BTS->NormalVector
-        << " for this triangle ... " << endl;
-        cout << Verbose(1) << "We have "<< BaseRay->TrianglesCount << " for line " << BaseRay << "." << endl;
+        // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
+        // i.e. at least one of the three lines must be present with TriangleCount <= 1
+        if (CheckLineCriteriaforDegeneratedTriangle(TPS)) {
+          AddTriangleLine(TPS[0], TPS[1], 0);
+          AddTriangleLine(TPS[0], TPS[2], 1);
+          AddTriangleLine(TPS[1], TPS[2], 2);
+
+          BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
+          //TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
+          AddTriangleToLines();
+
+          (*it)->OtherOptCenter.Scale(-1.);
+          BTS->GetNormalVector((*it)->OtherOptCenter);
+          (*it)->OtherOptCenter.Scale(-1.);
+
+          cout << "--> WARNING: Special new triangle with " << *BTS << " and normal vector " << BTS->NormalVector
+          << " for this triangle ... " << endl;
+          cout << Verbose(1) << "We have "<< BaseRay->TrianglesCount << " for line " << BaseRay << "." << endl;
+        } else {
+          cout << Verbose(1) << "WARNING: This triangle consisting of ";
+          cout << *(*it)->point << ", ";
+          cout << *BaseRay->endpoints[0]->node << " and ";
+          cout << *BaseRay->endpoints[1]->node << " ";
+          cout << "exists and is not added, as it does not seem helpful!" << endl;
+          result = false;
+        }
     } else {
       cout << Verbose(1) << "This triangle consisting of ";
@@ -3049,5 +3098,5 @@
     }
 
-	  if ((existentTrianglesCount < 2) && (DoSingleStepOutput && (TrianglesOnBoundaryCount % 1 == 0))) { // if we have a new triangle and want to output each new triangle configuration
+	  if ((result) && (existentTrianglesCount < 2) && (DoSingleStepOutput && (TrianglesOnBoundaryCount % 1 == 0))) { // if we have a new triangle and want to output each new triangle configuration
       sprintf(NumberName, "-%04d-%s_%s_%s", TriangleFilesWritten, BTS->endpoints[0]->node->Name, BTS->endpoints[1]->node->Name, BTS->endpoints[2]->node->Name);
       if (DoTecplotOutput) {
