예제 #1
0
def test_distance_field_2d():
    for dtype in TEST_TYPES:
        values = np.ones((5, 5), dtype=dtype)

        field = dijkstra3d.distance_field(values, (0, 0))

        assert np.all(field == np.array([[
            [0, 1, 2, 3, 4],
            [1, 1, 2, 3, 4],
            [2, 2, 2, 3, 4],
            [3, 3, 3, 3, 4],
            [4, 4, 4, 4, 4],
        ]]))

        field = dijkstra3d.distance_field(values, (4, 4))

        assert np.all(field == np.array([[
            [4, 4, 4, 4, 4],
            [4, 3, 3, 3, 3],
            [4, 3, 2, 2, 2],
            [4, 3, 2, 1, 1],
            [4, 3, 2, 1, 0],
        ]]))

        field = dijkstra3d.distance_field(values, (2, 2))

        assert np.all(field == np.array([[
            [2, 2, 2, 2, 2],
            [2, 1, 1, 1, 2],
            [2, 1, 0, 1, 2],
            [2, 1, 1, 1, 2],
            [2, 2, 2, 2, 2],
        ]]))

        field = dijkstra3d.distance_field(values * 2, (2, 2))

        assert np.all(field == np.array([[
            [4, 4, 4, 4, 4],
            [4, 2, 2, 2, 4],
            [4, 2, 0, 2, 4],
            [4, 2, 2, 2, 4],
            [4, 4, 4, 4, 4],
        ]]))
예제 #2
0
def test_distance_field_2d_symmetric_4(dtype):
    values = np.ones((5, 5), dtype=dtype)

    field = dijkstra3d.distance_field(values, (0, 0), connectivity=4)

    assert np.all(field == np.array([[
        [0, 1, 2, 3, 4],
        [1, 2, 3, 4, 5],
        [2, 3, 4, 5, 6],
        [3, 4, 5, 6, 7],
        [4, 5, 6, 7, 8],
    ]]))

    field = dijkstra3d.distance_field(values, (4, 4), connectivity=4)

    assert np.all(field == np.array([[
        [8, 7, 6, 5, 4],
        [7, 6, 5, 4, 3],
        [6, 5, 4, 3, 2],
        [5, 4, 3, 2, 1],
        [4, 3, 2, 1, 0],
    ]]))

    field = dijkstra3d.distance_field(values, (2, 2), connectivity=4)

    assert np.all(field == np.array([[
        [4, 3, 2, 3, 4],
        [3, 2, 1, 2, 3],
        [2, 1, 0, 1, 2],
        [3, 2, 1, 2, 3],
        [4, 3, 2, 3, 4],
    ]]))

    field = dijkstra3d.distance_field(values * 2, (2, 2), connectivity=4)

    assert np.all(field == np.array([[
        [8, 6, 4, 6, 8],
        [6, 4, 2, 4, 6],
        [4, 2, 0, 2, 4],
        [6, 4, 2, 4, 6],
        [8, 6, 4, 6, 8],
    ]]))
예제 #3
0
def test_distance_field_2d_asymmetric(dtype):
    values = np.ones((5, 10), dtype=dtype)

    assert np.all(field == np.array([[
        [0, 1, 2, 3, 4],
        [1, 1, 2, 3, 4],
        [2, 2, 2, 3, 4],
        [3, 3, 3, 3, 4],
        [4, 4, 4, 4, 4],
    ]]))

    field = dijkstra3d.distance_field(values, (4, 4))

    assert np.all(field == np.array([[
        [4, 4, 4, 4, 4],
        [4, 3, 3, 3, 3],
        [4, 3, 2, 2, 2],
        [4, 3, 2, 1, 1],
        [4, 3, 2, 1, 0],
    ]]))

    field = dijkstra3d.distance_field(values, (2, 2))

    assert np.all(field == np.array([[
        [2, 2, 2, 2, 2],
        [2, 1, 1, 1, 2],
        [2, 1, 0, 1, 2],
        [2, 1, 1, 1, 2],
        [2, 2, 2, 2, 2],
    ]]))

    field = dijkstra3d.distance_field(values * 2, (2, 2))

    assert np.all(field == np.array([[
        [4, 4, 4, 4, 4],
        [4, 2, 2, 2, 4],
        [4, 2, 0, 2, 4],
        [4, 2, 2, 2, 4],
        [4, 4, 4, 4, 4],
    ]]))
예제 #4
0
def test_distance_field_2d_asymmetric(dtype):
    values = np.ones((5, 10), dtype=dtype)

    answer = np.array([
        [1, 0, 1, 2, 3, 4, 5, 6, 7, 8],
        [1, 1, 1, 2, 3, 4, 5, 6, 7, 8],
        [2, 2, 2, 2, 3, 4, 5, 6, 7, 8],
        [3, 3, 3, 3, 3, 4, 5, 6, 7, 8],
        [4, 4, 4, 4, 4, 4, 5, 6, 7, 8],
    ],
                      dtype=np.float32)

    field = dijkstra3d.distance_field(values, (0, 1))
    assert np.all(field == answer)
예제 #5
0
def test_distance_field_2d(dtype):
    values = np.ones((5, 5), dtype=dtype)

    field = dijkstra3d.distance_field(values, (0, 0))

    assert np.all(field == np.array([[
        [0, 1, 2, 3, 4],
        [1, 1, 2, 3, 4],
        [2, 2, 2, 3, 4],
        [3, 3, 3, 3, 4],
        [4, 4, 4, 4, 4],
    ]]))

    field = dijkstra3d.distance_field(values, [(0, 0), (4, 4)])

    assert np.all(field == np.array([[
        [0, 1, 2, 3, 4],
        [1, 1, 2, 3, 3],
        [2, 2, 2, 2, 2],
        [3, 3, 2, 1, 1],
        [4, 3, 2, 1, 0],
    ]]))

    field = dijkstra3d.distance_field(values, [(0, 0), (2, 2), (4, 4)])

    assert np.all(field == np.array([[
        [0, 1, 2, 2, 2],
        [1, 1, 1, 1, 2],
        [2, 1, 0, 1, 2],
        [2, 1, 1, 1, 1],
        [2, 2, 2, 1, 0],
    ]]))

    field = dijkstra3d.distance_field(values, (4, 4))

    assert np.all(field == np.array([[
        [4, 4, 4, 4, 4],
        [4, 3, 3, 3, 3],
        [4, 3, 2, 2, 2],
        [4, 3, 2, 1, 1],
        [4, 3, 2, 1, 0],
    ]]))

    field = dijkstra3d.distance_field(values, (2, 2))

    assert np.all(field == np.array([[
        [2, 2, 2, 2, 2],
        [2, 1, 1, 1, 2],
        [2, 1, 0, 1, 2],
        [2, 1, 1, 1, 2],
        [2, 2, 2, 2, 2],
    ]]))

    field = dijkstra3d.distance_field(values * 2, (2, 2))

    assert np.all(field == np.array([[
        [4, 4, 4, 4, 4],
        [4, 2, 2, 2, 4],
        [4, 2, 0, 2, 4],
        [4, 2, 2, 2, 4],
        [4, 4, 4, 4, 4],
    ]]))

    field, max_loc = dijkstra3d.distance_field(values * 2, (2, 2),
                                               return_max_location=True)
    assert field[max_loc] == np.max(field)