Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs
===================================================================
diff -u -r6404 -r7045
--- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 6404)
+++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 7045)
@@ -294,7 +294,7 @@
al3 = al3 - (2.0 * Math.PI);
}
- if (((Math.PI - al3) < epsilon) || ((Math.PI + al3) < epsilon))
+ if ((Math.PI - al3 < epsilon) || (Math.PI + al3 < epsilon))
{
UndoAddIfNeeded(polygon, pointAdded);
return PointInPolygon.OnPolygonEdge;
@@ -307,7 +307,7 @@
index++;
}
- if ((som > (1.9 * Math.PI)) || (som < (-1.9 * Math.PI)))
+ if ((som > 1.9 * Math.PI) || (som < -1.9 * Math.PI))
{
result = PointInPolygon.InsidePolygon;
}
@@ -359,7 +359,7 @@
if (lD > lAbcEps)
{
double lU = (-lB + Math.Sqrt(lD)) / (2 * lA);
- if ((lU >= -lAbcEps) && (lU <= (1.0 + lAbcEps)))
+ if ((lU >= -lAbcEps) && (lU <= 1.0 + lAbcEps))
{
result.Add(new Point2D
{
@@ -370,7 +370,7 @@
lU = (-lB - Math.Sqrt(lD)) / (2 * lA);
- if ((lU >= -lAbcEps) && (lU <= (1.0 + lAbcEps)))
+ if ((lU >= -lAbcEps) && (lU <= 1.0 + lAbcEps))
{
result.Add(new Point2D
{
@@ -381,7 +381,7 @@
}
else if (Math.Abs(lD) <= lAbcEps)
{
- double lU = (-lB) / (2 * lA);
+ double lU = -lB / (2 * lA);
if ((lU >= -lAbcEps) && (lU <= 1.0 + lAbcEps))
{
result.Add(new Point2D
@@ -444,7 +444,7 @@
///
public static bool AreEqual(double x1, double x2, double tolerance)
{
- return (Math.Abs(x1 - x2) < tolerance);
+ return Math.Abs(x1 - x2) < tolerance;
}
///
@@ -512,7 +512,7 @@
/// true when points coincide
public static bool DetermineIfPointsCoincide(double point1X, double point1Z, double point2X, double point2Z, double tolerance)
{
- if ((Math.Abs(point1X - point2X)) < tolerance && Math.Abs(point1Z - point2Z) < tolerance)
+ if (Math.Abs(point1X - point2X) < tolerance && Math.Abs(point1Z - point2Z) < tolerance)
{
return true;
}
@@ -558,6 +558,32 @@
new Point2D(lineEndX, lineEndY)));
}
+ public static Point2D ComputeCentroid(List polygon)
+ {
+ double accumulatedArea = 0;
+ double centerX = 0;
+ double centerY = 0;
+
+ int count = polygon.Count;
+
+ for (var i = 0; i < count; i++)
+ {
+ Point2D current = polygon[i];
+ Point2D next = polygon[(i + 1) % count];
+
+ double cross = current.X * next.Z - next.X * current.Z;
+ accumulatedArea += cross;
+ centerX += (current.X + next.X) * cross;
+ centerY += (current.Z + next.Z) * cross;
+ }
+
+ accumulatedArea *= 0.5f;
+ centerX /= 6 * accumulatedArea;
+ centerY /= 6 * accumulatedArea;
+
+ return new Point2D(centerX, centerY);
+ }
+
private static void UndoAddIfNeeded(GeometryLoop polygon, bool needed)
{
if (needed)