Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Builders/SoilProfileBuilder2D.cs =================================================================== diff -u -r33d4f4e7e5404dcc6470dd3d34168b30410109eb -r97c9e382dffcf32dc34d2e05e6a8a475b833ebd4 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Builders/SoilProfileBuilder2D.cs (.../SoilProfileBuilder2D.cs) (revision 33d4f4e7e5404dcc6470dd3d34168b30410109eb) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Builders/SoilProfileBuilder2D.cs (.../SoilProfileBuilder2D.cs) (revision 97c9e382dffcf32dc34d2e05e6a8a475b833ebd4) @@ -1,66 +1,87 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; - using Ringtoets.Piping.Data; - using Ringtoets.Piping.IO.Properties; namespace Ringtoets.Piping.IO.Builders { /// /// Constructs a 1d Soil Profile based on definitions of . /// - internal class SoilProfileBuilder2D : ISoilProfileBuilder + internal class SoilProfileBuilder2D { private readonly ICollection layers = new Collection(); + private readonly double atX; + private readonly string profileName; + private double bottom; + /// /// Creates a new instance of with the supposed name for the new /// and the point at which a 1D profile should be obtained from the 2D profile. /// /// The name for the constructed by the . /// The x position from which to obtain a 1D profile. + /// Thrown when can not be used to determine intersections with + /// (is ). internal SoilProfileBuilder2D(string profileName, double atX) { if (double.IsNaN(atX)) { throw new ArgumentException(Resources.Error_SoilProfileBuilder_cant_determine_intersect_at_double_NaN); } - ProfileName = profileName; - AtX = atX; - Bottom = double.MaxValue; + this.profileName = profileName; + this.atX = atX; + bottom = double.MaxValue; } /// - /// Adds a new to the profile. + /// Creates a new instances of the based on the layer definitions. /// - /// The to add to the profile. - /// The . - internal SoilProfileBuilder2D Add(SoilLayer2D soilLayer) + /// A new . + /// Thrown when trying to build a + /// and not having added any layers using . + /// + public PipingSoilProfile Build() { - double bottom; - foreach (PipingSoilLayer layer in soilLayer.AsPipingSoilLayers(AtX, out bottom)) + try { - layers.Add(layer); + return new PipingSoilProfile(profileName, bottom, layers); } - Bottom = Math.Min(Bottom, bottom); - return this; + catch (ArgumentException e) + { + throw new SoilProfileBuilderException(e.Message, e); + } } /// - /// Creates a new instance of . + /// Adds a new to the profile. /// - /// A new . - public PipingSoilProfile Build() + /// The to add to the profile. + /// The . + /// Thrown when the 's geometry + /// contains vertical segments the X-coordinate given for the construction of the + /// . + internal SoilProfileBuilder2D Add(SoilLayer2D soilLayer) { - return new PipingSoilProfile(ProfileName, Bottom, layers); - } + double newBottom; - private double Bottom { get; set; } + try + { + var pipingSoilLayers = soilLayer.AsPipingSoilLayers(atX, out newBottom); + foreach (PipingSoilLayer layer in pipingSoilLayers) + { + layers.Add(layer); + } + } + catch (SoilLayer2DConversionException e) + { + throw new SoilProfileBuilderException(e.Message, e); + } - private double AtX { get; set; } - - private string ProfileName { get; set; } + bottom = Math.Min(bottom, newBottom); + return this; + } } } \ No newline at end of file