Пример #1
0
 private bool Cut(Intervall i, Intervall j, out Intervalls sub)
 {
     sub = new Intervalls();
     if (j.To.Value.CompareTo(i.From) <= 0 || i.To.Value.CompareTo(j.From) <= 0)
     {                                           //           [-----i-----]
         return(false);                          //  [--j--]                 [--j--]
     }
     else
     {
         if (j.From.CompareTo(i.From) < 0)               //        [--------i--------]
         {                                               //   [xxxx[----j-----]
             j.From = i.From;
         }
         if (i.To.Value.CompareTo(j.To.Value) < 0)       //        [--------i--------]
         {                                               //                   [---j--]xxx]
             j.To = i.To;
         }
         if (i.From.CompareTo(j.From) < 0)               //  [xxxxxx--i--------]      [xxxxxxxxxxx--i---]
         {                                               //        [---j--]                      [---j--]
             sub.Add(new Intervall(i.From, j.From));
         }
         if (j.To.Value.CompareTo(i.To.Value) < 0)       //  [----i-xxxxxxxxxxx]      [--------i--xxxxxx]
         {                                               //  [---j--]                      [---j--]
             sub.Add(new Intervall(j.To.Value, i.To.Value));
         }
         return(true);
     }
 }
Пример #2
0
        public void CutWith(Intervalls intervals)
        {
            var bHasChanges = true;

            while (bHasChanges)
            {
                bHasChanges = Cut(this, intervals);
            }
        }
Пример #3
0
 private bool Cut(Intervalls ii, Intervalls jj)
 {
     for (var k = 0; k < ii.Count; k++)
     {
         for (var l = 0; l < jj.Count; l++)
         {
             Intervalls sub;
             var        bHasChanges = Cut(ii[k], jj[l], out sub);
             if (bHasChanges)
             {
                 ii.RemoveAt(k);
                 ii.AddRange(sub);
                 return(true);
             }
         }
     }
     return(false);
 }