VertexInfo FindPrevVertex(VertexInfo vertexCenter, VertexInfo vertexEnd, bool isCW, Dictionary <string, EdgeInfo> inputEdges) { List <string> adjancentEdges = vertexCenter.belongToEdgeIndex.Where(s => inputEdges.ContainsKey(s)).ToList(); if (adjancentEdges.Count == 1) { return(vertices[edges[adjancentEdges[0]].GetOtherPoint(vertexCenter.index)]); } List <string> rightEdges = adjancentEdges.Where(e => IsRightOfVector(vertexCenter, vertexEnd, vertices[edges[e].GetOtherPoint(vertexCenter.index)])).ToList(); List <string> rightExceptEdges = adjancentEdges.Except(rightEdges).ToList(); List <string> leftEdges = adjancentEdges.Where(e => IsLeftOfVector(vertexCenter, vertexEnd, vertices[edges[e].GetOtherPoint(vertexCenter.index)])).ToList(); List <string> leftExceptEdges = adjancentEdges.Except(leftEdges).ToList(); string nextEdgeString; Func <string, float> calculateDot = eString => { EdgeInfo e = edges[eString]; return(Vector3.Dot((vertexEnd.vertex - vertexCenter.vertex).normalized, (vertices [e.GetOtherPoint(vertexCenter.index)].vertex - vertexCenter.vertex).normalized)); }; if (isCW) { if (rightEdges.Count > 0) { nextEdgeString = rightEdges.OrderByDescending(calculateDot).First(); } else { nextEdgeString = rightExceptEdges.OrderBy(calculateDot).First(); } } else { if (leftEdges.Count > 0) { nextEdgeString = leftEdges.OrderByDescending(calculateDot).First(); } else { nextEdgeString = leftExceptEdges.OrderBy(calculateDot).First(); } } return(vertices[edges[nextEdgeString].GetOtherPoint(vertexCenter.index)]); }