Example #1
0
        public virtual void TestArea()
        {
            double radius = DistanceUtils.EARTH_MEAN_RADIUS_KM * DistanceUtils.KM_TO_DEG;
            //surface of a sphere is 4 * pi * r^2
            double earthArea = 4 * Math.PI * radius * radius;

            ICircle c = ctx.MakeCircle(random.Next(-180, 180), random.Next(-90, 90),
                                       180); //180 means whole earth

            CustomAssert.EqualWithDelta(earthArea, c.GetArea(ctx), 1.0);

            CustomAssert.EqualWithDelta(earthArea, ctx.WorldBounds.GetArea(ctx), 1.0);

            //now check half earth
            ICircle cHalf = ctx.MakeCircle(c.Center, 90);

            CustomAssert.EqualWithDelta(earthArea / 2, cHalf.GetArea(ctx), 1.0);

            //circle with same radius at +20 lat with one at -20 lat should have same area as well as bbox with same area
            ICircle c2 = ctx.MakeCircle(c.Center, 30);
            ICircle c3 = ctx.MakeCircle(c.Center.X, 20, 30);

            CustomAssert.EqualWithDelta(c2.GetArea(ctx), c3.GetArea(ctx), 0.01);
            ICircle c3Opposite = ctx.MakeCircle(c.Center.X, -20, 30);

            CustomAssert.EqualWithDelta(c3.GetArea(ctx), c3Opposite.GetArea(ctx), 0.01);
            CustomAssert.EqualWithDelta(c3.BoundingBox.GetArea(ctx), c3Opposite.BoundingBox.GetArea(ctx), 0.01);

            //small shapes near the equator should have similar areas to euclidean rectangle
            IRectangle smallRect = ctx.MakeRectangle(0, 1, 0, 1);

            CustomAssert.EqualWithDelta(1.0, smallRect.GetArea(null), 0.0);
            double smallDelta = smallRect.GetArea(null) - smallRect.GetArea(ctx);

            Assert.True(smallDelta > 0 && smallDelta < 0.0001);

            ICircle smallCircle = ctx.MakeCircle(0, 0, 1);

            smallDelta = smallCircle.GetArea(null) - smallCircle.GetArea(ctx);
            Assert.True(smallDelta > 0 && smallDelta < 0.0001);

            //bigger, but still fairly similar
            //c2 = ctx.makeCircle(c.getCenter(), 30);
            double areaRatio = c2.GetArea(null) / c2.GetArea(ctx);

            Assert.True(areaRatio > 1 && areaRatio < 1.1);
        }
Example #2
0
 public override double Area(ICircle circle)
 {
     return(circle.GetArea(null));
 }