Beispiel #1
0
        public static void AdjustIngredientPercentages(object senderObj, double newPercent, List <Ingredient> ingredients)
        {
            Ingredient sender       = senderObj as Ingredient;
            double     oldPercent   = sender.GetExactPercent();
            double     oldRemainder = 100 - oldPercent;
            double     newRemainder = 100 - newPercent;

            for (int i = 0; i < ingredients.Count; i++)
            {
                Ingredient item = ingredients[i];
                if (item == sender)
                {
                    continue;
                }

                double adjustedPercent = (item.GetExactPercent() / oldRemainder) * newRemainder;
                item.AdjustPercent(adjustedPercent);
            }
        }
Beispiel #2
0
        public static void AdjustIngredientPercentages(object senderObj, double newPercent, ObservableCollection <Ingredient> ingredients)
        {
            Ingredient        sender               = senderObj as Ingredient;
            double            oldPercent           = sender.GetExactPercent();
            List <Ingredient> freeIngredients      = ingredients.Where(i => !i.RatioLocked).ToList();
            double            freePercentagesTotal = freeIngredients.Sum(i => i.GetExactPercent());
            double            oldRemainder         = freePercentagesTotal - oldPercent;
            double            newRemainder         = freePercentagesTotal - newPercent;

            foreach (Ingredient item in freeIngredients)
            {
                if (item == sender)
                {
                    continue;
                }

                double adjustedPercent = (item.GetExactPercent() / oldRemainder) * newRemainder;
                item.AdjustPercent(adjustedPercent);
            }
        }