private static void SwapMerge(Bundle lower, Bundle upper, BundleTree rBundleTree) { lower.RemovePurpleL(); RecordIntersections(lower, upper); lower.AddAbovePurpleL(upper); if (lower.IsRed == lower.PurpleUp.IsRed) { rBundleTree.GroupBundles(lower, true); } if (upper.IsRed == upper.PurpleDown.IsRed) { rBundleTree.GroupBundles(upper, false); } }
private void CalcIntersections() { Debug.Assert(mergedSegments != null); Segment[] contSegs = new Segment[2]; ClearIntersections(); IEnumerable <FPoint> eventList = CreateEventList(mergedSegments); BundleTree rBundleTree = InitSentinels(); int imerge = 0; foreach (FPoint sweepEvent in eventList) { Bundle bClose = rBundleTree.FindSmBAbove(sweepEvent); Bundle bRedTeq = bClose.PurpleDown.PurpleDown; if (bRedTeq.PurpleDown != null) { for (bRedTeq = rBundleTree.separateEq(bRedTeq, sweepEvent, true, false); Witnessed(bRedTeq.PurpleDown, bRedTeq, sweepEvent); SwapMerge(bRedTeq.PurpleDown, bRedTeq, rBundleTree)) { } rBundleTree.separateEq(bRedTeq.PurpleDown, sweepEvent, true, true); if (Witnessed(bRedTeq.PurpleDown, bRedTeq, sweepEvent)) { SwapMerge(bRedTeq.PurpleDown, bRedTeq, rBundleTree); } if (bRedTeq.PurpleUp.IsRed) { bClose = bRedTeq.PurpleUp; } if (bClose.PurpleUp != null) { for (; Witnessed(bClose, bClose.PurpleUp, sweepEvent); SwapMerge(bClose, bClose.PurpleUp, rBundleTree)) { } rBundleTree.separateEq(bClose.PurpleUp, sweepEvent, true, false); if (Witnessed(bClose, bClose.PurpleUp, sweepEvent)) { SwapMerge(bClose, bClose.PurpleUp, rBundleTree); } } if (bRedTeq.PurpleUp.IsRed) { rBundleTree.GroupBundles(bRedTeq, true); } for (bRedTeq = rBundleTree.separateEq(bRedTeq, sweepEvent, false, false); Witnessed(bRedTeq.PurpleDown, bRedTeq, sweepEvent); SwapMerge(bRedTeq.PurpleDown, bRedTeq, rBundleTree)) { } rBundleTree.separateEq(bRedTeq.PurpleDown, sweepEvent, false, true); if (Witnessed(bRedTeq.PurpleDown, bRedTeq, sweepEvent)) { SwapMerge(bRedTeq.PurpleDown, bRedTeq, rBundleTree); } if (bRedTeq.PurpleUp.IsRed) { rBundleTree.GroupBundles(bRedTeq, true); } } bClose = rBundleTree.FindLgBBelow(sweepEvent); Bundle bRedBeq = bClose.PurpleUp.PurpleUp; if (bRedBeq.PurpleUp != null) { for (bRedBeq = rBundleTree.separateEq(bRedBeq, sweepEvent, false, true); Witnessed(bRedBeq, bRedBeq.PurpleUp, sweepEvent); SwapMerge(bRedBeq, bRedBeq.PurpleUp, rBundleTree)) { } rBundleTree.separateEq(bRedBeq.PurpleUp, sweepEvent, false, false); if (Witnessed(bRedBeq, bRedBeq.PurpleUp, sweepEvent)) { SwapMerge(bRedBeq, bRedBeq.PurpleUp, rBundleTree); } if (bRedBeq.PurpleDown.IsRed) { bClose = bRedBeq.PurpleDown; } if (bClose.PurpleDown != null) { for (; Witnessed(bClose.PurpleDown, bClose, sweepEvent); SwapMerge(bClose.PurpleDown, bClose, rBundleTree)) { } rBundleTree.separateEq(bClose.PurpleDown, sweepEvent, false, true); if (Witnessed(bClose.PurpleDown, bClose, sweepEvent)) { SwapMerge(bClose.PurpleDown, bClose, rBundleTree); } } if (bRedBeq.PurpleDown.IsRed) { rBundleTree.GroupBundles(bRedBeq, false); } for (bRedBeq = rBundleTree.separateEq(bRedBeq, sweepEvent, true, true); Witnessed(bRedBeq, bRedBeq.PurpleUp, sweepEvent); SwapMerge(bRedBeq, bRedBeq.PurpleUp, rBundleTree)) { } rBundleTree.separateEq(bRedBeq.PurpleUp, sweepEvent, true, false); if (Witnessed(bRedBeq, bRedBeq.PurpleUp, sweepEvent)) { SwapMerge(bRedBeq, bRedBeq.PurpleUp, rBundleTree); } if (bRedBeq.PurpleDown.IsRed) { rBundleTree.GroupBundles(bRedBeq, false); } } BundleTree plusTree = rBundleTree.Split(sweepEvent, true); BundleTree minusTree = rBundleTree; BundleTree oldEqTree = minusTree.Split(sweepEvent, false); FindContSegs(oldEqTree, contSegs, sweepEvent); rBundleTree = new BundleTree(); imerge = MakeNewEqTree(rBundleTree, mergedSegments, imerge, contSegs, sweepEvent); RecordEndIntersections(oldEqTree, rBundleTree); rBundleTree.Merge(plusTree, true); rBundleTree.Merge(minusTree, false); } }