示例#1
0
 private void CalculateBalance()
 {
     IsBalanced  = true;
     TotalWeight = Weight;
     if (Childs.Any())
     {
         foreach (var c in Childs)
         {
             c.CalculateBalance();
         }
         // Disc is balanced if all childs have exactly the same weight, ie 1/nth of their total weight
         var w = Childs.Select(c => c.TotalWeight).Sum();
         TotalWeight += w;
         IsBalanced   = w % Childs.Length == 0 && Childs.All(c => c.TotalWeight == w / Childs.Length);
     }
 }