Index: Core/Common/src/Core.Common.Geometry/AdvancedMath2D.cs =================================================================== diff -u -r6cdb90fc3f89fe0c44b62d3be7266a0090a6b891 -r2016e52c40bafa21e1c6d49c9cdc54cc31c6f3a0 --- Core/Common/src/Core.Common.Geometry/AdvancedMath2D.cs (.../AdvancedMath2D.cs) (revision 6cdb90fc3f89fe0c44b62d3be7266a0090a6b891) +++ Core/Common/src/Core.Common.Geometry/AdvancedMath2D.cs (.../AdvancedMath2D.cs) (revision 2016e52c40bafa21e1c6d49c9cdc54cc31c6f3a0) @@ -119,6 +119,36 @@ }).ToArray(); } + /// + /// Gets the interior point of a polygon. + /// + /// The outer ring of the polygon. + /// The inner rings of the polygon. + /// The interior point. + /// Thrown when any + /// parameter is null. + public static Point2D GetPolygonInteriorPoint(IEnumerable outerRing, IEnumerable> innerRings) + { + if (outerRing == null) + { + throw new ArgumentNullException(nameof(outerRing)); + } + + if (innerRings == null) + { + throw new ArgumentNullException(nameof(innerRings)); + } + + Polygon outerPolygon = PointsToPolygon(outerRing); + IEnumerable innerPolygons = innerRings.Select(PointsToPolygon).ToArray(); + + var polygon = new Polygon(outerPolygon.Shell, innerPolygons.Select(p => p.Shell).ToArray()); + + IPoint interiorPoint = polygon.InteriorPoint; + + return new Point2D(interiorPoint.X, interiorPoint.Y); + } + private static IEnumerable GetPointsFromLine(IEnumerable line, double completingPointsLevel) { foreach (Point2D point in line) Index: Core/Common/test/Core.Common.Geometry.Test/AdvancedMath2DTest.cs =================================================================== diff -u -r51b64230b9b947ba32821ed104809429d469959b -r2016e52c40bafa21e1c6d49c9cdc54cc31c6f3a0 --- Core/Common/test/Core.Common.Geometry.Test/AdvancedMath2DTest.cs (.../AdvancedMath2DTest.cs) (revision 51b64230b9b947ba32821ed104809429d469959b) +++ Core/Common/test/Core.Common.Geometry.Test/AdvancedMath2DTest.cs (.../AdvancedMath2DTest.cs) (revision 2016e52c40bafa21e1c6d49c9cdc54cc31c6f3a0) @@ -429,6 +429,41 @@ Assert.AreEqual(new Point2D(firstPointX, completingPointsLevel), pointsOfPolygon.ElementAt(4)); } + [Test] + public void GetPolygonInteriorPoint_OuterRingNull_ThrowsArgumentNullException() + { + // Call + void Call() => AdvancedMath2D.GetPolygonInteriorPoint(null, new IEnumerable[0]); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("outerRing", exception.ParamName); + } + + [Test] + public void GetPolygonInteriorPoint_InnerRingsNull_ThrowsArgumentNullException() + { + // Call + void Call() => AdvancedMath2D.GetPolygonInteriorPoint(CreateBasePolygon(), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("innerRings", exception.ParamName); + } + + [Test] + public void GetPolygonInteriorPoint_WithGeometry_ReturnsInteriorPoint() + { + // Setup + Point2D[] outerRing = CreateBasePolygon(); + + // Call + Point2D interiorPoint = AdvancedMath2D.GetPolygonInteriorPoint(outerRing, new IEnumerable[0]); + + // Assert + Assert.AreEqual(new Point2D(2, 2), interiorPoint); + } + private static double[] ThreeRandomXCoordinates() { var random = new Random(21);