void HandleLeftEvent(SweepEvent currentEvent) { AVLNode <SweepEvent> position = sweepLineEvents.Insert(currentEvent); // the line segment must be inserted into S currentEvent.positionInS = position; prev = position.GetPredecessor(); next = position.GetSuccessor(); // Compute the inside and inOut flags if (prev == null) { currentEvent.Inside = false; currentEvent.InOut = false; } else if (prev.Value.Type != EdgeType.NORMAL) { if (prev.Value == sweepLineEvents.GetMin()) // currentEvent overlaps with prev // JUST GET! NOT POP! { currentEvent.Inside = true; // it is not relevant to set true or false currentEvent.InOut = false; } else // the previous two line segments in S are overlapping line segments { prevPrev = prev.GetPredecessor(); if (prev.Value.OwningPolygon == currentEvent.OwningPolygon) { currentEvent.InOut = !prev.Value.InOut; currentEvent.Inside = !prevPrev.Value.InOut; } else { currentEvent.InOut = !prevPrev.Value.InOut; currentEvent.Inside = !prev.Value.InOut; } } } else if (currentEvent.OwningPolygon == prev.Value.OwningPolygon) // edges of same polygon { currentEvent.Inside = prev.Value.Inside; currentEvent.InOut = !prev.Value.InOut; } else // edges of different polygons { currentEvent.Inside = !prev.Value.InOut; currentEvent.InOut = prev.Value.Inside; } AddDebugEdge(currentEvent); if (next != null) { PossibleIntersection(currentEvent, next.Value); } if (prev != null) { PossibleIntersection(prev.Value, currentEvent); } }
void HandleRightEvent(OperationType ot, SweepEvent currentEvent) { // the left end/part of the current SweepEvent must be removed from sweepLineEvents left = currentEvent.Other.positionInS; next = left.GetSuccessor(); prev = left.GetPredecessor(); // Check if the line segment belongs to the Boolean operation switch (currentEvent.Type) { case EdgeType.NORMAL: switch (ot) { case OperationType.INTERSECTION: if (currentEvent.Other.Inside) { connector.Add(currentEvent.CreateEdge()); } break; case OperationType.UNION: if (!currentEvent.Other.Inside) { connector.Add(currentEvent.CreateEdge()); } break; case OperationType.DIFFERENCE: if ((currentEvent.OwningPolygon == (int)Operand.SUBJECT && !currentEvent.Other.Inside) || (currentEvent.OwningPolygon == (int)Operand.CLIPPER && currentEvent.Other.Inside)) { connector.Add(currentEvent.CreateEdge()); } break; case OperationType.XOR: connector.Add(currentEvent.CreateEdge()); break; } break; case EdgeType.SAME_TRANSITION: if (ot == OperationType.INTERSECTION || ot == OperationType.UNION) { connector.Add(currentEvent.CreateEdge()); } break; case EdgeType.DIFFERENT_TRANSITION: if (ot == OperationType.DIFFERENCE) { connector.Add(currentEvent.CreateEdge()); } break; } AddDebugEdge(currentEvent); sweepLineEvents.RemoveAt(left); if (next != null && prev != null) { PossibleIntersection(prev.Value, next.Value); } }