public void Convert_Null_ReturnsEmptyColor() { // Call Color color = SoilLayerColorConverter.Convert(null); // Assert Assert.AreEqual(Color.Empty, color); }
/// <summary> /// Transforms the generic <paramref name="soilLayer"/> into one or more <see cref="PipingSoilLayer"/>. /// </summary> /// <param name="soilLayer">The soil layer to use in the transformation.</param> /// <param name="atX">The 1D intersection of the profile.</param> /// <param name="soilLayers">The collection of transformed piping soil layers to add the /// transformation to.</param> /// <param name="bottom">The bottom of the soil layer.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilLayer"/> is <c>null</c>.</exception> /// <exception cref="ImportedDataTransformException">Thrown when transformation would not result /// in a valid transformed instance.</exception> private static void Transform(SoilLayer2D soilLayer, double atX, ICollection <PipingSoilLayer> soilLayers, ref double bottom) { if (soilLayer == null) { throw new ArgumentNullException(nameof(soilLayer)); } ValidateStochasticParameters(soilLayer); if (soilLayer.OuterLoop == null) { return; } string soilLayerName = soilLayer.MaterialName; double[] outerLoopIntersectionHeights = GetLoopIntersectionHeights(soilLayer.OuterLoop.Segments, atX, soilLayerName).ToArray(); if (!outerLoopIntersectionHeights.Any()) { return; } IEnumerable <IEnumerable <double> > innerLoopsIntersectionHeights = soilLayer.NestedLayers.Select(l => GetLoopIntersectionHeights(l.OuterLoop.Segments, atX, soilLayerName)); IEnumerable <Tuple <double, double> > innerLoopIntersectionHeightPairs = GetOrderedStartAndEndPairsIn1D(innerLoopsIntersectionHeights).ToList(); IEnumerable <Tuple <double, double> > outerLoopIntersectionHeightPairs = GetOrderedStartAndEndPairsIn1D(outerLoopIntersectionHeights).ToList(); double currentBottom = outerLoopIntersectionHeightPairs.First().Item1; var heights = new List <double>(); heights.AddRange(innerLoopIntersectionHeightPairs.Where(p => p.Item1 >= currentBottom).Select(p => p.Item1)); heights.AddRange(outerLoopIntersectionHeightPairs.Select(p => p.Item2)); foreach (double height in heights.Where(height => !innerLoopIntersectionHeightPairs.Any(tuple => HeightInInnerLoop(tuple, height)))) { var pipingSoilLayer = new PipingSoilLayer(height) { IsAquifer = TransformIsAquifer(soilLayer.IsAquifer, soilLayerName), MaterialName = soilLayer.MaterialName, Color = SoilLayerColorConverter.Convert(soilLayer.Color) }; SetStochasticParameters(pipingSoilLayer, soilLayer); soilLayers.Add(pipingSoilLayer); } bottom = currentBottom < bottom ? currentBottom : bottom; foreach (SoilLayer2D nestedLayer in soilLayer.NestedLayers) { Transform(nestedLayer, atX, soilLayers, ref bottom); } }
public void Convert_DifferentDoubleValues_ReturnsExpectedColor(double colorValue, int r, int g, int b) { // Call Color color = SoilLayerColorConverter.Convert(colorValue); // Assert Assert.AreEqual(r, color.R); Assert.AreEqual(g, color.G); Assert.AreEqual(b, color.B); Assert.AreEqual(255, color.A); }
/// <summary> /// Converts <see cref="SoilLayerBase"/> into <see cref="MacroStabilityInwardsSoilLayerData"/>. /// </summary> /// <param name="soilLayer">The soil layer to get the data from.</param> /// <exception cref="ImportedDataTransformException">Thrown when transformation would not result /// in a valid transformed instance.</exception> private static MacroStabilityInwardsSoilLayerData ConvertSoilLayerData(SoilLayerBase soilLayer) { string soilLayerName = soilLayer.MaterialName; return(new MacroStabilityInwardsSoilLayerData { ShearStrengthModel = TransformShearStrengthModel(soilLayer.ShearStrengthModel, soilLayerName), UsePop = TransformUsePop(soilLayer.UsePop, soilLayerName), MaterialName = soilLayerName, IsAquifer = TransformIsAquifer(soilLayer.IsAquifer, soilLayerName), Color = SoilLayerColorConverter.Convert(soilLayer.Color), AbovePhreaticLevel = TransformLogNormalDistribution(soilLayer.AbovePhreaticLevelMean, soilLayer.AbovePhreaticLevelCoefficientOfVariation, soilLayer.AbovePhreaticLevelShift, soilLayerName, Resources.SoilLayerData_AbovePhreaticLevelDistribution_Description), BelowPhreaticLevel = TransformLogNormalDistribution(soilLayer.BelowPhreaticLevelMean, soilLayer.BelowPhreaticLevelCoefficientOfVariation, soilLayer.BelowPhreaticLevelShift, soilLayerName, Resources.SoilLayerData_BelowPhreaticLevelDistribution_DisplayName), Cohesion = TransformLogNormalDistribution(soilLayer.CohesionMean, soilLayer.CohesionCoefficientOfVariation, soilLayerName, Resources.SoilLayerData_CohesionDistribution_DisplayName), FrictionAngle = TransformLogNormalDistribution(soilLayer.FrictionAngleMean, soilLayer.FrictionAngleCoefficientOfVariation, soilLayerName, Resources.SoilLayerData_FrictionAngleDistribution_DisplayName), ShearStrengthRatio = TransformLogNormalDistribution(soilLayer.ShearStrengthRatioMean, soilLayer.ShearStrengthRatioCoefficientOfVariation, soilLayerName, Resources.SoilLayerData_ShearStrengthRatioDistribution_DisplayName), StrengthIncreaseExponent = TransformLogNormalDistribution(soilLayer.StrengthIncreaseExponentMean, soilLayer.StrengthIncreaseExponentCoefficientOfVariation, soilLayerName, Resources.SoilLayerData_StrengthIncreaseExponentDistribution_DisplayName), Pop = TransformLogNormalDistribution(soilLayer.PopMean, soilLayer.PopCoefficientOfVariation, soilLayerName, Resources.SoilLayerData_PopDistribution_DisplayName) }); }
/// <summary> /// Transforms the generic <paramref name="soilLayer"/> into a <see cref="PipingSoilLayer"/>. /// </summary> /// <param name="soilLayer">The soil layer to use in the transformation.</param> /// <returns>A new <see cref="PipingSoilLayer"/> based on the given data.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilLayer"/> is <c>null</c>.</exception> /// <exception cref="ImportedDataTransformException">Thrown when transformation would not result /// in a valid transformed instance.</exception> public static PipingSoilLayer Transform(SoilLayer1D soilLayer) { if (soilLayer == null) { throw new ArgumentNullException(nameof(soilLayer)); } ValidateStochasticParameters(soilLayer); var pipingSoilLayer = new PipingSoilLayer(soilLayer.Top) { IsAquifer = TransformIsAquifer(soilLayer.IsAquifer, soilLayer.MaterialName), MaterialName = soilLayer.MaterialName, Color = SoilLayerColorConverter.Convert(soilLayer.Color) }; SetStochasticParameters(pipingSoilLayer, soilLayer); return(pipingSoilLayer); }