Esempio n. 1
0
        public void testFaceUVtoXYZ()
        {
            // Check that each face appears exactly once.
            var sum = new S2Point();

            for (var face = 0; face < 6; ++face)
            {
                var center = S2Projections.FaceUvToXyz(face, 0, 0);
                assertEquals(S2Projections.GetNorm(face), center);
                assertEquals(Math.Abs(center[center.LargestAbsComponent]), 1.0);
                sum = sum + S2Point.Fabs(center);
            }
            assertEquals(sum, new S2Point(2, 2, 2));

            // Check that each face has a right-handed coordinate system.
            for (var face = 0; face < 6; ++face)
            {
                assertEquals(
                    S2Point.CrossProd(S2Projections.GetUAxis(face), S2Projections.GetVAxis(face)).DotProd(
                        S2Projections.FaceUvToXyz(face, 0, 0)), 1.0);
            }

            // Check that the Hilbert curves on each face combine to form a
            // continuous curve over the entire cube.
            for (var face = 0; face < 6; ++face)
            {
                // The Hilbert curve on each face starts at (-1,-1) and terminates
                // at either (1,-1) (if axes not swapped) or (-1,1) (if swapped).
                var sign = ((face & S2.SwapMask) != 0) ? -1 : 1;
                assertEquals(S2Projections.FaceUvToXyz(face, sign, -sign),
                             S2Projections.FaceUvToXyz((face + 1) % 6, -1, -1));
            }
        }
Esempio n. 2
0
        public void Test_FaceUVtoXYZ()
        {
            // Check that each face appears exactly once.
            S2Point sum = S2Point.Empty;

            for (int face = 0; face < 6; ++face)
            {
                S2Point center = S2.FaceUVtoXYZ(face, 0, 0);
                Assert.Equal(S2.GetNorm(face), center);
                Assert.Equal(1, Math.Abs(center[center.LargestAbsComponent()]));
                sum += center.Fabs();
            }
            Assert.Equal(sum, new S2Point(2, 2, 2));

            // Check that each face has a right-handed coordinate system.
            for (int face = 0; face < 6; ++face)
            {
                Assert.Equal(1, S2.GetUAxis(face).CrossProd(S2.GetVAxis(face))
                             .DotProd(S2.FaceUVtoXYZ(face, 0, 0)));
            }

            // Check that the Hilbert curves on each face combine to form a
            // continuous curve over the entire cube.
            for (int face = 0; face < 6; ++face)
            {
                // The Hilbert curve on each face starts at (-1,-1) and terminates
                // at either (1,-1) (if axes not swapped) or (-1,1) (if swapped).
                int sign = ((face & S2.kSwapMask) != 0) ? -1 : 1;
                Assert.Equal(S2.FaceUVtoXYZ(face, sign, -sign),
                             S2.FaceUVtoXYZ((face + 1) % 6, -1, -1));
            }
        }