Exemplo n.º 1
0
        protected virtual void TestRectangle(double minX, double width, double minY, double height)
        {
            double maxX = minX + width;
            double maxY = minY + height;

            minX = NormX(minX);
            maxX = NormX(maxX);

            IRectangle r = ctx.MakeRectangle(minX, maxX, minY, maxY);

            //test equals & hashcode of duplicate
            IRectangle r2 = ctx.MakeRectangle(minX, maxX, minY, maxY);

            Assert.Equal(r, r2);
            Assert.Equal(r.GetHashCode(), r2.GetHashCode());

            string msg = r.ToString();

            Assert.Equal(/*msg,*/ width != 0 && height != 0, r.HasArea);
            Assert.Equal(/*msg,*/ width != 0 && height != 0, r.GetArea(ctx) > 0);
            if (ctx.IsGeo && r.Width == 360 && r.Height == 180)
            {
                //whole globe
                double earthRadius = DistanceUtils.ToDegrees(1);
                CustomAssert.EqualWithDelta(4 * Math.PI * earthRadius * earthRadius, r.GetArea(ctx), 1.0);//1km err
            }

            AssertEqualsRatio(msg, height, r.Height);
            AssertEqualsRatio(msg, width, r.Width);
            IPoint center = r.Center;

            msg += " ctr:" + center;
            //System.out.println(msg);
            AssertRelation(msg, SpatialRelation.CONTAINS, r, center);

            IDistanceCalculator dc = ctx.DistCalc;
            double dUR             = dc.Distance(center, r.MaxX, r.MaxY);
            double dLR             = dc.Distance(center, r.MaxX, r.MinY);
            double dUL             = dc.Distance(center, r.MinX, r.MaxY);
            double dLL             = dc.Distance(center, r.MinX, r.MinY);

            Assert.Equal(/*msg,*/ width != 0 || height != 0, dUR != 0);
            if (dUR != 0)
            {
                Assert.True(dUR > 0 && dLL > 0);
            }
            AssertEqualsRatio(msg, dUR, dUL);
            AssertEqualsRatio(msg, dLR, dLL);
            if (!ctx.IsGeo || center.Y == 0)
            {
                AssertEqualsRatio(msg, dUR, dLL);
            }
        }