/// <summary> /// Indicates whether a stochastic soil model intersects with a surface line. /// </summary> /// <param name="stochasticSoilModel">The stochastic soil model used to match a surface line.</param> /// <param name="surfaceLine">The surface line used to match a stochastic soil model.</param> /// <returns><c>true</c> when the <paramref name="stochasticSoilModel"/> intersects with the <paramref name="surfaceLine"/>; /// <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception> public static bool IntersectsWithSurfaceLineGeometry(this MacroStabilityInwardsStochasticSoilModel stochasticSoilModel, MacroStabilityInwardsSurfaceLine surfaceLine) { if (stochasticSoilModel == null) { throw new ArgumentNullException(nameof(stochasticSoilModel)); } if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } Segment2D[] surfaceLineSegments = Math2D.ConvertPointsToLineSegments(surfaceLine.Points.Select(p => new Point2D(p.X, p.Y))).ToArray(); return(DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(stochasticSoilModel, surfaceLineSegments)); }
/// <summary> /// Updates the <see cref="MacroStabilityInwardsStochasticSoilModel"/> with the properties /// from <paramref name="fromModel"/>. /// </summary> /// <param name="fromModel">The <see cref="MacroStabilityInwardsStochasticSoilModel"/> to /// obtain the property values from.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="fromModel"/> /// is <c>null</c>.</exception> /// <exception cref="InvalidOperationException">Thrown when <see cref="StochasticSoilProfiles"/> /// contains multiple profiles with the same name, and <paramref name="fromModel"/> also contains a /// profile with the same name. /// </exception> public MacroStabilityInwardsStochasticSoilModelProfileDifference Update(MacroStabilityInwardsStochasticSoilModel fromModel) { if (fromModel == null) { throw new ArgumentNullException(nameof(fromModel)); } Name = fromModel.Name; Geometry = fromModel.Geometry; var newSoilProfiles = new List <IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> >(); var updatedProfiles = new List <MacroStabilityInwardsStochasticSoilProfile>(); var addedProfiles = new List <MacroStabilityInwardsStochasticSoilProfile>(); var removedProfiles = new List <MacroStabilityInwardsStochasticSoilProfile>(); foreach (MacroStabilityInwardsStochasticSoilProfile fromProfile in fromModel.StochasticSoilProfiles) { MacroStabilityInwardsStochasticSoilProfile sameProfile = StochasticSoilProfiles.SingleOrDefault( sp => IsSame(sp, fromProfile) ); if (sameProfile != null) { if (!sameProfile.Equals(fromProfile)) { sameProfile.Update(fromProfile); updatedProfiles.Add(sameProfile); } } else { stochasticSoilProfiles.Add(fromProfile); addedProfiles.Add(fromProfile); } newSoilProfiles.Add(fromProfile.SoilProfile); } foreach (MacroStabilityInwardsStochasticSoilProfile profileToRemove in StochasticSoilProfiles.Where( sp => !newSoilProfiles.Any(newSp => IsSame(newSp, sp.SoilProfile))).ToArray()) { stochasticSoilProfiles.Remove(profileToRemove); removedProfiles.Add(profileToRemove); } return(new MacroStabilityInwardsStochasticSoilModelProfileDifference(addedProfiles, updatedProfiles, removedProfiles)); }
private static bool DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(MacroStabilityInwardsStochasticSoilModel stochasticSoilModel, Segment2D[] surfaceLineSegments) { IEnumerable <Segment2D> soilProfileGeometrySegments = Math2D.ConvertPointsToLineSegments(stochasticSoilModel.Geometry); return(soilProfileGeometrySegments.Any(s => DoesSegmentIntersectWithSegmentArray(s, surfaceLineSegments))); }