Пример #1
0
        public void Test_S2Cap_GetRectBound()
        {
            // Empty and full caps.
            Assert.True(S2Cap.Empty.GetRectBound().IsEmpty());
            Assert.True(S2Cap.Full.GetRectBound().IsFull());

            // Maximum allowable error for latitudes and longitudes measured in
            // degrees.  (Assert2.Near isn't sufficient.)

            // Cap that includes the south pole.
            S2LatLngRect rect = new S2Cap(GetLatLngPoint(-45, 57),
                                          S1Angle.FromDegrees(50)).GetRectBound();

            Assert2.Near(rect.LatLo().GetDegrees(), -90, kDegreeEps);
            Assert2.Near(rect.LatHi().GetDegrees(), 5, kDegreeEps);
            Assert.True(rect.Lng.IsFull());

            // Cap that is tangent to the north pole.
            rect = new S2Cap(new S2Point(1, 0, 1).Normalize(),
                             S1Angle.FromRadians(S2.M_PI_4 + 1e-16)).GetRectBound();
            Assert2.Near(rect.Lat.Lo, 0, kEps);
            Assert2.Near(rect.Lat.Hi, S2.M_PI_2, kEps);
            Assert.True(rect.Lng.IsFull());

            var p   = new S2Point(1, 0, 1).Normalize();
            var rb1 = S1Angle.FromDegrees(45 + 5e-15);

            rect = new S2Cap(p, rb1).GetRectBound();
            Assert2.Near(rect.LatLo().GetDegrees(), 0, kDegreeEps);
            Assert2.Near(rect.LatHi().GetDegrees(), 90, kDegreeEps);
            Assert.True(rect.Lng.IsFull());

            // The eastern hemisphere.
            var rb2 = S1Angle.FromRadians(S2.M_PI_2 + 2e-16);

            rect = new S2Cap(new S2Point(0, 1, 0), rb2).GetRectBound();
            Assert2.Near(rect.LatLo().GetDegrees(), -90, kDegreeEps);
            Assert2.Near(rect.LatHi().GetDegrees(), 90, kDegreeEps);
            Assert.True(rect.Lng.IsFull());

            // A cap centered on the equator.
            rect = new S2Cap(GetLatLngPoint(0, 50), S1Angle.FromDegrees(20)).GetRectBound();
            Assert2.Near(rect.LatLo().GetDegrees(), -20, kDegreeEps);
            Assert2.Near(rect.LatHi().GetDegrees(), 20, kDegreeEps);
            Assert2.Near(rect.LngLo().GetDegrees(), 30, kDegreeEps);
            Assert2.Near(rect.LngHi().GetDegrees(), 70, kDegreeEps);

            // A cap centered on the north pole.
            rect = new S2Cap(GetLatLngPoint(90, 123), S1Angle.FromDegrees(10)).GetRectBound();
            Assert2.Near(rect.LatLo().GetDegrees(), 80, kDegreeEps);
            Assert2.Near(rect.LatHi().GetDegrees(), 90, kDegreeEps);
            Assert.True(rect.Lng.IsFull());
        }