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)); } }
public void Test_FaceXYZtoUVW() { for (int face = 0; face < 6; ++face) { Assert.Equal(new S2Point(0, 0, 0), S2.FaceXYZtoUVW(face, S2Point.Empty)); Assert.Equal(new S2Point(1, 0, 0), S2.FaceXYZtoUVW(face, S2.GetUAxis(face))); Assert.Equal(new S2Point(-1, 0, 0), S2.FaceXYZtoUVW(face, -S2.GetUAxis(face))); Assert.Equal(new S2Point(0, 1, 0), S2.FaceXYZtoUVW(face, S2.GetVAxis(face))); Assert.Equal(new S2Point(0, -1, 0), S2.FaceXYZtoUVW(face, -S2.GetVAxis(face))); Assert.Equal(new S2Point(0, 0, 1), S2.FaceXYZtoUVW(face, S2.GetNorm(face))); Assert.Equal(new S2Point(0, 0, -1), S2.FaceXYZtoUVW(face, -S2.GetNorm(face))); } }
public void Test_UVWAxis() { for (int face = 0; face < 6; ++face) { // Check that axes are consistent with FaceUVtoXYZ. Assert.Equal(S2.FaceUVtoXYZ(face, 1, 0) - S2.FaceUVtoXYZ(face, 0, 0), S2.GetUAxis(face)); Assert.Equal(S2.FaceUVtoXYZ(face, 0, 1) - S2.FaceUVtoXYZ(face, 0, 0), S2.GetVAxis(face)); Assert.Equal(S2.FaceUVtoXYZ(face, 0, 0), S2.GetNorm(face)); // Check that every face coordinate frame is right-handed. Assert.Equal(1, S2.GetUAxis(face).CrossProd(S2.GetVAxis(face)) .DotProd(S2.GetNorm(face))); // Check that GetUVWAxis is consistent with GetUAxis, GetVAxis, GetNorm. Assert.Equal(S2.GetUAxis(face), S2.GetUVWAxis(face, 0)); Assert.Equal(S2.GetVAxis(face), S2.GetUVWAxis(face, 1)); Assert.Equal(S2.GetNorm(face), S2.GetUVWAxis(face, 2)); } }