Esempio n. 1
0
def test_almost_globe():
    globe1 = BoundingBox(north=90, west=1, east=360, south=-90)

    globe2 = BoundingBox(north=90, west=-180, east=179, south=-90)

    assert globe1.merge(globe2).width == 360, globe1.merge(globe2).width
    assert globe2.merge(globe1).width == 360, globe2.merge(globe1).width
    print(globe1.merge(globe2))
Esempio n. 2
0
def test_bbox():

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i, south=30, east=10 + i)
        assert bbox.width == 10, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i, south=30, east=350 + i)
        assert bbox.width == 350, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i, south=30, east=(10 + i) % 360)
        assert bbox.width == 10, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i, south=30, east=(350 + i) % 360)
        assert bbox.width == 350, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i % 360, south=30, east=10 + i)
        assert bbox.width == 10, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i % 360, south=30, east=350 + i)
        assert bbox.width == 350, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90,
                           west=i % 360,
                           south=30,
                           east=(10 + i) % 360)
        assert bbox.width == 10, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90,
                           west=i % 360,
                           south=30,
                           east=(350 + i) % 360)
        assert bbox.width == 350, bbox

    for i in range(-365, 365):
        bbox1 = BoundingBox(north=90, west=150 + i, south=30, east=170 + i)
        bbox2 = BoundingBox(north=90, west=-170 + i, south=30, east=-150 + i)
        bbox = bbox1.merge(bbox2)
        assert bbox.width == 60, (bbox1, bbox2, bbox)

        bbox = bbox2.merge(bbox1)
        assert bbox.width == 60, (bbox1, bbox2, bbox)

    with pytest.raises(ValueError):
        BoundingBox(north=-10, west=0, south=30, east=1)

    with pytest.raises(ValueError):
        BoundingBox(north=90, west=1, south=30, east=1)
Esempio n. 3
0
def test_globe():
    globe1 = BoundingBox(north=90, west=0, east=360, south=-90)
    assert globe1.width == 360
    assert globe1.west == 0

    globe2 = BoundingBox(north=90, west=-180, east=180, south=-90)
    assert globe2.width == 360
    assert globe2.west == -180

    assert globe1.merge(globe2).width == 360, globe1.merge(globe2).width
    assert globe2.merge(globe1).width == 360, globe2.merge(globe1).width

    # assert globe1.merge(globe2) == globe1,globe1.merge(globe2)
    # assert globe2.merge(globe1) == globe2, globe2.merge(globe1)

    b1 = BoundingBox(north=90, west=-180, east=0, south=-90)
    b2 = BoundingBox(north=90, west=0, east=180, south=-90)
    b0 = b1.merge(b2)
    assert b0.width == 360
Esempio n. 4
0
def test_overlapping_bbox_2():

    b1 = BoundingBox(north=90, west=-200, south=-90, east=-130)
    b2 = BoundingBox(north=90, west=-180, south=-90, east=-90)
    b0 = b1.merge(b2)

    assert b0.width == 110, b0.width

    b3 = BoundingBox(north=90, west=-210, south=-90, east=-160)
    b0 = b0.merge(b3)
    assert b0.width == 120, b0.width

    #      ----------------------
    #           ---------------------
    # ---------------------

    for i in range(-365, 365):
        b1 = BoundingBox(north=90, west=10 + i, south=-90, east=80 + i)
        b2 = BoundingBox(north=90, west=30 + i, south=-90, east=120 + i)
        b3 = BoundingBox(north=90, west=0 + i, south=-90, east=50 + i)
        b0 = BoundingBox.multi_merge([b1, b2, b3])
        assert b0.width == 120, (b0.width, b0)

    # --------------------------------
    #           ---------------------
    #     ---------------------

    for i in range(-365, 365):
        b1 = BoundingBox(north=90, west=-10 + i, south=-90, east=200 + i)
        b2 = BoundingBox(north=90, west=30 + i, south=-90, east=120 + i)
        b3 = BoundingBox(north=90, west=0 + i, south=-90, east=50 + i)

        b0 = BoundingBox.multi_merge([b1, b2, b3])
        assert b0.width == 210, (b0.width, b0)

    # --------------------------------
    #           --------------------------
    #     ---------------------

    for i in range(-365, 365):
        b1 = BoundingBox(north=90, west=-10 + i, south=-90, east=200 + i)
        b2 = BoundingBox(north=90, west=30 + i, south=-90, east=300 + i)
        b3 = BoundingBox(north=90, west=0 + i, south=-90, east=50 + i)

        b0 = BoundingBox.multi_merge([b1, b2, b3])

        assert b0.width == 310, (b0.width, b0)
Esempio n. 5
0
def test_overlapping_bbox_3():

    for i in range(361):

        b1 = BoundingBox(north=90, west=-45 - i, south=-90, east=45 - i)
        b2 = BoundingBox(north=90, west=-45 + i, south=-90, east=45 + i)
        b0 = b1.merge(b2)

        if i <= 90:
            assert b0.width == 90 + 2 * i, (i, b0.width, b0)

        if i > 90 and i <= 180:
            assert b0.width == 3 * 90 - 2 * (i - 90), (i, b0.width, b0)

        if i > 180 and i <= 270:
            assert b0.width == 90 + 2 * (i - 180), (i, b0.width, b0)

        if i > 270:
            assert b0.width == 3 * 90 - 2 * (i - 270), (i, b0.width, b0)
Esempio n. 6
0
def test_bbox():

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i, south=30, east=10 + i)
        assert bbox.width == 10, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i, south=30, east=350 + i)
        assert bbox.width == 350, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i, south=30, east=(10 + i) % 360)
        assert bbox.width == 10, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i, south=30, east=(350 + i) % 360)
        assert bbox.width == 350, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i % 360, south=30, east=10 + i)
        assert bbox.width == 10, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90, west=i % 360, south=30, east=350 + i)
        assert bbox.width == 350, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90,
                           west=i % 360,
                           south=30,
                           east=(10 + i) % 360)
        assert bbox.width == 10, bbox

    for i in range(-365, 365):
        bbox = BoundingBox(north=90,
                           west=i % 360,
                           south=30,
                           east=(350 + i) % 360)
        assert bbox.width == 350, bbox

    for i in range(-365, 365):
        bbox1 = BoundingBox(north=90, west=150 + i, south=30, east=170 + i)
        bbox2 = BoundingBox(north=90, west=-170 + i, south=30, east=-150 + i)

        bbox = bbox1.merge(bbox2)
        assert bbox.width == 60, (bbox1, bbox2, bbox, bbox.width)

        bbox = bbox2.merge(bbox1)
        assert bbox.width == 60, (bbox1, bbox2, bbox, bbox.width)

        merge1 = bbox1.merge(bbox2)
        merge2 = bbox2.merge(bbox1)
        assert merge1 == merge2, (bbox1, bbox2, merge1, merge2)

    with pytest.raises(ValueError):
        BoundingBox(north=-10, west=0, south=30, east=1)

    b0 = BoundingBox(north=89.9746,
                     west=-179.975,
                     south=-89.9746,
                     east=179.975)
    b1 = BoundingBox(north=89.9746,
                     west=-179.975,
                     south=-89.9746,
                     east=179.975)
    b2 = BoundingBox(north=89.9746,
                     west=-179.975,
                     south=-89.9746,
                     east=179.975)
    b3 = b1.merge(b2)

    assert b0 == b3