Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2D.cs =================================================================== diff -u -r5212 -r5228 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2D.cs (.../SoilProfile2D.cs) (revision 5212) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2D.cs (.../SoilProfile2D.cs) (revision 5228) @@ -326,38 +326,40 @@ private static bool IsPointWithinOldSurfaces(Point2D point, IEnumerable oldSurfaces, double shift, double deviation) { - bool flag = false; point.X -= shift; point.Z += deviation; foreach (SoilLayer2D oldSurface in oldSurfaces) { GeometryLoop outerLoop = oldSurface.GeometrySurface.OuterLoop; - if (outerLoop != null && Routines2D.CheckIfPointIsInPolygon(outerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) + List innerLoops = oldSurface.GeometrySurface.InnerLoops; + var isPointInSurface = IsPointInGivenOuterLoopOfOldSurface(point, outerLoop, innerLoops); + if (!isPointInSurface) { - flag = true; - foreach (GeometryLoop innerLoop in oldSurface.GeometrySurface.InnerLoops) - { - if (Routines2D.CheckIfPointIsInPolygon(innerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) - flag = false; - } - } - if (!flag) - { GeometryLoop previousOuterLoop = oldSurface.GeometrySurface.PreviousOuterLoop; - if (previousOuterLoop != null && Routines2D.CheckIfPointIsInPolygon(previousOuterLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) - { - flag = true; - foreach (GeometryLoop previousInnerLoop in oldSurface.GeometrySurface.PreviousInnerLoops) - { - if (Routines2D.CheckIfPointIsInPolygon(previousInnerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) - flag = false; - } - } + List previousInnerLoops = oldSurface.GeometrySurface.PreviousInnerLoops; + isPointInSurface = IsPointInGivenOuterLoopOfOldSurface(point, previousOuterLoop, previousInnerLoops); } - if (flag) + if (isPointInSurface) return true; } return false; } + + private static bool IsPointInGivenOuterLoopOfOldSurface(Point2D point, GeometryLoop outerLoop, + List innerLoops) + { + var isPointInSurface = false; + if (outerLoop != null && Routines2D.CheckIfPointIsInPolygon(outerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) + { + isPointInSurface = true; + // Make sure the point is in the outer loop, not in the inner loop(s). + foreach (GeometryLoop innerLoop in innerLoops) + { + if (Routines2D.CheckIfPointIsInPolygon(innerLoop, point.X, point.Z) == PointInPolygon.InsidePolygon) + return false; + } + } + return isPointInSurface; + } } \ No newline at end of file