/// <summary> /// Returns the other triangle than the given triangle on the graph /// Returns null if no such triangle could be found. /// </summary> /// <param name="t"></param> /// <returns></returns> public Triangle GetOtherTriangle(Triangle t) { var otherVertexOfTriangle = t.GetVertices().Single(o => o != v1 && o != v2); var triangleMembers = GetTriangleMembers(); //if (triangleMembers.Count() > 2) //throw new InvalidOperationException("Edge with more than two triangles?"); //TODO: Something goes wrong here! This should never be larger than 1!!! var otherTriangleMember = triangleMembers.FirstOrDefault(o => o != otherVertexOfTriangle); if (otherTriangleMember == null) return null; var edges = new List<Edge>() { this }; otherTriangleMember.Edges.ForEach(o => { if ((o.v1 == v1 || o.v1 == v2 || o.v2 == v1 || o.v2 == v2)) edges.Add(o); }); if (edges.Count != 3) throw new InvalidOperationException("Triangle with no 3 edges"); var triangle = new Triangle() { Edges = edges}; return triangle; }
/// <summary> /// Retriangulate the given triangle with P /// Basically removes the conflicting edge from the graph and introduces a new one from the vertex that was not on the removed edge and P /// </summary> /// <param name="triangle"></param> /// <param name="P"></param> private void Retriangulate(Triangle triangle, Vertex P) { var otherVertex = triangle.GetVertices().Single(o => o != triangle.conflictingEdge.v1 && o != triangle.conflictingEdge.v2); GM.DestroyEdge(triangle.conflictingEdge); GM.CreateOrGet(otherVertex, P); }