Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/SurfaceLineSlopeAdapter.cs =================================================================== diff -u -r4000 -r4052 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/SurfaceLineSlopeAdapter.cs (.../SurfaceLineSlopeAdapter.cs) (revision 4000) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/DikesDesign/SurfaceLineSlopeAdapter.cs (.../SurfaceLineSlopeAdapter.cs) (revision 4052) @@ -27,91 +27,90 @@ using Deltares.DamEngine.Data.Standard; using Deltares.DamEngine.Data.Standard.Validation; -namespace Deltares.DamEngine.Calculators.DikesDesign +namespace Deltares.DamEngine.Calculators.DikesDesign; + +/// +/// Class for adapting the slope of a surfaceline +/// +public class SurfaceLineSlopeAdapter : SurfaceLineAdapter { /// - /// Class for adapting the slope of a surfaceline + /// Initializes a new instance of the class. /// - public class SurfaceLineSlopeAdapter : SurfaceLineAdapter + /// + /// + /// + public SurfaceLineSlopeAdapter(SurfaceLine2 surfaceLine, Location location, double scenarioPolderLevel) + : base(surfaceLine, location, scenarioPolderLevel) {} + + /// + /// Constructs a new surface line with an adjusted slope + /// Adapt slope by moving the toe of the dike horizontally with deltaXAtToeOfSlope + /// + /// + /// + /// The offset to shift to the right + /// The adapted surface line + public SurfaceLine2 ConstructNewSurfaceLine(double deltaXAtToeOfSlope) { - /// - /// Initializes a new instance of the class. - /// - /// - /// - /// - public SurfaceLineSlopeAdapter(SurfaceLine2 surfaceLine, Location location, double scenarioPolderLevel) - : base(surfaceLine, location, scenarioPolderLevel) {} + ThrowHelper.ThrowWhenConditionIsTrue("deltaXAtToeOfSlope should be >= 0.0", () => deltaXAtToeOfSlope < 0.0); + GeometryPoint dikeTopAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder); + GeometryPoint dikeToeAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder); + GeometryPoint dikeBaseInside = surfaceLine.HasShoulderInside() ? surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.ShoulderBaseInside) : dikeToeAtPolder; + double slopeTangent = (dikeTopAtPolder.Z - dikeBaseInside.Z) / + (dikeBaseInside.X + deltaXAtToeOfSlope - dikeTopAtPolder.X); - /// - /// Constructs a new surface line with an adjusted slope - /// Adapt slope by moving the toe of the dike horizontally with deltaXAtToeOfSlope - /// - /// - /// - /// The offset to shift to the right - /// The adapted surface line - public SurfaceLine2 ConstructNewSurfaceLine(double deltaXAtToeOfSlope) - { - ThrowHelper.ThrowWhenConditionIsTrue("deltaXAtToeOfSlope should be >= 0.0", () => deltaXAtToeOfSlope < 0.0); - GeometryPoint dikeTopAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder); - GeometryPoint dikeToeAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder); - GeometryPoint dikeBaseInside = surfaceLine.HasShoulderInside() ? surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.ShoulderBaseInside) : dikeToeAtPolder; - double slopeTangent = (dikeTopAtPolder.Z - dikeBaseInside.Z) / - (dikeBaseInside.X + deltaXAtToeOfSlope - dikeTopAtPolder.X); + ConstructNewSurfaceLineBySlope(slopeTangent); - ConstructNewSurfaceLineBySlope(slopeTangent); + return surfaceLine; + } - return surfaceLine; + /// + /// Constructs a new surface line with an adjusted slope + /// Adapt slope by changing the slope to the specified slopeTangent + /// The top of the dike will remain in place and the te of the dike will be moved + /// + /// + /// + public SurfaceLine2 ConstructNewSurfaceLineBySlope(double slopeTangent) + { + ThrowHelper.ThrowWhenConditionIsTrue("Slopetangent should be >= 0.0", () => slopeTangent < 0.0); + // the given surface line must be valid to begin with. + ValidationResult validationError = surfaceLine.Validate().FirstOrDefault(vr => vr.MessageType == ValidationResultType.Error); + if (validationError != null) + { + throw new SurfaceLineException(validationError.Text); } - /// - /// Constructs a new surface line with an adjusted slope - /// Adapt slope by changing the slope to the specified slopeTangent - /// The top of the dike will remain in place and the te of the dike will be moved - /// - /// - /// - public SurfaceLine2 ConstructNewSurfaceLineBySlope(double slopeTangent) + double orgMaxX = surfaceLine.Geometry.GetMaxX(); + if (double.IsNaN(orgMaxX)) { - ThrowHelper.ThrowWhenConditionIsTrue("Slopetangent should be >= 0.0", () => slopeTangent < 0.0); - // the given surface line must be valid to begin with. - ValidationResult validationError = surfaceLine.Validate().FirstOrDefault(vr => vr.MessageType == ValidationResultType.Error); - if (validationError != null) - { - throw new SurfaceLineException(validationError.Text); - } + orgMaxX = double.MaxValue; + } - double orgMaxX = surfaceLine.Geometry.GetMaxX(); - if (double.IsNaN(orgMaxX)) - { - orgMaxX = double.MaxValue; - } + GeometryPoint dikeTopAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder); + GeometryPoint dikeToeAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder); + GeometryPoint dikeBaseInside = surfaceLine.HasShoulderInside() ? surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.ShoulderBaseInside) : dikeToeAtPolder; + // Remove points on inside slope + surfaceLine.RemoveSegmentBetween(dikeTopAtPolder.X, dikeBaseInside.X); + // Store the ditch (if any) + DitchDefinition? ditchDefinition = GetDitchDefinition(); + // Delete the ditch from the surfaceline (if any) + RemoveExistingDitch(ditchDefinition); + // Adjust for the new slope + ReplaceBaseInsideForNewSlope(dikeTopAtPolder, slopeTangent); + // Restore Ditch (if any) + RestoreDitch(ditchDefinition); + // Check whether the surface line is extended. This is not allowed! + if (surfaceLine.Geometry.GetMaxX() > orgMaxX) + { + throw new SurfaceLineAdapterException(Resources.SurfaceLineShoulderAdapterNewShoulderHeightTooLargeError); + } - GeometryPoint dikeTopAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder); - GeometryPoint dikeToeAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder); - GeometryPoint dikeBaseInside = surfaceLine.HasShoulderInside() ? surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.ShoulderBaseInside) : dikeToeAtPolder; - // Remove points on inside slope - surfaceLine.RemoveSegmentBetween(dikeTopAtPolder.X, dikeBaseInside.X); - // Store the ditch (if any) - DitchDefinition? ditchDefinition = GetDitchDefinition(); - // Delete the ditch from the surfaceline (if any) - RemoveExistingDitch(ditchDefinition); - // Adjust for the new slope - ReplaceBaseInsideForNewSlope(dikeTopAtPolder, slopeTangent); - // Restore Ditch (if any) - RestoreDitch(ditchDefinition); - // Check whether the surface line is extended. This is not allowed! - if (surfaceLine.Geometry.GetMaxX() > orgMaxX) - { - throw new SurfaceLineAdapterException(Resources.SurfaceLineShoulderAdapterNewShoulderHeightTooLargeError); - } + // Restore traffic load + RestoreTrafficLoad(); + surfaceLine.SortPoints(); - // Restore traffic load - RestoreTrafficLoad(); - surfaceLine.SortPoints(); - - return surfaceLine; - } + return surfaceLine; } } \ No newline at end of file