public void CheckCircle(BeachArc mid) { BeachEdge leftParent = BeachNode.GetLeftParent(mid); BeachEdge rightParent = BeachNode.GetRightParent(mid); BeachArc left = BeachNode.GetLeftChild(leftParent); BeachArc right = BeachNode.GetRightChild(rightParent); if (left == null || right == null || left.site == right.site) { return; } Vector2 s = GetEdgeIntersection(leftParent.edge, rightParent.edge); if (float.IsNaN(s.x) || float.IsNaN(s.y)) { return; } float dx = left.site.pos.x - s.x; float dy = left.site.pos.y - s.y; float d = Mathf.Sqrt((dx * dx) + (dy * dy)); if (s.y - d >= sweep) { return; } VertexEvent ev = new VertexEvent(left, mid, right); mid.ev = ev; events.Add(ev); }
public void Remove(VertexEvent e) { BeachArc mid = e.arcs[1]; BeachEdge leftEdge = BeachNode.GetLeftParent(mid); BeachEdge rightEdge = BeachNode.GetRightParent(mid); BeachArc left = BeachNode.GetLeftChild(leftEdge); BeachArc right = BeachNode.GetRightChild(rightEdge); if (left.ev != null) { events.Remove(left.ev); left.ev = null; } if (right.ev != null) { events.Remove(right.ev); right.ev = null; } Vertex end = new Vertex(e.center); diagram.vertices.Add(end); leftEdge.edge.end = end; rightEdge.edge.end = end; diagram.edges.Add(leftEdge.edge); diagram.edges.Add(rightEdge.edge); BeachEdge higher = null; BeachNode par = mid; while (par != root) { par = par.parent; if (par == leftEdge) { higher = leftEdge; } if (par == rightEdge) { higher = rightEdge; } } higher.edge = new Edge(end, left.site, right.site); diagram.edges.Add(higher.edge); BeachEdge gparent = (BeachEdge)mid.parent.parent; if (mid.parent.left == mid) { if (gparent.left == mid.parent) { gparent.left = mid.parent.right; } if (gparent.right == mid.parent) { gparent.right = mid.parent.right; } } else { if (gparent.left == mid.parent) { gparent.left = mid.parent.left; } if (gparent.right == mid.parent) { gparent.right = mid.parent.left; } } CheckCircle(left); CheckCircle(right); }