Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs
===================================================================
diff -u -r5256 -r5564
--- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 5256)
+++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 5564)
@@ -758,76 +758,58 @@
}
}
+ ///
+ /// Structure for line constant in 3D
+ ///
public struct LineConstant
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}
+ ///
+ /// Calculates the distance between a point and a line segment.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public static double CalculateDistanceToLine(
double pointX,
double pointY,
- double segmentStartX,
- double segmentStartY,
- double segmentEndX,
- double segmentEndY)
+ double lineStartX,
+ double lineStartY,
+ double lineEndX,
+ double lineEndY)
{
- return Math.Sqrt(CalculateSquaredDistance(new Point2D(pointX, pointY), new Point2D(segmentStartX, segmentStartY),
- new Point2D(segmentEndX, segmentEndY)));
+ return Math.Sqrt(CalculateSquaredDistance(new Point2D(pointX, pointY), new Point2D(lineStartX, lineStartY),
+ new Point2D(lineEndX, lineEndY)));
}
- private static double CalculateSquaredDistance(Point2D point, Point2D segmentPoint1, Point2D segmentPoint2)
+ private static double CalculateSquaredDistance(Point2D point, Point2D lineStart, Point2D lineEnd)
{
- Point2D point2D1 = segmentPoint2 - segmentPoint1;
- Point2D point2D2 = point - segmentPoint1;
- Func func = (first, second) => first.X * second.X + first.Z * second.Z;
- double num1 = func(point2D2, point2D1);
- double num2 = func(point2D1, point2D1);
+ Point2D point2D1 = lineEnd - lineStart;
+ Point2D point2D2 = point - lineStart;
+ double SquareXAndZValues(Point2D first, Point2D second) => first.X * second.X + first.Z * second.Z;
+ double num1 = SquareXAndZValues(point2D2, point2D1);
+ double num2 = SquareXAndZValues(point2D1, point2D1);
Point2D point2D3;
if (num1 <= 0.0)
- point2D3 = point - segmentPoint1;
+ point2D3 = point - lineStart;
else if (num2 <= num1)
{
- point2D3 = point - segmentPoint2;
+ point2D3 = point - lineEnd;
}
else
{
double num3 = num1 / num2;
- Point2D point2D4 = segmentPoint1 + num3 * point2D1;
+ Point2D point2D4 = lineStart + num3 * point2D1;
point2D3 = point - point2D4;
}
- return func(point2D3, point2D3);
+ return SquareXAndZValues(point2D3, point2D3);
}
-
- public static void GetPointOnLineClosestTo(
- double aPointX,
- double aPointY,
- double aLine1X,
- double aLine1Y,
- double aLine2X,
- double aLine2Y,
- out Point2D aResult)
- {
- double x1 = Compute2DDistance(aLine1X, aLine1Y, aLine2X, aLine2Y);
- double x2 = Compute2DDistance(aLine1X, aLine1Y, aPointX, aPointY);
- double x3 = Compute2DDistance(aLine2X, aLine2Y, aPointX, aPointY);
- double num = (Math.Pow(x2, 2.0) - Math.Pow(x3, 2.0) + Math.Pow(x1, 2.0)) / (2.0 * x1);
- aResult = new Point2D();
- if (num <= 0.0)
- {
- aResult.X = aLine1X;
- aResult.Z = aLine1Y;
- }
- else if (num >= x1)
- {
- aResult.X = aLine2X;
- aResult.Z = aLine2Y;
- }
- else
- {
- aResult.X = aLine1X + num / x1 * (aLine2X - aLine1X);
- aResult.Z = aLine1Y + num / x1 * (aLine2Y - aLine1Y);
- }
- }
}
\ No newline at end of file
Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryConstants.cs
===================================================================
diff -u -r5386 -r5564
--- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryConstants.cs (.../GeometryConstants.cs) (revision 5386)
+++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryConstants.cs (.../GeometryConstants.cs) (revision 5564)
@@ -49,7 +49,7 @@
///
/// The accuracy as used for testing similarity of the geometry objects
///
- public const double TestAccuracy = Accuracy / 2.0;
+ public const double Tolerance = Accuracy / 2.0;
///
/// The volumic weight of water
Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs
===================================================================
diff -u -r5528 -r5564
--- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 5528)
+++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 5564)
@@ -131,7 +131,7 @@
var p1 = new Point2D(geometryCurve.HeadPoint.X, geometryCurve.HeadPoint.Z);
var p2 = new Point2D(geometryCurve.EndPoint.X, geometryCurve.EndPoint.Z);
// If head or endpoint is at atX, skip this curve
- if (Math.Abs(p1.X - atX) > GeometryConstants.Accuracy && Math.Abs(p2.X - atX) > GeometryConstants.TestAccuracy)
+ if (Math.Abs(p1.X - atX) > GeometryConstants.Accuracy && Math.Abs(p2.X - atX) > GeometryConstants.Tolerance)
{
var p3 = new Point2D(intersectionCurve.HeadPoint.X, intersectionCurve.HeadPoint.Z);
var p4 = new Point2D(intersectionCurve.EndPoint.X, intersectionCurve.EndPoint.Z);
@@ -161,7 +161,7 @@
Point2D[] points = geometry.Points.ToArray();
for (var i = 0; i < points.Length; i++)
{
- if (points[i].X < atX - GeometryConstants.TestAccuracy)
+ if (points[i].X < atX - GeometryConstants.Tolerance)
{
geometry.DeletePointWithCurves(points[i]);
}
@@ -216,7 +216,7 @@
Point2D[] points = geometry.Points.ToArray();
for (var i = 0; i < points.Length; i++)
{
- if (points[i].X > atX + GeometryConstants.TestAccuracy)
+ if (points[i].X > atX + GeometryConstants.Tolerance)
{
geometry.DeletePointWithCurves(points[i]);
}
@@ -251,7 +251,7 @@
{
foreach (Point2D point in (IEnumerable) surface.OuterLoop.CalcPoints)
{
- if (point.X < atX - GeometryConstants.TestAccuracy)
+ if (point.X < atX - GeometryConstants.Tolerance)
{
surfacesLeftOfLimits.Add(surface);
break;
@@ -268,7 +268,7 @@
{
foreach (Point2D point in (IEnumerable) surface.OuterLoop.CalcPoints)
{
- if (point.X > atX + GeometryConstants.TestAccuracy)
+ if (point.X > atX + GeometryConstants.Tolerance)
{
surfacesRightOfLimits.Add(surface);
break;
@@ -278,10 +278,10 @@
return surfacesRightOfLimits;
}
- private static void DeleteSurface(GeometryData geometry, GeometrySurface aSurface)
+ private static void DeleteSurface(GeometryData geometry, GeometrySurface surface)
{
- GeometrySurface aData = aSurface;
- GeometryLoop outerLoop = aSurface.OuterLoop;
+ GeometrySurface aData = surface;
+ GeometryLoop outerLoop = surface.OuterLoop;
List geometryCurveList = new List();
foreach (GeometryCurve curve in outerLoop.CurveList)
{
@@ -290,17 +290,21 @@
else
geometry.NewlyEffectedCurves.Add(curve);
}
+
foreach (GeometryCurve aCurve in geometryCurveList)
+ {
geometry.DeleteCurve(aCurve, true);
+ }
+
geometry.Remove( outerLoop);
- geometry.Remove( aSurface);
+ geometry.Remove( surface);
geometry.NewlyEffectedCurves.Clear();
}
- private static bool IsCurveAnExistingCurve(GeometryCurve curve, GeometrySurface aData)
+ private static bool IsCurveAnExistingCurve(GeometryCurve curve, GeometrySurface surface)
{
- if (((curve.SurfaceAtLeft == null ? (1) : (curve.SurfaceAtLeft == aData ? 1 : 0)) &
- (curve.SurfaceAtRight == null ? 1 : (curve.SurfaceAtRight == aData ? 1 : 0))) != 0)
+ if (((curve.SurfaceAtLeft == null ? (1) : (curve.SurfaceAtLeft == surface ? 1 : 0)) &
+ (curve.SurfaceAtRight == null ? 1 : (curve.SurfaceAtRight == surface ? 1 : 0))) != 0)
{
return true;
}
@@ -326,9 +330,9 @@
int curveCount = curves.Count;
// loop through the list of curves, check if point on line
- for (var index = 0; index < curveCount; index++)
+ for (var i = 0; i < curveCount; i++)
{
- GeometryCurve curve = curves[index];
+ GeometryCurve curve = curves[i];
// does the input point exist in this line (within aValue1 tolerance)
if (Routines2D.DoesPointExistInLine(curve.HeadPoint, curve.EndPoint, headPoint, GeometryConstants.Accuracy))
Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Point2D.cs
===================================================================
diff -u -r5478 -r5564
--- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Point2D.cs (.../Point2D.cs) (revision 5478)
+++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Point2D.cs (.../Point2D.cs) (revision 5564)
@@ -107,16 +107,34 @@
return res * accuracy;
}
+ ///
+ /// Minus operator for 2D points
+ ///
+ ///
+ ///
+ ///
public static Point2D operator -(Point2D aPoint2, Point2D aPoint1)
{
return new Point2D(aPoint2.X - aPoint1.X, aPoint2.Z - aPoint1.Z);
}
+ ///
+ /// Times operator for 2D points
+ ///
+ ///
+ ///
+ ///
public static Point2D operator *(double aValue1, Point2D aPoint1)
{
return new Point2D(aValue1 * aPoint1.X, aValue1 * aPoint1.Z);
}
+ ///
+ /// Sum operator for 2D points
+ ///
+ ///
+ ///
+ ///
public static Point2D operator +(Point2D aPoint2, Point2D aPoint1)
{
return new Point2D(aPoint2.X + aPoint1.X, aPoint2.Z + aPoint1.Z);
Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryObject.cs
===================================================================
diff -u -r5479 -r5564
--- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryObject.cs (.../GeometryObject.cs) (revision 5479)
+++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryObject.cs (.../GeometryObject.cs) (revision 5564)
@@ -80,6 +80,6 @@
///
///
///
- ///
+ /// the value rounded to the requested accuracy
public static double RoundValue(double originalValue, double accuracy = GeometryConstants.Accuracy) => Math.Round(originalValue / accuracy) * accuracy;
}
\ No newline at end of file
Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs
===================================================================
diff -u -r5561 -r5564
--- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 5561)
+++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 5564)
@@ -951,6 +951,12 @@
#endregion
+ ///
+ /// Regenerates all the curves that have intersections.
+ /// Find all intersections between curves and split them at the intersection points, adding curves where needed.
+ /// Find all parallel curves and split them at the intersection pointss, adding curves where needed.
+ /// At the end, clean up the points and curves.
+ ///
private void RegenerateAllCurvesIntersection()
{
intersectedCurveList.Clear();