Index: Ringtoets/Common/src/Ringtoets.Common.Data/Structures/StructuresInputBase.cs =================================================================== diff -u -r8e8f8c83c45656f65adaa8e47600379dc5ae8f61 -r974fb1eadbd8a630c7a992648ad42ac85ec205b1 --- Ringtoets/Common/src/Ringtoets.Common.Data/Structures/StructuresInputBase.cs (.../StructuresInputBase.cs) (revision 8e8f8c83c45656f65adaa8e47600379dc5ae8f61) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Structures/StructuresInputBase.cs (.../StructuresInputBase.cs) (revision 974fb1eadbd8a630c7a992648ad42ac85ec205b1) @@ -20,13 +20,15 @@ // All rights reserved. using System; +using System.Globalization; using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Properties; namespace Ringtoets.Common.Data.Structures @@ -37,6 +39,11 @@ public abstract class StructuresInputBase : Observable, IStructuresCalculationInput, IUseBreakWater, IUseForeshore where T : StructureBase { + private const int structureNormalOrientationNumberOfDecimals = 2; + + private static readonly Range structureNormalOrientationValidityRange = new Range(new RoundedDouble(structureNormalOrientationNumberOfDecimals), + new RoundedDouble(structureNormalOrientationNumberOfDecimals, 360)); + private readonly NormalDistribution modelFactorSuperCriticalFlow; private readonly LogNormalDistribution allowedLevelIncreaseStorage; private readonly VariationCoefficientLogNormalDistribution storageStructureArea; @@ -46,7 +53,6 @@ private readonly VariationCoefficientLogNormalDistribution stormDuration; private T structure; - private RoundedDouble structureNormalOrientation; private double failureProbabilityStructureWithErosion; @@ -69,7 +75,7 @@ CoefficientOfVariation = (RoundedDouble) 0.25 }; - structureNormalOrientation = new RoundedDouble(2); + structureNormalOrientation = new RoundedDouble(structureNormalOrientationNumberOfDecimals); allowedLevelIncreaseStorage = new LogNormalDistribution(2); storageStructureArea = new VariationCoefficientLogNormalDistribution(2); flowWidthAtBottomProtection = new LogNormalDistribution(2); @@ -127,16 +133,6 @@ /// protected abstract void UpdateStructureParameters(); - /// - /// Validates the provided probability value. - /// - /// The probability value to validate. - /// True when the provided value is valid, false otherwise. - protected static bool ValidProbabilityValue(double probability) - { - return !double.IsNaN(probability) && probability <= 1 && probability >= 0; - } - private void SetDefaultCommonStructureSchematizationProperties() { StructureNormalOrientation = RoundedDouble.NaN; @@ -215,9 +211,10 @@ set { RoundedDouble newStructureNormalOrientation = value.ToPrecision(structureNormalOrientation.NumberOfDecimalPlaces); - if (!double.IsNaN(newStructureNormalOrientation) && (newStructureNormalOrientation < 0 || newStructureNormalOrientation > 360)) + if (!double.IsNaN(newStructureNormalOrientation) && !structureNormalOrientationValidityRange.InRange(newStructureNormalOrientation)) { - throw new ArgumentOutOfRangeException(nameof(value), Resources.Orientation_Value_needs_to_be_between_0_and_360); + throw new ArgumentOutOfRangeException(nameof(value), string.Format(Resources.Orientation_Value_needs_to_be_in_Range_0_, + structureNormalOrientationValidityRange)); } structureNormalOrientation = newStructureNormalOrientation; } @@ -305,9 +302,12 @@ } set { - if (!ValidProbabilityValue(value)) + if (!ProbabilityHelper.IsValidProbability(value)) { - throw new ArgumentOutOfRangeException(nameof(value), Resources.FailureProbability_Value_needs_to_be_between_0_and_1); + var probabilityValidityRange = new Range(0, 1); + string message = string.Format(Resources.FailureProbability_Value_needs_to_be_in_Range_0_, + probabilityValidityRange.ToString(FormattableConstants.ShowAtLeastOneDecimal, CultureInfo.CurrentCulture)); + throw new ArgumentOutOfRangeException(nameof(value), message); } failureProbabilityStructureWithErosion = value; }