public Vertex2D IncludeVertex(Edge2D e) { if (e.HasVertex(a)) { return(a); } else { return(b); } }
/// <summary> /// 辺と対応する面の接続関係を追加する /// </summary> /// <returns>The add.</returns> /// <param name="face">Face.</param> /// <param name="edge">Edge.</param> void Add(Face2D face, Edge2D edge) { if (!_connection.ContainsKey(edge)) { _connection.Add(edge, new List <Face2D>() { face }); } else { _connection[edge].Add(face); } }
/// <summary> /// 入力した面から入力した辺を介する隣接する面を取得する。 /// </summary> /// <returns><c>true</c>, if get neighbor was tryed, <c>false</c> otherwise.</returns> /// <param name="edge">Edge.</param> /// <param name="face">Face.</param> /// <param name="neighbor">Neighbor.</param> public bool TryGetNeighbor(Edge2D edge, Face2D face, out Face2D neighbor) { List <Face2D> faces; if (_connection.TryGetValue(edge, out faces)) { neighbor = faces.Find(f => f != face); return(neighbor != null); } else { neighbor = null; return(false); } }
/// <summary> /// 入力した辺に含まれない頂点を返す /// </summary> /// <returns>The vertex.</returns> /// <param name="e">E.</param> public Vertex2D ExcludeVertex(Edge2D e) { if (!e.HasVertex(a)) { return(a); } else if (!e.HasVertex(b)) { return(b); } else { return(c); } }
/// <summary> /// 面情報を作成する。 /// </summary> /// <returns>The face.</returns> /// <param name="t">T.</param> /// <param name="contour">Contour.</param> /// <param name="vSet">V set.</param> Face2D MakeFace(Triangle2D t, List <Vector2> contour, VerticesSet2D vSet) { var a = vSet.FindNear(t.p0); var b = vSet.FindNear(t.p1); var c = vSet.FindNear(t.p2); var g = vSet.CheckAndAdd((a.p + b.p + c.p) / 3f); g.isExterior = false; var face = new Face2D(a, b, c, g); int externalCount = 0; bool isExterior = false; for (int i = 0, j = 2; i < 3; j = i++) { isExterior = IsContourEdge(contour, face.vertices[i].p, face.vertices[j].p); externalCount += isExterior ? 1 : 0; var mid = vSet.CheckAndAdd((face.vertices[j].p + face.vertices[i].p) * 0.5f); mid.isExterior = false; var edge = new Edge2D(face.vertices[j], face.vertices[i], mid, isExterior); face.edges[j] = edge; } switch (externalCount) { case 0: face.category = Face2D.Category.Junction; break; case 1: face.category = Face2D.Category.Sleeve; break; case 2: face.category = Face2D.Category.Terminal; break; default: throw new System.Exception("輪郭情報とマッチしません。"); } return(face); }
/// <summary> /// 指定した内部辺以外の他の内部辺を取得する /// </summary> /// <returns><c>true</c>, if get othe interior edge was tryed, <c>false</c> otherwise.</returns> /// <param name="interiorEdge">Interior edge.</param> /// <param name="others">Others.</param> public bool TryGetOtheInteriorEdge(Edge2D interiorEdge, out Edge2D[] others) { if (category != Category.Terminal) { others = new Edge2D[(int)category]; var count = 0; for (var i = 0; i < edges.Length; ++i) { if (!edges[i].isExterior && !edges[i].Equals(interiorEdge)) { others[count++] = edges[i]; } } return(count == others.Length); } else { others = null; return(false); } }