using System.Collections.Generic;
public double FromWeight { get; set; }
public double ToWeight { get; set; }
public double AllowedError { get; set; }
public override string ToString()
return FromWeight + " < m <= " + ToWeight + ", " + AllowedError;
private static double CalculateAreas(
double allowedErrorMultiplier1,
double allowedErrorMultiplier2,
double allowedErrorMultiplier3,
ref List<WeightArea> areas)
double max1ScalePart = toMax / division;
if (lastMax < division * ScalePart1)
FromWeight = lastMax > 0 ? lastMax : 0,
ToWeight = toMax < division * ScalePart1 ? toMax : division * ScalePart1,
AllowedError = division * allowedErrorMultiplier1
if (lastMax < division * ScalePart2 && division * ScalePart1 < toMax)
FromWeight = lastMax > division * ScalePart1 ? lastMax : division * ScalePart1,
ToWeight = toMax < division * ScalePart2 ? toMax : division * ScalePart2,
AllowedError = division * allowedErrorMultiplier2
if (lastMax < division * ScalePart3 && division * ScalePart2 < toMax)
FromWeight = lastMax > division * ScalePart2 ? lastMax : division * ScalePart2,
ToWeight = toMax < division * ScalePart3 ? toMax : division * ScalePart3,
AllowedError = division * allowedErrorMultiplier3
var lastArea = areas.LastOrDefault();
return lastArea == null ? 0 : lastArea.ToWeight;
private static List<WeightArea> PrintTolerance(DynamicOrStatic dynamic_or_static, AccuracyClass accuracy_class, double max1, double division1, Tuple<double, double> max2, Tuple<double, double> max3)
List<WeightArea> areas = new List<WeightArea>();
if (dynamic_or_static == DynamicOrStatic.Dynamic)
if (accuracy_class == AccuracyClass.Ya)
double lastMax = CalculateAreas(0, max1, division1, 500, 2000, 10000, 1, 1.5, 2, ref areas);
lastMax = CalculateAreas(lastMax, max2.Item1, max2.Item2, 500, 2000, 10000, 1, 1.5, 2, ref areas);
if (max2 != null && max3 != null)
lastMax = CalculateAreas(lastMax, max3.Item1, max3.Item2, 500, 2000, 10000, 1, 1.5, 2, ref areas);
double lastMax = CalculateAreas(0, max1, division1, 50, 200, 1000, 1, 1.5, 2, ref areas);
lastMax = CalculateAreas(lastMax, max2.Item1, max2.Item2, 50, 200, 1000, 1, 1.5, 2, ref areas);
if (max2 != null && max3 != null)
lastMax = CalculateAreas(lastMax, max3.Item1, max3.Item2, 50, 200, 1000, 1, 1.5, 2, ref areas);
if (accuracy_class == AccuracyClass.Ya)
double lastMax = CalculateAreas(0, max1, division1, 500, 2000, 10000, 0.5, 1.0, 1.5, ref areas);
lastMax = CalculateAreas(lastMax, max2.Item1, max2.Item2, 500, 2000, 10000, 0.5, 1.0, 1.5, ref areas);
if (max2 != null&& max3 != null)
lastMax = CalculateAreas(lastMax, max3.Item1, max3.Item2, 500, 2000, 10000, 0.5, 1.0, 1.5, ref areas);
double lastMax = CalculateAreas(0, max1, division1, 50, 200, 1000, 0.5, 1.0, 1.5, ref areas);
lastMax = CalculateAreas(lastMax, max2.Item1, max2.Item2, 50, 200, 1000, 0.5, 1.0, 1.5, ref areas);
if (max2 != null && max3 != null)
lastMax = CalculateAreas(lastMax, max3.Item1, max3.Item2, 50, 200, 1000, 0.5, 1.0, 1.5, ref areas);
public static void Main()
DynamicOrStatic dynamic_or_static = DynamicOrStatic.Static;
AccuracyClass accuracy_class = AccuracyClass.Yb;
!Max2.HasValue ? null : Tuple.Create(Max2.Value, Division2),
!Max3.HasValue ? null : Tuple.Create(Max3.Value, Division3));
foreach (var area in areas)