Ejemplo n.º 1
0
        public void Test_S2Cap_Union()
        {
            // Two caps which have the same center but one has a larger radius.
            S2Cap a = new(GetLatLngPoint(50.0, 10.0), S1Angle.FromDegrees(0.2));
            S2Cap b = new(GetLatLngPoint(50.0, 10.0), S1Angle.FromDegrees(0.3));

            Assert.True(b.Contains(a));
            Assert.Equal(b, a.Union(b));

            // Two caps where one is the full cap.
            Assert.True(a.Union(S2Cap.Full).IsFull());

            // Two caps where one is the empty cap.
            Assert.Equal(a, a.Union(S2Cap.Empty));

            // Two caps which have different centers, one entirely encompasses the other.
            S2Cap c = new(GetLatLngPoint(51.0, 11.0), S1Angle.FromDegrees(1.5));

            Assert.True(c.Contains(a));
            Assert.Equal(a.Union(c).Center, c.Center);
            Assert.Equal(a.Union(c).Radius, c.Radius);

            // Two entirely disjoint caps.
            S2Cap d = new(GetLatLngPoint(51.0, 11.0), S1Angle.FromDegrees(0.1));

            Assert.False(d.Contains(a));
            Assert.False(d.Intersects(a));
            Assert.True(a.Union(d).ApproxEquals(d.Union(a)));
            Assert2.Near(50.4588, new S2LatLng(a.Union(d).Center).Lat().GetDegrees(), 0.001);
            Assert2.Near(10.4525, new S2LatLng(a.Union(d).Center).Lng().GetDegrees(), 0.001);
            Assert2.Near(0.7425, a.Union(d).Radius.Degrees(), 0.001);

            // Two partially overlapping caps.
            S2Cap e = new(GetLatLngPoint(50.3, 10.3), S1Angle.FromDegrees(0.2));

            Assert.False(e.Contains(a));
            Assert.True(e.Intersects(a));
            Assert.True(a.Union(e).ApproxEquals(e.Union(a)));
            Assert2.Near(50.1500, new S2LatLng(a.Union(e).Center).Lat().GetDegrees(), 0.001);
            Assert2.Near(10.1495, new S2LatLng(a.Union(e).Center).Lng().GetDegrees(), 0.001);
            Assert2.Near(0.3781, a.Union(e).Radius.Degrees(), 0.001);

            // Two very large caps, whose radius sums to in excess of 180 degrees, and
            // whose centers are not antipodal.
            S2Cap f = new(new S2Point(0, 0, 1).Normalize(), S1Angle.FromDegrees(150));
            S2Cap g = new(new S2Point(0, 1, 0).Normalize(), S1Angle.FromDegrees(150));

            Assert.True(f.Union(g).IsFull());

            // Two non-overlapping hemisphere caps with antipodal centers.
            S2Cap hemi = S2Cap.FromCenterHeight(new S2Point(0, 0, 1).Normalize(), 1);

            Assert.True(hemi.Union(hemi.Complement()).IsFull());
        }