public bool checkSame(DTEdge otherEdge) { if ((nodeA == otherEdge.getNodeA() || nodeA == otherEdge.getNodeB()) && (nodeB == otherEdge.getNodeA() || nodeB == otherEdge.getNodeB())) { return(true); } return(false); }
private void DrawConnection(DTEdge c) { DTNode room1 = c.getNodeA(); DTNode room2 = c.getNodeB(); Vector2 pos = new Vector2((float)Math.Round(room1.getNodePosition().x), (float)Math.Round(room1.getNodePosition().y)); float xDir = 0f, yDir = 0f; if (room1.getNodePosition().x <= room2.getNodePosition().x) { xDir = 1f; } else { xDir = -1f; } while (pos.x != (float)Math.Round(room2.getNodePosition().x)) { ConnectionFloor(pos.x, pos.y); ConnectionFloor(pos.x, pos.y + 1f); pos = new Vector2(pos.x + xDir, pos.y); } if (room1.getNodePosition().y <= room2.getNodePosition().y) { yDir = 1f; } else { yDir = -1f; } while (pos.y != (float)Math.Round(room2.getNodePosition().y)) { ConnectionFloor(pos.x, pos.y); ConnectionFloor(pos.x + 1f, pos.y); pos = new Vector2(pos.x, pos.y + yDir); } }
private void CheckEdges(List <DTEdge> edgesList) { //the current dirty edge if (edgesList.Count == 0) { if (nodesToAddList.Count > 0) { AddVertexToTriangulation(); } return; } //get the next edge in the dirty list DTEdge currentEdge = edgesList[0]; DTTriangle[] connectedTris = new DTTriangle[2]; int index = 0; foreach (DTTriangle aTri in triangleList) { if (aTri.ContainsEdge(currentEdge)) { connectedTris[index] = aTri; index++; } } //in first case (omega triangle) this will = 1 so dont flip if (index == 2) { //stores the two verticies from both triangles that arnt on the shared edge DTNode[] uniqueNodes = new DTNode[2]; int index1 = 0; //loop through the connected triangles and there edges. Checking for a vertex that isnt in the edge for (int i = 0; i < connectedTris.Length; i++) { foreach (DTEdge aEdge in connectedTris[i].GetEdges()) { if (!currentEdge.containsNode(aEdge.getNodeA())) { uniqueNodes[index1] = aEdge.getNodeA(); index1++; break; } if (!currentEdge.containsNode(aEdge.getNodeB())) { uniqueNodes[index1] = aEdge.getNodeB(); index1++; break; } } } //find the angles of the two unique verticies float angle0 = CalculateVertexAngle(uniqueNodes[0].getNodePosition(), currentEdge.getNodeA().getNodePosition(), currentEdge.getNodeB().getNodePosition()); float angle1 = CalculateVertexAngle(uniqueNodes[1].getNodePosition(), currentEdge.getNodeA().getNodePosition(), currentEdge.getNodeB().getNodePosition()); //Check if the target Edge needs flipping if (angle0 + angle1 > 180) { //create the new edge after flipped DTEdge flippedEdge = new DTEdge(uniqueNodes[0], uniqueNodes[1]); //store the edges of both triangles in the Quad DTEdge[] firstTriEdges = new DTEdge[3]; DTEdge[] secondTriEdges = new DTEdge[3]; DTNode sharedNode0; DTNode sharedNode1; //set the shared nodes on the shared edge sharedNode0 = currentEdge.getNodeA(); sharedNode1 = currentEdge.getNodeB(); //construct a new triangle to update old triangle after flip firstTriEdges[0] = new DTEdge(uniqueNodes[0], sharedNode0); firstTriEdges[1] = new DTEdge(sharedNode0, uniqueNodes[1]); firstTriEdges[2] = flippedEdge; //construct a new triangle to update the other old triangle after flip secondTriEdges[0] = new DTEdge(uniqueNodes[1], sharedNode1); secondTriEdges[1] = new DTEdge(sharedNode1, uniqueNodes[0]); secondTriEdges[2] = flippedEdge; //update the edges of the triangles involved in the flip connectedTris[0].SetEdges(firstTriEdges[0], firstTriEdges[1], firstTriEdges[2]); connectedTris[1].SetEdges(secondTriEdges[0], secondTriEdges[1], secondTriEdges[2]); //Adds all edges to be potentially dirty. This is bad and should only add the edges that *could* be dirty foreach (DTEdge eEdge in connectedTris[0].GetEdges()) { edgesList.Add(eEdge); } foreach (DTEdge eEdge in connectedTris[1].GetEdges()) { edgesList.Add(eEdge); } //also add new edge to dirty list edgesList.Add(flippedEdge); } } //remove the current edge from the dirty list edgesList.Remove(currentEdge); CheckEdges(edgesList); }