void InitRanges() { //实例化透明度交集 m_IntersectRanges = new List <fyTransparentRange>(); //fyGrid数据的范围 List <Interval> AllIntervals = new List <Interval>(); AllIntervals.Add(new Interval(m_Range.Min, m_Range.Max)); //用户设置的范围 List <Interval> UserIntervals = new List <Interval>(); foreach (var range in m_UserRanges) { double Min = range.Min; double Max = range.Max; //如果range的Min等于Max,即范围仅仅是一个点,那么对其进行修正 //对Min加EPSILON,同时对Max减EPSILON,使其成为一个有效的范围 if (range.Min == range.Max) { Min = Min + EPSILON; Max = Max - EPSILON; } UserIntervals.Add(new Interval(Min, Max)); } //用户设置的范围补集 List <Interval> UserIntervals_补集 = Interval.Complement(UserIntervals); //计算透明的范围 var IntersectIntervals_透明 = Interval.Intersection(AllIntervals, UserIntervals); //计算不透明的范围 var IntersectIntervals_不透明 = Interval.Intersection(AllIntervals, UserIntervals_补集); foreach (var interval in IntersectIntervals_透明) { if (interval.lowerbound == interval.upperbound) { continue; } fyTransparentRange range = new fyTransparentRange(); range.Min = interval.lowerbound; range.Max = interval.upperbound; range.Transparent = true; m_IntersectRanges.Add(range); } foreach (var interval in IntersectIntervals_不透明) { if (interval.lowerbound == interval.upperbound) { continue; } fyTransparentRange range = new fyTransparentRange(); range.Min = interval.lowerbound; range.Max = interval.upperbound; range.Transparent = false; m_IntersectRanges.Add(range); } //进行排序 m_IntersectRanges = m_IntersectRanges.OrderBy(a => a.Min).ThenBy(a => a.Max).ToList(); }