Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryLoop.cs
===================================================================
diff -u -r1974 -r3079
--- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryLoop.cs (.../GeometryLoop.cs) (revision 1974)
+++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryLoop.cs (.../GeometryLoop.cs) (revision 3079)
@@ -19,7 +19,9 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections.Generic;
+using System.Linq;
namespace Deltares.DamEngine.Data.Geometry
{
@@ -88,6 +90,52 @@
}
///
+ /// Determines whether this instance has area.
+ ///
+ ///
+ public bool HasArea()
+ {
+ if (CurveList.Count < 3)
+ {
+ return false;
+ }
+
+ var points = new List();
+ points.AddRange(Points);
+ points.Add(points[0]);
+
+ // Calculate area of polygon using Shoelace algorithm:
+ var sum = 0.0;
+ for (int i = 1; i < points.Count; i++)
+ {
+ sum += points[i - 1].X * points[i].Z - points[i - 1].Z * points[i].X;
+ }
+
+ return Math.Abs(sum) > 1e-6;
+ }
+
+ ///
+ /// Determines whether [is clock wise].
+ ///
+ ///
+ ///
+ /// Cannot determine if loop is clockwise if checked location forms a straight line with its neighboring vectors.
+ public bool IsClockWise()
+ {
+ var polyGon = GetLocalPoint2DList();
+ var isClockWise = Routines2D.IsClockWise(polyGon);
+ if (isClockWise == Clockwise.NotEnoughUniquePoints)
+ {
+ throw new NotEnoughUniquePointsException();
+ }
+ if (isClockWise == Clockwise.PointsOnLine)
+ {
+ throw new InvalidOperationException("Cannot determine if loop is clockwise if checked location forms a straight line with its neighboring vectors.");
+ }
+ return isClockWise == Clockwise.IsClockwise;
+ }
+
+ ///
/// See if a point lies in a closed surface
///
///
@@ -98,6 +146,15 @@
}
///
+ /// Gets the local 2D Points List.
+ ///
+ ///
+ private List GetLocalPoint2DList()
+ {
+ return CalcPoints;//Points.Select(loopPoint => new Point2D(loopPoint.X, loopPoint.Z)).ToList();
+ }
+
+ ///
/// Populates the loop's GeometryPoint list.
///
private void PopulateLoopPointList()
@@ -150,6 +207,18 @@
calcPoints.RemoveAt(calcPoints.Count - 1);
}
}
- }
+ }
+
+ ///
+ /// Helper class NotEnoughUniquePointsException
+ ///
+ public class NotEnoughUniquePointsException : InvalidOperationException
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public NotEnoughUniquePointsException()
+ : base("At least 3 unique points are required to determine if the loop is running clockwise.") { }
+ }
}
}
\ No newline at end of file