public static Metre CreateNewMetre(double value, Metre firstLength, Metre secondLength) { if (firstLength.MaxValue == null && secondLength.MaxValue != null) // Takes the max & min value from the first Length { double newMin = (double)secondLength.MinValue; double newMax = (double)secondLength.MaxValue; return(new Metre(value, newMin, newMax)); } else if (firstLength.MaxValue != null && secondLength.MaxValue == null) // Takes the max & min value from the second Length { double newMin = (double)firstLength.MinValue; double newMax = (double)firstLength.MaxValue; return(new Metre(value, newMin, newMax)); } else if (firstLength.MaxValue == null && secondLength.MaxValue == null) // None of the Lengthes has a range set { return(new Metre(value)); } else // Takes the highest max value and the lowest min value from both Lengthes { double newMin = Math.Min((double)firstLength.MinValue, (double)secondLength.MinValue); double newMax = Math.Max((double)firstLength.MaxValue, (double)secondLength.MaxValue); return(new Metre(value, newMin, newMax)); } }
// For when adding a value to an existing Length, instead of two Lengthes together public static Metre CreateNewMetre(double value, Metre Metre) { if (Metre.MaxValue != null) { double newMin = (double)Metre.MinValue; double newMax = (double)Metre.MaxValue; return(new Metre(value, newMin, newMax)); } else { return(new Metre(value)); } }