/// <summary> /// Determines whether a <see cref="IGeometry" /> instance spatially overlaps another <see cref="IGeometry" />. /// </summary> /// <param name="geometry">The geometry.</param> /// <param name="otherGeometry">The other geometry.</param> /// <returns><c>true</c> if the geometry spatially overlaps the other geometry; otherwise, <c>false</c>.</returns> /// <exception cref="System.ArgumentNullException"> /// The geometry is null. /// or /// The other geometry is null. /// </exception> /// <exception cref="System.ArgumentException">The operation is not supported with the specified geometry types.</exception> public static Boolean Overlaps(this IGeometry geometry, IGeometry otherGeometry) { if (geometry == null) { throw new ArgumentNullException("geometry", "The geometry is null."); } if (otherGeometry == null) { throw new ArgumentNullException("otherGeometry", "The other geometry is null."); } using (IGeometryRelateOperator op = GetRelateOperator(geometry)) { return(op.Overlaps(geometry, otherGeometry)); } }
public void HalfedgeGeometryRelateTest() { IMultiPolygon first = _factory.CreateMultiPolygon(new[] { _factory.CreatePolygon( _factory.CreatePoint(0, 0), _factory.CreatePoint(10, 0), _factory.CreatePoint(10, 10), _factory.CreatePoint(0, 10)), _factory.CreatePolygon( _factory.CreatePoint(10, 0), _factory.CreatePoint(20, 0), _factory.CreatePoint(20, 10), _factory.CreatePoint(10, 10)), _factory.CreatePolygon( _factory.CreatePoint(0, 10), _factory.CreatePoint(10, 10), _factory.CreatePoint(10, 20), _factory.CreatePoint(0, 20)), }); IMultiPolygon second = _factory.CreateMultiPolygon(new[] { _factory.CreatePolygon( _factory.CreatePoint(-5, -5), _factory.CreatePoint(5, -5), _factory.CreatePoint(5, 5), _factory.CreatePoint(-5, 5)), _factory.CreatePolygon( _factory.CreatePoint(5, -5), _factory.CreatePoint(15, -5), _factory.CreatePoint(15, 5), _factory.CreatePoint(5, 5)), _factory.CreatePolygon( _factory.CreatePoint(-5, -15), _factory.CreatePoint(5, -15), _factory.CreatePoint(5, -5), _factory.CreatePoint(-5, -5)), }); IPolygon third = _factory.CreatePolygon( _factory.CreatePoint(3, 5), _factory.CreatePoint(7, 5), _factory.CreatePoint(7, 15), _factory.CreatePoint(3, 15)); Assert.IsFalse(_operator.Contains(first, first)); // equals is not contains Assert.IsFalse(_operator.Contains(first, second)); Assert.IsTrue(_operator.Contains(first, third)); Assert.IsFalse(_operator.Contains(second, third)); Assert.IsFalse(_operator.Within(first, first)); Assert.IsFalse(_operator.Within(first, second)); Assert.IsFalse(_operator.Within(first, third)); Assert.IsFalse(_operator.Within(second, third)); Assert.IsTrue(_operator.Intersects(first, first)); Assert.IsTrue(_operator.Intersects(first, second)); Assert.IsTrue(_operator.Intersects(first, third)); Assert.IsTrue(_operator.Intersects(second, third)); Assert.IsFalse(_operator.Disjoint(first, first)); Assert.IsFalse(_operator.Disjoint(first, second)); Assert.IsFalse(_operator.Disjoint(first, third)); Assert.IsFalse(_operator.Disjoint(second, third)); // for operands with the same dimension crosses is always false Assert.IsFalse(_operator.Crosses(first, first)); Assert.IsFalse(_operator.Crosses(first, second)); Assert.IsFalse(_operator.Crosses(first, third)); Assert.IsFalse(_operator.Crosses(second, third)); Assert.IsTrue(_operator.Equals(first, first)); Assert.IsFalse(_operator.Equals(first, second)); Assert.IsFalse(_operator.Equals(first, third)); Assert.IsFalse(_operator.Equals(second, third)); Assert.IsFalse(_operator.Touches(first, first)); Assert.IsFalse(_operator.Touches(first, second)); Assert.IsFalse(_operator.Touches(first, third)); Assert.IsTrue(_operator.Touches(second, third)); Assert.IsFalse(_operator.Overlaps(first, first)); Assert.IsTrue(_operator.Overlaps(first, second)); Assert.IsFalse(_operator.Overlaps(first, third)); // contains is not overlaps Assert.IsFalse(_operator.Overlaps(second, third)); // the result has not the same dimension }