Example #1
0
def test_rotate_identity():
    g = Grid(
        np.arange(27).reshape((1, 3, 3, 3)), np.array([0, 0, 0]),
        np.array([1, 1, 1]))
    before = g.grid.copy()
    g.move(np.eye(3), np.array([0, 0, 0]))
    np.testing.assert_array_equal(before, g.grid)
Example #2
0
def test_translate():
    g = Grid(
        np.arange(27).reshape((1, 3, 3, 3)), np.array([0, 0, 0]),
        np.array([1, 1, 1]))
    before = g.grid.copy()
    g.move(np.eye(3), np.array([1, 1, 1]))

    manually_translated = np.zeros_like(g.grid)
    manually_translated[0, 1:, 1:, 1:] = before[0, :2, :2, :2]

    # compare rotated grids
    np.testing.assert_array_equal(manually_translated, g.grid)
Example #3
0
def test_rotate_180_around_Z():
    rot_mat = _get_rotation_matrix_around_Z(np.pi)
    g = Grid(
        np.arange(27).reshape((1, 3, 3, 3)), np.array([0, 0, 0]),
        np.array([1, 1, 1]))
    before = g.grid.copy()
    g.move(rot_mat, np.array([0, 0, 0]))

    # flip entries to match the rotated grid
    manually_rotated = np.zeros_like(g.grid)
    for k in range(g.grid.shape[3]):
        for _i, _j in product(range(3), range(3)):
            j, i = INDEX_MAP_180[_j][_i]
            manually_rotated[0, i, j, k] = before[0, _i, _j, k]

    # compare rotated grids
    np.testing.assert_array_equal(manually_rotated, g.grid)