public void ReplaceWithSingleNode(BeachLineElement newNode) { if (Parent != null) { newNode.SetParent(Parent); if (Parent.LeftChild == this) { Parent.SetLeftChild(newNode); } else { Parent.SetRightChild(newNode); } } else { // This is the root node mBeachLine.SetRoot(newNode); } if (LeftChild != null) { newNode.SetLeftChild(LeftChild); LeftChild.SetParent(newNode); } if (RightChild != null) { newNode.SetRightChild(RightChild); RightChild.SetParent(newNode); } mParent = null; mLeftChild = null; mRightChild = null; }
public void ReplaceWithSubTree(BeachLineElement newSubtreeParentNode) { if (Parent != null) { newSubtreeParentNode.SetParent(Parent); if (Parent.LeftChild == this) { Parent.SetLeftChild(newSubtreeParentNode); } else { Parent.SetRightChild(newSubtreeParentNode); } } }
public List <BeachLineEdge> Squeeze(out BeachLineEdge newEdge) { // These are the output edges BeachLineEdge leftEdge = (BeachLineEdge)Prev; BeachLineEdge rightEdge = (BeachLineEdge)Next; BeachLineArc leftArc = (BeachLineArc)leftEdge.Prev; BeachLineArc rightArc = (BeachLineArc)rightEdge.Next; // Create new edge // To create it, we need the intersection point of the two output edges plus the // focuses of the two arcs. Vector2 intersection; leftEdge.CheckIntersection(rightEdge, out intersection); Vector2 focus1 = leftArc.Focus; Vector2 focus2 = rightArc.Focus; Vector2 perpendicular = focus2 - focus1; Vector2 newEdgeDirection = new Vector2(perpendicular.y, -perpendicular.x); if (Vector2.Dot(leftEdge.Direction.normalized + rightEdge.Direction.normalized, -newEdgeDirection) > 0) //if (newEdgeDirection.y < 0) { newEdgeDirection = -newEdgeDirection; } newEdge = new BeachLineEdge(intersection, newEdgeDirection.normalized); BeachLineEdge edgeToReplace = leftEdge == Parent ? rightEdge : leftEdge; //newEdge.SetLeftArc(LeftArc); //newEdge.SetRightArc(RightArc); // Replace other edge with new edge edgeToReplace.ReplaceWithSingleNode(newEdge); // Replace parent with sibling BeachLineElement sibling = Sibling; sibling.SetParent(null); bool iAmLeftChild = this == Parent.LeftChild; if (iAmLeftChild) { Parent.SetRightChild(null); } else { Parent.SetLeftChild(null); } BeachLineElement parentsParent = Parent.Parent; bool parentIsLeftChild = Parent == parentsParent.LeftChild; if (parentIsLeftChild) { parentsParent.SetLeftChild(sibling); } else { parentsParent.SetRightChild(sibling); } sibling.SetParent(parentsParent); //Parent.ReplaceWith(Sibling); //Parent.SetLeftChild(null); //Parent.SetRightChild(null); // Set next/prev for altered nodes leftArc.SetNext(newEdge); newEdge.SetPrev(leftArc); newEdge.SetNext(rightArc); rightArc.SetPrev(newEdge); // Remove this node from tree SetParent(null); SetLeftChild(null); SetRightChild(null); SetNext(null); SetPrev(null); leftEdge.SetParent(null); leftEdge.SetLeftChild(null); leftEdge.SetRightChild(null); leftEdge.SetNext(null); leftEdge.SetPrev(null); rightEdge.SetParent(null); rightEdge.SetLeftChild(null); rightEdge.SetRightChild(null); rightEdge.SetNext(null); rightEdge.SetPrev(null); leftEdge.SetEndpoint(intersection); rightEdge.SetEndpoint(intersection); List <BeachLineEdge> outputList = new List <BeachLineEdge> { leftEdge, rightEdge }; return(outputList); }