public void SqueezeEvent(VoronoiArcNode node) { VoronoiEdgeNode leftEdge = VoronoiNode.GetLeftParentEdge(node); VoronoiEdgeNode rightEdge = VoronoiNode.GetRightParentEdge(node); VoronoiArcNode leftArc = VoronoiNode.GetLeftChildArc(leftEdge); VoronoiArcNode rightArc = VoronoiNode.GetRightChildArc(rightEdge); if (leftArc == null || rightArc == null || leftArc.mFocus == rightArc.mFocus) { return; } Vector2 intersection = GetIntersection(leftEdge, rightEdge); if (intersection.Equals(new Vector2(-10000, -10000))) { return; } float circleX = leftArc.mFocus.x - intersection.x; float circleY = leftArc.mFocus.y - intersection.y; float radius = Mathf.Sqrt((circleX * circleX) + (circleY * circleY)); if (intersection.y - radius >= sweepY) { return; } SqueezeEvent squeezeEvent = new SqueezeEvent(intersection, node); node.squeezeEvent = squeezeEvent; eventQueue.Add(squeezeEvent); }
public void CallSqueeze(int coefficient) => SqueezeEvent?.Invoke(coefficient);
public void RemoveArc(SqueezeEvent vEvent) { VoronoiArcNode removeNode = vEvent.mArcToRemove; VoronoiEdgeNode leftEdge = VoronoiNode.GetLeftParentEdge(removeNode); VoronoiEdgeNode rightEdge = VoronoiNode.GetRightParentEdge(removeNode); VoronoiArcNode leftArc = VoronoiNode.GetLeftChildArc(leftEdge); VoronoiArcNode rightArc = VoronoiNode.GetRightChildArc(rightEdge); if (leftArc.squeezeEvent != null) { removed.Add(leftArc.squeezeEvent); leftArc.squeezeEvent = null; } if (rightArc.squeezeEvent != null) { removed.Add(rightArc.squeezeEvent); rightArc.squeezeEvent = null; } Vector2 point = new Vector2(vEvent.mIntersectionPoint.x, GetYCoord(removeNode.mFocus, vEvent.mIntersectionPoint.x)); leftEdge.mEndVertex = point; rightEdge.mEndVertex = point; VoronoiNode h; VoronoiNode tempNode = removeNode; while (tempNode != root) { tempNode = tempNode.mParent; if (tempNode == leftEdge) { h = leftEdge; } if (tempNode == rightEdge) { h = rightEdge; } } h = new VoronoiEdgeNode(point, new Vector2(), leftArc.mFocus, rightArc.mFocus); //******* //edges.Add((VoronoiEdgeNode)h); VoronoiNode removeNodeGrandparent = removeNode.mParent.mParent; if (removeNode.mParent.mLeft == removeNode) { if (removeNodeGrandparent.mLeft == removeNode.mParent) { removeNodeGrandparent.mLeft = removeNode.mParent.mRight; removeNode.mParent.mRight.mParent = removeNodeGrandparent; } if (removeNodeGrandparent.mRight == removeNode.mParent) { removeNodeGrandparent.mRight = removeNode.mParent.mRight; removeNode.mParent.mRight.mParent = removeNodeGrandparent; } } else { if (removeNodeGrandparent.mLeft == removeNode.mParent) { removeNodeGrandparent.mLeft = removeNode.mParent.mLeft; removeNode.mParent.mLeft.mParent = removeNodeGrandparent; } if (removeNodeGrandparent.mRight == removeNode.mParent) { removeNodeGrandparent.mRight = removeNode.mParent.mLeft; removeNode.mParent.mLeft.mParent = removeNodeGrandparent; } } SqueezeEvent(leftArc); SqueezeEvent(rightArc); }