Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2D.cs =================================================================== diff -u -r5228 -r5231 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2D.cs (.../SoilProfile2D.cs) (revision 5228) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2D.cs (.../SoilProfile2D.cs) (revision 5231) @@ -33,9 +33,10 @@ /// public class SoilProfile2D : SoilProfile { - protected readonly List surfaces = new List(); - protected GeometryData geometry = new GeometryData(); - + private readonly List surfaces = new List(); + private GeometryData geometry = new GeometryData(); + private const double deviation = 1E-05; + /// /// Initializes a new instance of the class. /// @@ -125,40 +126,6 @@ } /// - /// Get the surface from the point - /// - /// The point which is supposed to be within the soil layer - /// Surface - public SoilLayer2D GetSoilLayer(Point2D point) - { - for (var i = 0; i < Surfaces.Count; i++) - { - SoilLayer2D surface = Surfaces[i]; - GeometryLoop surfaceLine = surface.GeometrySurface.OuterLoop; - if (surfaceLine.IsPointInLoopArea(point)) - { - var found = true; - - // if point lies in an innerloop it belongs to another area - foreach (GeometryLoop innerloop in surface.GeometrySurface.InnerLoops) - { - if (innerloop.IsPointInLoopArea(point)) - { - found = false; - } - } - - if (found) - { - return surface; - } - } - } - - return null; - } - - /// /// Clone the soil profile 2D /// /// The cloned SoilProfile2D @@ -199,7 +166,8 @@ /// /// /// - public static SoilLayer2D GetOriginalLayerFromOldSurfaces(GeometrySurface geometrySurface, IEnumerable oldSurfaces) + public static SoilLayer2D GetOriginalLayerFromOldSurfaces(GeometrySurface geometrySurface, + IEnumerable oldSurfaces) { return GetOriginalLayerFromOldSurfaces(geometrySurface, oldSurfaces, 0.0); } @@ -215,119 +183,172 @@ double shift) { Point2D point = new Point2D(0.0, 0.0); - bool flag1 = false; - foreach (GeometryCurve curve in geometrySurface.OuterLoop.CurveList) + bool isPointInOuterLoopAndOldSurface = false; + point = IsPointInOuterLoopAndOldSurface(geometrySurface, oldSurfaces, shift, point, ref isPointInOuterLoopAndOldSurface); + + if (!isPointInOuterLoopAndOldSurface) { - point = new Point2D((curve.HeadPoint.X + curve.EndPoint.X) / 2.0, (curve.HeadPoint.Z + curve.EndPoint.Z) / 2.0); - if (IsPointWithinOldSurfaces(point, oldSurfaces, shift, 1E-05) || IsPointWithinOldSurfaces(point, oldSurfaces, shift, -1E-05)) + isPointInOuterLoopAndOldSurface = IsPointInOldSurfaceJustBelowTopOfNewGeometryWithinItsLimits(geometrySurface, + oldSurfaces, shift, point, isPointInOuterLoopAndOldSurface); + } + if (isPointInOuterLoopAndOldSurface) + { + point.X -= shift; + if (IsPointInPreviousOuterLoopOfOldSurface(oldSurfaces, point, out SoilLayer2D soilLayer2D)) { - point.Z += 1E-05; - if (Routines2D.CheckIfPointIsInPolygon(geometrySurface.OuterLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) - { - flag1 = true; - break; - } - point.Z -= 2E-05; - if (Routines2D.CheckIfPointIsInPolygon(geometrySurface.OuterLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) - { - flag1 = true; - break; - } + return soilLayer2D; } + + if (IsPointInOuterLoopOfOldSurface(oldSurfaces, point, out SoilLayer2D originalLayerFromOldSurfaces1)) + { + return originalLayerFromOldSurfaces1; + } } - if (!flag1) - { + return null; + } + + private static bool IsPointInOuterLoopOfOldSurface(IEnumerable oldSurfaces, Point2D point, + out SoilLayer2D originalLayerFromOldSurfaces1) + { + originalLayerFromOldSurfaces1 = null; + foreach (SoilLayer2D oldSurface in oldSurfaces) + { + GeometryLoop outerLoop = oldSurface.GeometrySurface.OuterLoop; + if (outerLoop != null && outerLoop.CurveList.Count > 2 && Routines2D.CheckIfPointIsInPolygon(outerLoop, point.X, + point.Z) == PointInPolygon.InsidePolygon) + { + bool isPointInOuterLoopOfOldSurface = true; + foreach (GeometryLoop innerLoop in oldSurface.GeometrySurface.InnerLoops) + { + if (Routines2D.CheckIfPointIsInPolygon(innerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) + isPointInOuterLoopOfOldSurface = false; + } + if (isPointInOuterLoopOfOldSurface) + { + originalLayerFromOldSurfaces1 = oldSurface; + return true; + } + } + } + + return false; + } + + private static bool IsPointInPreviousOuterLoopOfOldSurface(IEnumerable oldSurfaces, Point2D point, + out SoilLayer2D soilLayer2D) + { + soilLayer2D = null; + foreach (SoilLayer2D oldSurface in oldSurfaces) + { + GeometryLoop previousOuterLoop = oldSurface.GeometrySurface.PreviousOuterLoop; + if (previousOuterLoop != null && previousOuterLoop.CurveList.Count > 2 && + Routines2D.CheckIfPointIsInPolygon(previousOuterLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) + { + bool isPointInPreviousOuterLoopOfOldSurface = true; + foreach (GeometryLoop previousInnerLoop in oldSurface.GeometrySurface.PreviousInnerLoops) + { + if (Routines2D.CheckIfPointIsInPolygon(previousInnerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) + isPointInPreviousOuterLoopOfOldSurface = false; + } + if (isPointInPreviousOuterLoopOfOldSurface) + { + soilLayer2D = oldSurface; + return true; + } + } + } + + return false; + } + + private static bool IsPointInOldSurfaceJustBelowTopOfNewGeometryWithinItsLimits(GeometrySurface geometrySurface, + IEnumerable oldSurfaces, double shift, Point2D point, bool isPointInOuterLoopAndOldSurface) + { GeometryPointString topGeometrySurface = geometrySurface.DetermineTopGeometrySurface(); topGeometrySurface.SortPointsByXAscending(); Point2D geometryPoint1 = topGeometrySurface[0]; - geometryPoint1.X -= 1E-05; - geometryPoint1.Z -= 1E-05; + geometryPoint1.X -= deviation; + geometryPoint1.Z -= deviation; Point2D geometryPoint2 = topGeometrySurface[checked (topGeometrySurface.Count - 1)]; - geometryPoint2.X += 1E-05; - geometryPoint2.Z -= 1E-05; - int num = IsPointWithinOldSurfaces(geometryPoint1, oldSurfaces, shift, -1E-05) ? 1 : 0; - bool flag2 = IsPointWithinOldSurfaces(geometryPoint2, oldSurfaces, shift, -1E-05); + geometryPoint2.X += deviation; + geometryPoint2.Z -= deviation; + bool isPoint1WithinOldSurfaces = IsPointWithinOldSurfaces(geometryPoint1, oldSurfaces, shift, -deviation); + bool isPoint2WithinOldSurfaces = IsPointWithinOldSurfaces(geometryPoint2, oldSurfaces, shift, -deviation); double d = double.NaN; - if (num != 0 && !flag2) + if (isPoint1WithinOldSurfaces && !isPoint2WithinOldSurfaces) { - point.X = geometryPoint1.X; - point.Z = geometryPoint1.Z; - flag1 = true; - d = geometryPoint1.X + 1E-05; + point.X = geometryPoint1.X; + point.Z = geometryPoint1.Z; + isPointInOuterLoopAndOldSurface = true; + d = geometryPoint1.X + deviation; } - if (num == 0 && flag2) + if (!isPoint1WithinOldSurfaces && isPoint2WithinOldSurfaces) { - point.X = geometryPoint2.X; - point.Z = geometryPoint2.Z; - flag1 = true; - d = geometryPoint2.X - 1E-05; + point.X = geometryPoint2.X; + point.Z = geometryPoint2.Z; + isPointInOuterLoopAndOldSurface = true; + d = geometryPoint2.X - deviation; } if (!double.IsNaN(d)) { - double xminFromSurfaces = GetXminFromSurfaces(oldSurfaces); - double xmaxFromSurfaces = GetXmaxFromSurfaces(oldSurfaces); - if (d <= xmaxFromSurfaces && d >= xminFromSurfaces) - flag1 = false; + double xminFromSurfaces = GetXminFromSurfaces(oldSurfaces); + double xmaxFromSurfaces = GetXmaxFromSurfaces(oldSurfaces); + if (d <= xmaxFromSurfaces && d >= xminFromSurfaces) + isPointInOuterLoopAndOldSurface = false; } - } - if (flag1) - { - point.X -= shift; - foreach (SoilLayer2D oldSurface in oldSurfaces) + + return isPointInOuterLoopAndOldSurface; + } + + private static Point2D IsPointInOuterLoopAndOldSurface(GeometrySurface geometrySurface, IEnumerable oldSurfaces, double shift, Point2D point, ref bool isPointInOuterLoopAndOldSurface) + { + foreach (GeometryCurve curve in geometrySurface.OuterLoop.CurveList) { - GeometryLoop previousOuterLoop = oldSurface.GeometrySurface.PreviousOuterLoop; - if (previousOuterLoop != null && previousOuterLoop.CurveList.Count > 2 && - Routines2D.CheckIfPointIsInPolygon(previousOuterLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) - { - bool flag3 = true; - foreach (GeometryLoop previousInnerLoop in oldSurface.GeometrySurface.PreviousInnerLoops) + point = new Point2D((curve.HeadPoint.X + curve.EndPoint.X) / 2.0, (curve.HeadPoint.Z + curve.EndPoint.Z) / 2.0); + if (IsPointWithinOldSurfaces(point, oldSurfaces, shift, deviation) || IsPointWithinOldSurfaces(point, oldSurfaces, + shift, -deviation)) { - if (Routines2D.CheckIfPointIsInPolygon(previousInnerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) - flag3 = false; + point.Z += deviation; + if (Routines2D.CheckIfPointIsInPolygon(geometrySurface.OuterLoop, point.X, point.Z) == + PointInPolygon.InsidePolygon) + { + isPointInOuterLoopAndOldSurface = true; + break; + } + point.Z -= 2*deviation; + if (Routines2D.CheckIfPointIsInPolygon(geometrySurface.OuterLoop, point.X, point.Z) == + PointInPolygon.InsidePolygon) + { + isPointInOuterLoopAndOldSurface = true; + break; + } } - if (flag3) - return oldSurface; - } } - foreach (SoilLayer2D oldSurface in oldSurfaces) - { - GeometryLoop outerLoop = oldSurface.GeometrySurface.OuterLoop; - if (outerLoop != null && outerLoop.CurveList.Count > 2 && Routines2D.CheckIfPointIsInPolygon(outerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) - { - bool flag4 = true; - foreach (GeometryLoop innerLoop in oldSurface.GeometrySurface.InnerLoops) - { - if (Routines2D.CheckIfPointIsInPolygon(innerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) - flag4 = false; - } - if (flag4) - return oldSurface; - } - } - } - return null; + + return point; } - + private static double GetXminFromSurfaces(IEnumerable oldSurfaces) { - double val1 = double.MaxValue; + double xminFromSurfaces = double.MaxValue; foreach (SoilLayer2D oldSurface in oldSurfaces) - val1 = Math.Min(val1, oldSurface.GeometrySurface.OuterLoop.GetMinX()); - return val1; + xminFromSurfaces = Math.Min(xminFromSurfaces, oldSurface.GeometrySurface.OuterLoop.GetMinX()); + return xminFromSurfaces; } private static double GetXmaxFromSurfaces(IEnumerable oldSurfaces) { - double val1 = double.MinValue; + double xmaxFromSurfaces = double.MinValue; foreach (SoilLayer2D oldSurface in oldSurfaces) - val1 = Math.Max(val1, oldSurface.GeometrySurface.OuterLoop.GetMaxX()); - return val1; + xmaxFromSurfaces = Math.Max(xmaxFromSurfaces, oldSurface.GeometrySurface.OuterLoop.GetMaxX()); + return xmaxFromSurfaces; } - private static bool IsPointWithinOldSurfaces(Point2D point, IEnumerable oldSurfaces, double shift, double deviation) + private static bool IsPointWithinOldSurfaces(Point2D point, IEnumerable oldSurfaces, double shift, + double verticalShift) { point.X -= shift; - point.Z += deviation; + point.Z += verticalShift; foreach (SoilLayer2D oldSurface in oldSurfaces) { GeometryLoop outerLoop = oldSurface.GeometrySurface.OuterLoop;