// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Components.Chart.Data; using Ringtoets.MacroStabilityInwards.Data; namespace Ringtoets.MacroStabilityInwards.Forms.Factories { /// /// Factory for creating collections of points in 2D space for a collection of /// to use in . /// (created via ). /// internal static class MacroStabilityInwardsSliceChartDataPointsFactory { /// /// Create lines of the slices based on the provided . /// /// The containing the slices /// to create the areas for. /// A collection of collections of points in 2D space or an empty collection when /// is null. public static IEnumerable> CreateSliceAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { if (slidingCurve == null) { return Enumerable.Empty(); } return slidingCurve.Slices.Select(slice => new[] { slice.TopLeftPoint, slice.TopRightPoint, slice.BottomRightPoint, slice.BottomLeftPoint }); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateCohesionAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.Cohesion, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateEffectiveStressAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.EffectiveStress, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateEffectiveStressDailyAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.EffectiveStressDaily, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateTotalPorePressureAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.TotalPorePressure, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateWeightAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.Weight, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreatePiezometricPorePressureAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.PiezometricPorePressure, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreatePorePressureAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.PorePressure, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateVerticalPorePressureAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.VerticalPorePressure, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateHorizontalPorePressureAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.HorizontalPorePressure, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateOverConsolidationRatioAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.OverConsolidationRatio, 0.05); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreatePopAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.Pop, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateNormalStressAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.NormalStress, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateShearStressAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.ShearStress, 0.125); } /// /// Creates the areas for /// values in . /// /// The to /// get the slices from. /// A collection of collections of points in 2D space containing areas representing the /// slice output values, or an empty collection when is null. /// public static IEnumerable> CreateLoadStressAreas(MacroStabilityInwardsSlidingCurve slidingCurve) { return CreateParameterAreas(slidingCurve?.Slices, slice => slice.LoadStress, 0.125); } private static IEnumerable> CreateParameterAreas(IEnumerable slices, Func getParameterFunc, double scaleFactor) { if (slices == null || getParameterFunc == null) { return Enumerable.Empty(); } var areas = new List(); foreach (MacroStabilityInwardsSlice slice in slices) { RoundedDouble value = getParameterFunc.Invoke(slice); double offset = value.Value * scaleFactor; double deltaX = slice.BottomLeftPoint.X - slice.BottomRightPoint.X; double deltaY = slice.BottomLeftPoint.Y - slice.BottomRightPoint.Y; double length = Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2)); areas.Add(new[] { slice.BottomLeftPoint, slice.BottomRightPoint, new Point2D(slice.BottomRightPoint.X + offset * -deltaY / length, slice.BottomRightPoint.Y + offset * deltaX / length), new Point2D(slice.BottomLeftPoint.X + offset * -deltaY / length, slice.BottomLeftPoint.Y + offset * deltaX / length) }); } return areas; } } }