public virtual void TestGeoRectangle(SpatialContext ctx) { base.ctx = ctx; double v = 200 * (random.NextDouble() > 0.5 ? -1 : 1); Assert.Throws <InvalidShapeException>(() => ctx.MakeRectangle(v, 0, 0, 0)); Assert.Throws <InvalidShapeException>(() => ctx.MakeRectangle(0, v, 0, 0)); Assert.Throws <InvalidShapeException>(() => ctx.MakeRectangle(0, 0, v, 0)); Assert.Throws <InvalidShapeException>(() => ctx.MakeRectangle(0, 0, 0, v)); Assert.Throws <InvalidShapeException>(() => ctx.MakeRectangle(0, 0, 10, -10)); //test some relateXRange // opposite +/- 180 Assert.Equal(SpatialRelation.INTERSECTS, ctx.MakeRectangle(170, 180, 0, 0).RelateXRange(-180, -170)); Assert.Equal(SpatialRelation.INTERSECTS, ctx.MakeRectangle(-90, -45, 0, 0).RelateXRange(-45, -135)); Assert.Equal(SpatialRelation.CONTAINS, ctx.WorldBounds.RelateXRange(-90, -135)); //point on edge at dateline using opposite +/- 180 Assert.Equal(SpatialRelation.CONTAINS, ctx.MakeRectangle(170, 180, 0, 0).Relate(ctx.MakePoint(-180, 0))); //test 180 becomes -180 for non-zero width rectangle Assert.Equal(ctx.MakeRectangle(-180, -170, 0, 0), ctx.MakeRectangle(180, -170, 0, 0)); Assert.Equal(ctx.MakeRectangle(170, 180, 0, 0), ctx.MakeRectangle(170, -180, 0, 0)); double[] lons = new double[] { 0, 45, 160, 180, -45, -175, -180 }; //minX foreach (double lon in lons) { double[] lonWs = new double[] { 0, 20, 180, 200, 355, 360 }; //width foreach (double lonW in lonWs) { if (lonW == 360 && lon != -180) { continue; } TestRectangle(lon, lonW, 0, 0); TestRectangle(lon, lonW, -10, 10); TestRectangle(lon, lonW, 80, 10); //polar cap TestRectangle(lon, lonW, -90, 180); //full lat range } } TestShapes2D.TestCircleReset(ctx); //Test geo rectangle intersections TestRectIntersect(); //Test buffer AssertEquals(ctx.MakeRectangle(-10, 10, -10, 10), ctx.MakeRectangle(0, 0, 0, 0).GetBuffered(10, ctx)); for (int i = 0; i < AtLeast(100); i++) { IRectangle r = RandomRectangle(1); int buf = random.Next(0, 90 + 1); IRectangle br = (IRectangle)r.GetBuffered(buf, ctx); AssertRelation(null, SpatialRelation.CONTAINS, br, r); if (r.Width + 2 * buf >= 360) { CustomAssert.EqualWithDelta(360, br.Width, 0.0); } else { Assert.True(br.Width - r.Width >= 2 * buf); } //TODO test more thoroughly; we don't check that we over-buf } Assert.True(ctx.MakeRectangle(0, 10, 0, 89).GetBuffered(0.5, ctx).BoundingBox.Width > 11); }