Exemple #1
0
        public void Test_S2Cap_GetCentroid()
        {
            // Empty and full caps.
            Assert.Equal(new S2Point(), S2Cap.Empty.Centroid());
            Assert.True(S2Cap.Full.Centroid().Norm() <= S2.DoubleError);

            // Random caps.
            for (int i = 0; i < 100; ++i)
            {
                S2Point center   = S2Testing.RandomPoint();
                double  height   = S2Testing.Random.UniformDouble(0.0, 2.0);
                S2Cap   cap      = S2Cap.FromCenterHeight(center, height);
                S2Point centroid = cap.Centroid();
                S2Point expected = center * (1.0 - height / 2.0) * cap.Area();
                Assert.True((expected - centroid).Norm() <= S2.DoubleError);
            }
        }