Ejemplo n.º 1
0
def test_resize(width, height, left, top, right, bottom):
    # sort the percents
    top, bottom = sorted([top, bottom])
    left, right = sorted([left, right])

    left = get_percent(width, left)
    right = get_percent(width, right)
    top = get_percent(height, top)
    bottom = get_percent(height, bottom)

    # ignore 0 sized crops
    if left == right or top == bottom:
        return


    # identity proprety
    box = model.new_box(width, height, 0, 0, width, height)
    id_box = model.resize(box, width, height)
    assert id_box == box

    # identity property with a crop
    box = model.new_box(width, height, left, top, right, bottom)
    box_size = size(box)
    id_box = model.resize(box, box_size.width, box_size.height)
    assert id_box == box

    # inverse property
    box = model.new_box(width, height, left, top, right, bottom)
    box2 = model.resize(box, half(width), half(height))
    box2_size = size(box2)
    box2 = model.resize(box2,
                        double(box2_size.width),
                        double(box2_size.height),
    )
Ejemplo n.º 2
0
def test_resize_crop(w,h,w1,h1,lp,tp,rp,bp):
    l = choose(lp, 1, w1)
    t = choose(tp, 1, h1)
    r = choose(rp, l, w1)
    b = choose(bp, t, h1)
    l,r = sorted([l,r])
    t,b = sorted([t,b])

    # ignore 0 sized crops
    if l == r or t == b:
        return

    
    box = model.crop(
        model.resize(
            model.box(w, h),
            w1, h1
        ),
        l,t,r,b,
    )

    def resize_cb(i, w, h):
        return tresize(w,h,i)

    def crop_cb(i, l,t,r,b):
        return tcrop((l,t,r,b),i)

    f = model.make_transformer(box, resize_cb, crop_cb)
    x = f(tmodel(w,h))

    m = tcrop(
        (l,t,r,b),
        tresize(
            w1, h1,
            tmodel(w,h)
       )
    )

    compare(m,x)