/// <summary> /// Initializes a new instance of the <see cref="MinkowskiSumAlgorithm" /> class. /// </summary> /// <param name="source">The source.</param> /// <param name="buffer">The buffer.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException"> /// The source is null. /// or /// The buffer is null. /// </exception> public MinkowskiSumAlgorithm(IBasicPoint source, IReadOnlyList <Coordinate> buffer, PrecisionModel precisionModel) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } this.PrecisionModel = precisionModel ?? PrecisionModel.Default; this.sourceShellCoordinates = new Coordinate[] { source.Coordinate }; this.sourceHoleCoordinates = null; if (buffer.Count > 0 && buffer[0] != buffer[buffer.Count - 1]) { this.bufferCoordinates = new BasicProxyLineString(buffer, true); } else { this.bufferCoordinates = buffer; } this.hasResult = false; }
/// <summary> /// Initializes a new instance of the <see cref="MinkowskiSumAlgorithm"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="buffer">The buffer.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> /// <exception cref="System.ArgumentNullException">The buffer is null.</exception> /// <exception cref="System.ArgumentException">The orientation of the source is not suitable.</exception> /// <exception cref="System.ArgumentException">The orientation of the buffer is not suitable.</exception> public MinkowskiSumAlgorithm(IBasicPoint source, IBasicPolygon buffer) { if (source == null) { throw new ArgumentNullException(nameof(source), "The source is null."); } if (buffer == null) { throw new ArgumentNullException(nameof(buffer), "The buffer is null."); } _sourceShellCoordinates = new List <Coordinate>(); _sourceShellCoordinates.Add(source.Coordinate); _bufferCoordinates = new List <Coordinate>(); foreach (Coordinate coordinate in buffer.Shell.Coordinates) { _bufferCoordinates.Add(coordinate); } if (PolygonAlgorithms.Orientation(_bufferCoordinates) != Orientation.CounterClockwise) { throw new ArgumentException("The orientation of the buffer is not suitable.", nameof(buffer)); } _hasResult = false; }
/// <summary> /// Buffers he specified source. /// </summary> /// <param name="source">The source.</param> /// <param name="buffer">The buffer.</param> /// <param name="precisionModel">The precision model.</param> /// <returns>The buffered polygon.</returns> /// <exception cref="System.ArgumentNullException"> /// The source is null. /// or /// The buffer is null. /// </exception> public static IBasicPolygon Buffer(IBasicPoint source, IBasicPolygon buffer, PrecisionModel precisionModel) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } return(new MinkowskiSumAlgorithm(source, buffer.Shell, precisionModel).Result); }
/// <summary> /// Computes the distance between the specified geometries. /// </summary> /// <param name="point">The point.</param> /// <param name="lineString">The line string.</param> /// <param name="precisionModel">The precision model.</param> /// <returns>The distance between the specified geometries.</returns> /// <exception cref="System.ArgumentNullException"> /// The point is null. /// or /// The line string is null. /// </exception> public static Double Distance(IBasicPoint point, IBasicLineString lineString, PrecisionModel precisionModel) { if (point == null) { throw new ArgumentNullException(nameof(point)); } if (lineString == null) { throw new ArgumentNullException(nameof(lineString)); } return(new GeometryDistanceAlgorithm(new[] { point.Coordinate }, lineString, precisionModel).Result); }
/// <summary> /// Computes the distance between the specified geometries. /// </summary> /// <param name="first">The first point.</param> /// <param name="second">The second point.</param> /// <returns>The distance between the specified geometries.</returns> /// <exception cref="System.ArgumentNullException"> /// The first point is null. /// or /// The second point is null. /// </exception> public static Double Distance(IBasicPoint first, IBasicPoint second) { if (first == null) { throw new ArgumentNullException(nameof(first)); } if (second == null) { throw new ArgumentNullException(nameof(second)); } return(Coordinate.Distance(first.Coordinate, second.Coordinate)); }
/// <summary> /// Compares two <see cref="IBasicPoint" /> instances and returns a value indicating whether one is less than, equal to, or greater than the other. /// </summary> /// <param name="x">The first <see cref="IBasicPoint" /> to compare.</param> /// <param name="y">The second <see cref="IBasicPoint" /> to compare.</param> /// <returns>A signed integer that indicates the relative values of <paramref name="x" /> and <paramref name="y" />.</returns> /// <exception cref="System.ArgumentNullException"> /// The x argument is null. /// or /// The y argument is null. /// </exception> public Int32 Compare(IBasicPoint x, IBasicPoint y) { if (x == null) { throw new ArgumentNullException("x", "The x argument is null."); } if (y == null) { throw new ArgumentNullException("y", "The y argument is null."); } if (x == y) { return(0); } return(_comparer.Compare(x.Coordinate, y.Coordinate)); }
/// <summary> /// If the input geometry is a singular basic geometry, this will become a collection of 1 geometry. /// If the input geometry is a multi- basic geometry, this will simply ensure that each member /// is upgraded to a full geometry. /// </summary> /// <param name="inGeometry"></param> /// <param name="inFactory"></param> public GeometryCollection(IBasicGeometry inGeometry, IGeometryFactory inFactory) : base(inFactory) { if (inGeometry == null) { _geometries = new IGeometry[] { }; return; } IBasicPolygon pg = inGeometry.GetBasicGeometryN(0) as IBasicPolygon; if (pg != null) { _geometries = new IGeometry[inGeometry.NumGeometries]; for (int iGeom = 0; iGeom < inGeometry.NumGeometries; iGeom++) { pg = inGeometry.GetBasicGeometryN(iGeom) as IBasicPolygon; _geometries[iGeom] = new Polygon(pg); } return; } IBasicPoint pt = inGeometry.GetBasicGeometryN(0) as IBasicPoint; if (pt != null) { _geometries = new IGeometry[inGeometry.NumGeometries]; for (int iGeom = 0; iGeom < inGeometry.NumGeometries; iGeom++) { pt = inGeometry.GetBasicGeometryN(iGeom) as IBasicPoint; _geometries[iGeom] = new Point(pt); } return; } IBasicLineString ls = inGeometry.GetBasicGeometryN(0) as IBasicLineString; if (ls != null) { _geometries = new IGeometry[inGeometry.NumGeometries]; for (int iGeom = 0; iGeom < inGeometry.NumGeometries; iGeom++) { ls = inGeometry.GetBasicGeometryN(iGeom) as IBasicLineString; _geometries[iGeom] = new LineString(ls); } return; } }
/// <summary> /// Computes the distance between the specified geometries. /// </summary> /// <param name="first">The first point.</param> /// <param name="second">The second point.</param> /// <param name="precisionModel">The precision model.</param> /// <returns>The distance between the specified geometries.</returns> /// <exception cref="System.ArgumentNullException"> /// The first point is null. /// or /// The second point is null. /// </exception> public static Double Distance(IBasicPoint first, IBasicPoint second, PrecisionModel precisionModel) { if (first == null) { throw new ArgumentNullException(nameof(first)); } if (second == null) { throw new ArgumentNullException(nameof(second)); } if (precisionModel == null) { return(Coordinate.Distance(first.Coordinate, second.Coordinate)); } return(precisionModel.MakePrecise(Coordinate.Distance(first.Coordinate, second.Coordinate))); }
/// <summary> /// Computes the distance between the specified geometries. /// </summary> /// <param name="point">The point.</param> /// <param name="polygon">The polygon.</param> /// <param name="precisionModel">The precision model.</param> /// <returns>The distance between the specified geometries.</returns> /// <exception cref="System.ArgumentNullException"> /// The point is null. /// or /// The polygon is null. /// </exception> public static Double Distance(IBasicPoint point, IBasicPolygon polygon, PrecisionModel precisionModel) { if (point == null) { throw new ArgumentNullException(nameof(point)); } if (polygon == null) { throw new ArgumentNullException(nameof(polygon)); } if (!WindingNumberAlgorithm.InExterior(polygon, point.Coordinate)) { return(0); } if (polygon.HoleCount == 0) { return(Distance(point, polygon.Shell, precisionModel)); } return(Math.Min(Distance(point, polygon.Shell, precisionModel), polygon.Holes.Min(hole => Distance(point, hole, precisionModel)))); }
/// <summary> /// Buffers he specified source. /// </summary> /// <param name="source">The source.</param> /// <param name="radius">The radius of the buffer.</param> /// <param name="numberOfCoordinates">The number of coordinates of the buffer.</param> /// <param name="precisionModel">The precision model.</param> /// <returns>The buffered polygon.</returns> /// <exception cref="System.ArgumentNullException">The source is null.</exception> /// <exception cref="System.ArgumentOutOfRangeException">The number of coordinates is less than 3.</exception> public static IBasicPolygon Buffer(IBasicPoint source, Double radius, Int32 numberOfCoordinates, PrecisionModel precisionModel) { return(new MinkowskiSumAlgorithm(source, CreateCircle(radius, numberOfCoordinates), precisionModel).Result); }
public void MinkowskiSumAlgorithmBufferTest() { // two triangles IBasicPolygon buffer = new BasicPolygon( new Coordinate[] { new Coordinate(5, 5), new Coordinate(5, 7), new Coordinate(4, 6) }); List <Coordinate> sourceShellCoordinates = new List <Coordinate> { new Coordinate(2, 1), new Coordinate(4, 1), new Coordinate(3, 3) }; List <Coordinate> expectedCoordinates = new List <Coordinate> { new Coordinate(6, 7), new Coordinate(7, 6), new Coordinate(9, 6), new Coordinate(9, 8), new Coordinate(8, 10), new Coordinate(7, 9), }; IBasicPolygon expectedResult = new BasicPolygon(expectedCoordinates); IBasicPolygon actualResult = MinkowskiSumAlgorithm.Buffer(sourceShellCoordinates, buffer); Assert.IsTrue(PolygonAlgorithms.IsConvex(actualResult)); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i], actualResult.Shell.Coordinates[i]); } // triangle and a square buffer = new BasicPolygon( new Coordinate[] { new Coordinate(8, 6), new Coordinate(9, 6), new Coordinate(9, 7), new Coordinate(8, 7) }); sourceShellCoordinates = new List <Coordinate> { new Coordinate(3, 4), new Coordinate(5, 4), new Coordinate(4, 6) }; expectedCoordinates = new List <Coordinate> { new Coordinate(11, 11), new Coordinate(11, 10), new Coordinate(13, 10), new Coordinate(14, 10), new Coordinate(14, 11), new Coordinate(13, 13), new Coordinate(12, 13), new Coordinate(11, 11) }; expectedResult = new BasicPolygon(expectedCoordinates); actualResult = MinkowskiSumAlgorithm.Buffer(sourceShellCoordinates, buffer); Assert.IsTrue(PolygonAlgorithms.IsConvex(actualResult)); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i], actualResult.Shell.Coordinates[i]); } // square and circle of 4 points (square) buffer = new BasicPolygon( new Coordinate[] { new Coordinate(8, 6), new Coordinate(9, 6), new Coordinate(9, 7), new Coordinate(8, 7) }); expectedCoordinates = new List <Coordinate> { new Coordinate(6, 6), new Coordinate(8, 4), new Coordinate(9, 4), new Coordinate(11, 6), new Coordinate(11, 7), new Coordinate(9, 9), new Coordinate(8, 9), new Coordinate(6, 7), new Coordinate(6, 6) }; expectedResult = new BasicPolygon(expectedCoordinates); actualResult = MinkowskiSumAlgorithm.Buffer(buffer, 2, 4); Assert.IsTrue(PolygonAlgorithms.IsConvex(actualResult)); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i].X, Math.Round(actualResult.Shell.Coordinates[i].X, 2)); Assert.AreEqual(expectedResult.Shell.Coordinates[i].Y, Math.Round(actualResult.Shell.Coordinates[i].Y, 2)); } // point and circle (of 4 points) IBasicPoint point = _factory.CreatePoint(1, 1, 0); actualResult = MinkowskiSumAlgorithm.Buffer(point, 2, 4); expectedCoordinates = new List <Coordinate> { new Coordinate(3, 1), new Coordinate(1, 3), new Coordinate(-1, 1), new Coordinate(1, -1) }; expectedResult = new BasicPolygon(expectedCoordinates); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i].X, Math.Round(actualResult.Shell.Coordinates[i].X, 2)); Assert.AreEqual(expectedResult.Shell.Coordinates[i].Y, Math.Round(actualResult.Shell.Coordinates[i].Y, 2)); } // square with a square hole and circle (of 8 points) sourceShellCoordinates = new List <Coordinate> { new Coordinate(1, 1), new Coordinate(9, 1), new Coordinate(9, 9), new Coordinate(1, 9), new Coordinate(1, 1) }; List <List <Coordinate> > holes = new List <List <Coordinate> >(); holes.Add(new List <Coordinate>()); holes[0] = new List <Coordinate>(); holes[0].Add(new Coordinate(3, 3)); holes[0].Add(new Coordinate(3, 7)); holes[0].Add(new Coordinate(7, 7)); holes[0].Add(new Coordinate(7, 3)); holes[0].Add(new Coordinate(3, 3)); BasicPolygon source = new BasicPolygon(sourceShellCoordinates, holes); actualResult = MinkowskiSumAlgorithm.Buffer(source, 1, 8); expectedCoordinates = new List <Coordinate> { new Coordinate(0, 1), new Coordinate(0.3, 0.3), new Coordinate(1, 0), new Coordinate(9, 0), new Coordinate(9.7, 0.3), new Coordinate(10, 1), new Coordinate(10, 9), new Coordinate(9.7, 9.7), new Coordinate(9, 10), new Coordinate(1, 10), new Coordinate(0.3, 9.7), new Coordinate(0, 9) }; List <List <Coordinate> > expectedHoleCoordinates = new List <List <Coordinate> >(); expectedHoleCoordinates.Add(new List <Coordinate>() { new Coordinate(4, 3), new Coordinate(3.7, 3.7), new Coordinate(3, 4), new Coordinate(3, 6), new Coordinate(3.7, 6.3), new Coordinate(4, 7), new Coordinate(6, 7), new Coordinate(6.3, 6.3), new Coordinate(7, 6), new Coordinate(7, 4), new Coordinate(6.3, 3.7), new Coordinate(6, 3) }); expectedResult = new BasicPolygon(expectedCoordinates); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i].X, Math.Round(actualResult.Shell.Coordinates[i].X, 1)); Assert.AreEqual(expectedResult.Shell.Coordinates[i].Y, Math.Round(actualResult.Shell.Coordinates[i].Y, 1)); } Assert.AreEqual(expectedHoleCoordinates.Count, actualResult.HoleCount); for (Int32 i = 0; i < expectedHoleCoordinates.Count; i++) { for (Int32 j = 0; j < expectedHoleCoordinates[i].Count; j++) { Assert.AreEqual(expectedHoleCoordinates[i][j].X, Math.Round(actualResult.Holes[i].Coordinates[j].X, 1)); Assert.AreEqual(expectedHoleCoordinates[i][j].Y, Math.Round(actualResult.Holes[i].Coordinates[j].Y, 1)); } } // line string (2 points) and square buffer = new BasicPolygon( new Coordinate[] { new Coordinate(0, 2), new Coordinate(0, 0), new Coordinate(2, 0), new Coordinate(2, 2) }); actualResult = MinkowskiSumAlgorithm.Buffer(new BasicLineString(new List <Coordinate>() { new Coordinate(0, 4), new Coordinate(2, 4) }), buffer); expectedCoordinates = new List <Coordinate> { new Coordinate(0, 6), new Coordinate(0, 4), new Coordinate(2, 4), new Coordinate(4, 4), new Coordinate(4, 6), new Coordinate(2, 6) }; expectedResult = new BasicPolygon(expectedCoordinates); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i], actualResult.Shell.Coordinates[i]); } // line string (4 points) and square buffer = new BasicPolygon( new Coordinate[] { new Coordinate(0, 2), new Coordinate(0, 0), new Coordinate(2, 0), new Coordinate(2, 2) }); actualResult = MinkowskiSumAlgorithm.Buffer(new BasicLineString(new List <Coordinate>() { new Coordinate(1, 1), new Coordinate(3, 3), new Coordinate(5, 6), new Coordinate(3, 8) }), buffer); expectedCoordinates = new List <Coordinate> { new Coordinate(1, 3), new Coordinate(1, 1), new Coordinate(3, 1), new Coordinate(5, 3), new Coordinate(7, 6), new Coordinate(7, 8), new Coordinate(5, 10), new Coordinate(3, 10) }; expectedResult = new BasicPolygon(expectedCoordinates); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i], actualResult.Shell.Coordinates[i]); } // concave and convex with no hole in the result buffer = new BasicPolygon( new Coordinate[] { new Coordinate(13, 2), new Coordinate(14, 3), new Coordinate(13, 4), new Coordinate(12, 3) }); sourceShellCoordinates = new List <Coordinate> { new Coordinate(1, 1), new Coordinate(11, 1), new Coordinate(11, 6), new Coordinate(8, 6), new Coordinate(9, 3), new Coordinate(3, 3), new Coordinate(4, 6), new Coordinate(1, 6) }; actualResult = MinkowskiSumAlgorithm.Buffer(sourceShellCoordinates, buffer); expectedCoordinates = new List <Coordinate> { new Coordinate(13, 4), new Coordinate(14, 3), new Coordinate(24, 3), new Coordinate(25, 4), new Coordinate(25, 9), new Coordinate(24, 10), new Coordinate(21, 10), new Coordinate(20, 9), new Coordinate(20.67, 7), new Coordinate(17.33, 7), new Coordinate(18, 9), new Coordinate(17, 10), new Coordinate(14, 10), new Coordinate(13, 9) }; expectedResult = new BasicPolygon(expectedCoordinates); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i].X, Math.Round(actualResult.Shell.Coordinates[i].X, 2)); Assert.AreEqual(expectedResult.Shell.Coordinates[i].Y, Math.Round(actualResult.Shell.Coordinates[i].Y, 2)); } // convex and concave with no hole in the result buffer = new BasicPolygon( new Coordinate[] { new Coordinate(0, 3), new Coordinate(-3, 0), new Coordinate(0, -3), new Coordinate(3, 0) }); sourceShellCoordinates = new List <Coordinate> { new Coordinate(1, 1), new Coordinate(11, 1), new Coordinate(11, 6), new Coordinate(8, 6), new Coordinate(9, 3), new Coordinate(3, 3), new Coordinate(4, 6), new Coordinate(1, 6) }; actualResult = MinkowskiSumAlgorithm.Buffer(sourceShellCoordinates, buffer); expectedCoordinates = new List <Coordinate> { new Coordinate(-2, 1), new Coordinate(1, -2), new Coordinate(11, -2), new Coordinate(14, 1), new Coordinate(14, 6), new Coordinate(11, 9), new Coordinate(8, 9), new Coordinate(6, 7), new Coordinate(4, 9), new Coordinate(1, 9), new Coordinate(-2, 6) }; expectedResult = new BasicPolygon(expectedCoordinates); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i].X, Math.Round(actualResult.Shell.Coordinates[i].X, 2)); Assert.AreEqual(expectedResult.Shell.Coordinates[i].Y, Math.Round(actualResult.Shell.Coordinates[i].Y, 2)); } // convex and concave with hole in the result buffer = new BasicPolygon( new Coordinate[] { new Coordinate(13, 4), new Coordinate(12, 3), new Coordinate(13, 2), new Coordinate(14, 3) }); sourceShellCoordinates = new List <Coordinate> { new Coordinate(1, 1), new Coordinate(11, 1), new Coordinate(11, 6), new Coordinate(7, 6), new Coordinate(9, 3), new Coordinate(4, 3), new Coordinate(6, 6), new Coordinate(1, 6) }; actualResult = MinkowskiSumAlgorithm.Buffer(sourceShellCoordinates, buffer); expectedCoordinates = new List <Coordinate> { new Coordinate(13, 4), new Coordinate(14, 3), new Coordinate(24, 3), new Coordinate(25, 4), new Coordinate(25, 9), new Coordinate(24, 10), new Coordinate(20, 10), new Coordinate(19.5, 9.5), new Coordinate(19, 10), new Coordinate(14, 10), new Coordinate(13, 9) }; expectedHoleCoordinates = new List <List <Coordinate> >(); expectedHoleCoordinates.Add(new List <Coordinate>() { new Coordinate(19.5, 8.25), new Coordinate(20.3, 7), new Coordinate(18.6, 7) }); expectedResult = new BasicPolygon(expectedCoordinates); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i], actualResult.Shell.Coordinates[i]); } Assert.AreEqual(expectedHoleCoordinates.Count, actualResult.HoleCount); for (Int32 i = 0; i < expectedHoleCoordinates.Count; i++) { for (Int32 j = 0; j < expectedHoleCoordinates[i].Count; j++) { Assert.AreEqual(expectedHoleCoordinates[i][j].X, Math.Round(actualResult.Holes[i].Coordinates[j].X), 2); Assert.AreEqual(expectedHoleCoordinates[i][j].Y, Math.Round(actualResult.Holes[i].Coordinates[j].Y), 2); } } // convex source polygon with hole and a rhombus buffer = _factory.CreatePolygon( _factory.CreatePoint(10, 2), _factory.CreatePoint(11, 3), _factory.CreatePoint(10, 4), _factory.CreatePoint(9, 3)); sourceShellCoordinates = new List <Coordinate> { new Coordinate(1, 1), new Coordinate(9, 1), new Coordinate(9, 9), new Coordinate(1, 9), new Coordinate(1, 1) }; holes = new List <List <Coordinate> >(); holes.Add(new List <Coordinate>()); holes[0] = new List <Coordinate>(); holes[0].Add(new Coordinate(3, 3)); holes[0].Add(new Coordinate(3, 7)); holes[0].Add(new Coordinate(7, 7)); holes[0].Add(new Coordinate(7, 3)); holes[0].Add(new Coordinate(3, 3)); source = new BasicPolygon(sourceShellCoordinates, holes); actualResult = MinkowskiSumAlgorithm.Buffer(source, buffer); expectedCoordinates = new List <Coordinate> { new Coordinate(10, 4), new Coordinate(11, 3), new Coordinate(19, 3), new Coordinate(20, 4), new Coordinate(20, 12), new Coordinate(19, 13), new Coordinate(11, 13), new Coordinate(10, 12) }; expectedHoleCoordinates = new List <List <Coordinate> >(); expectedHoleCoordinates.Add(new List <Coordinate>() { new Coordinate(14, 6), new Coordinate(13, 7), new Coordinate(13, 9), new Coordinate(14, 10), new Coordinate(16, 10), new Coordinate(17, 9), new Coordinate(17, 7), new Coordinate(16, 6) }); expectedResult = new BasicPolygon(expectedCoordinates); Assert.AreEqual(expectedResult.Shell.Count, actualResult.Shell.Count); for (Int32 i = 0; i < expectedResult.Shell.Count; i++) { Assert.AreEqual(expectedResult.Shell.Coordinates[i], actualResult.Shell.Coordinates[i]); } Assert.AreEqual(expectedHoleCoordinates.Count, actualResult.HoleCount); for (Int32 i = 0; i < expectedHoleCoordinates.Count; i++) { for (Int32 j = 0; j < expectedHoleCoordinates[i].Count; j++) { Assert.AreEqual(expectedHoleCoordinates[i][j], actualResult.Holes[i].Coordinates[j]); } } // ArgumentNullException: null source Assert.Throws <ArgumentNullException>(() => MinkowskiSumAlgorithm.Buffer((IBasicPolygon)null, buffer)); // ArgumentNullException: null buffer polygon Assert.Throws <ArgumentNullException>(() => MinkowskiSumAlgorithm.Buffer(source, null)); // ArgumentException: source polygon with clockwise orientation sourceShellCoordinates = new List <Coordinate> { new Coordinate(1, 1), new Coordinate(1, 9), new Coordinate(9, 9), new Coordinate(9, 1), new Coordinate(1, 1) }; source = new BasicPolygon(sourceShellCoordinates); Assert.Throws <ArgumentException>(() => MinkowskiSumAlgorithm.Buffer(source, buffer)); }
/// <summary> /// Computes the buffer of the source geometry. /// </summary> /// <param name="source">The source.</param> /// <param name="radius">The radius of the circle.</param> /// <param name="numberOfPoints">The number of points.</param> /// <returns>The result polygon.</returns> public static IBasicPolygon Buffer(IBasicPoint source, Double radius, Int32 numberOfPoints) { return(new MinkowskiSumAlgorithm(source, new BasicPolygon(CreateCircle(radius, numberOfPoints))).Result); }
/// <summary> /// Computes the buffer of the source geometry. /// </summary> /// <param name="source">The source.</param> /// <param name="buffer">The buffer.</param> /// <returns>The result polygon.</returns> public static IBasicPolygon Buffer(IBasicPoint source, IBasicPolygon buffer) { return(new MinkowskiSumAlgorithm(source, buffer).Result); }
/// <summary> /// Computes the distance between the specified geometries. /// </summary> /// <param name="lineString">The line string.</param> /// <param name="point">The point.</param> /// <returns>The distance between the specified geometries.</returns> /// <exception cref="System.ArgumentNullException"> /// The line string is null. /// or /// The point is null. /// </exception> public static Double Distance(IBasicLineString lineString, IBasicPoint point) { return(Distance(point, lineString, null)); }
/// <summary> /// Computes the distance between the specified geometries. /// </summary> /// <param name="lineString">The line string.</param> /// <param name="point">The point.</param> /// <param name="precisionModel">The precision model.</param> /// <returns>The distance between the specified geometries.</returns> /// <exception cref="System.ArgumentNullException"> /// The line string is null. /// or /// The point is null. /// </exception> public static Double Distance(IBasicLineString lineString, IBasicPoint point, PrecisionModel precisionModel) { return(Distance(point, lineString, precisionModel)); }
/// <summary> /// Buffers he specified source. /// </summary> /// <param name="source">The source.</param> /// <param name="radius">The radius of the buffer.</param> /// <returns>The buffered polygon.</returns> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public static IBasicPolygon Buffer(IBasicPoint source, Double radius) { return(new MinkowskiSumAlgorithm(source, CreateCircle(radius, NumberOfPoints), null).Result); }
/// <summary> /// Computes the distance between the specified geometries. /// </summary> /// <param name="polygon">The polygon.</param> /// <param name="point">The point.</param> /// <param name="precisionModel">The precision model.</param> /// <returns>The distance between the specified geometries.</returns> /// <exception cref="System.ArgumentNullException"> /// The polygon is null. /// or /// The point is null. /// </exception> public static Double Distance(IBasicPolygon polygon, IBasicPoint point, PrecisionModel precisionModel) { return(Distance(point, polygon, precisionModel)); }
/// <summary> /// Computes the distance between the specified geometries. /// </summary> /// <param name="polygon">The polygon.</param> /// <param name="point">The point.</param> /// <returns>The distance between the specified geometries.</returns> /// <exception cref="System.ArgumentNullException"> /// The polygon is null. /// or /// The point is null. /// </exception> public static Double Distance(IBasicPolygon polygon, IBasicPoint point) { return(Distance(point, polygon, null)); }