From 3c4b9fbe6daf4881ecffcce1c721a8f1e5d4cbe9 Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Mon, 29 Feb 2016 11:01:05 +0100
Subject: [PATCH] used hashset for storing the points in delauney map to avoid
 duplicates.

---
 VectoCore/Utils/DelauneyMap.cs | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/VectoCore/Utils/DelauneyMap.cs b/VectoCore/Utils/DelauneyMap.cs
index d89790c25e..b4dea11356 100644
--- a/VectoCore/Utils/DelauneyMap.cs
+++ b/VectoCore/Utils/DelauneyMap.cs
@@ -31,10 +31,8 @@
 
 using System;
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Linq;
 using Newtonsoft.Json;
-using Org.BouncyCastle.Asn1.Crmf;
 using TUGraz.VectoCore.Exceptions;
 using TUGraz.VectoCore.Models;
 
@@ -43,7 +41,7 @@ namespace TUGraz.VectoCore.Utils
 	[JsonObject(MemberSerialization.Fields)]
 	public class DelauneyMap : LoggingObject
 	{
-		internal readonly List<Point> Points = new List<Point>();
+		internal readonly ICollection<Point> Points = new HashSet<Point>();
 		private List<Triangle> _triangles = new List<Triangle>();
 		private IEnumerable<Edge> _convexHull;
 
@@ -72,10 +70,9 @@ namespace TUGraz.VectoCore.Utils
 			var superTriangle = new Triangle(new Point(max, 0), new Point(0, max), new Point(-max, -max));
 			var triangles = new List<Triangle> { superTriangle };
 
+			var pointCount = 0;
 			// iteratively add each point into the correct triangle and split up the triangle
-			for (var i = 0; i < Points.Count; i++) {
-				var point = Points[i];
-
+			foreach (var point in Points) {
 				// If the vertex lies inside a triangle, the edges of the triangle are 
 				// added to the edge buffer and the triangle is removed from list.
 				var containerTriangles = triangles.FindAll(t => t.ContainsInCircumcircle(point));
@@ -90,12 +87,13 @@ namespace TUGraz.VectoCore.Utils
 				var newTriangles = convexHullEdges.Select(edge => new Triangle(edge.P1, edge.P2, point));
 
 				triangles.AddRange(newTriangles);
+				pointCount++;
 
 				// check invariant: m = 2n-2-k
 				// m...triangle count
-				// n...point count (index+1 +3 points on the supertriangle)
+				// n...point count (pointCount +3 points on the supertriangle)
 				// k...points on convex hull (exactly 3 --> supertriangle)
-				if (triangles.Count != 2 * (i + 1 + 3) - 2 - 3) {
+				if (triangles.Count != 2 * (pointCount + 3) - 2 - 3) {
 					throw new VectoException("Triangulation invariant violated! Triangle count and point count doesn't fit together.");
 				}
 			}
@@ -182,14 +180,6 @@ namespace TUGraz.VectoCore.Utils
 
 		public bool Extrapolated { get; set; }
 
-		public DelauneyMap CreateInvertedMap()
-		{
-			var reverted = new DelauneyMap();
-			reverted.Points.AddRange(Points.Select(p => new Point(p.X, p.Z, p.Y)));
-			reverted.Triangulate();
-			return reverted;
-		}
-
 		#region Equality members
 
 		protected bool Equals(DelauneyMap other)
-- 
GitLab