Esempio n. 1
0
def test_scale_translate_pad():
    transform_a = ScaleTranslate(scale=[2, 3], translate=[8, -5])
    transform_b = ScaleTranslate(scale=[2, 1, 3], translate=[8, 0, -5])
    npt.assert_allclose(transform_a.set_pad([1]).scale, transform_b.scale)
    npt.assert_allclose(
        transform_a.set_pad([1]).translate, transform_b.translate
    )
Esempio n. 2
0
def test_scale_translate_slice():
    transform_a = ScaleTranslate(scale=[2, 3], translate=[8, -5])
    transform_b = ScaleTranslate(scale=[2, 1, 3], translate=[8, 3, -5])
    npt.assert_allclose(transform_b.set_slice([0, 2]).scale, transform_a.scale)
    npt.assert_allclose(
        transform_b.set_slice([0, 2]).translate, transform_a.translate
    )
Esempio n. 3
0
def test_scale_translate_compose():
    coord = [10, 13]
    transform_a = ScaleTranslate(scale=[2, 3], translate=[8, -5])
    transform_b = ScaleTranslate(scale=[0.3, 1.4], translate=[-2.2, 3])
    transform_c = transform_b.compose(transform_a)

    new_coord_1 = transform_c(coord)
    new_coord_2 = transform_b(transform_a(coord))
    npt.assert_allclose(new_coord_1, new_coord_2)
Esempio n. 4
0
def test_scale_translate_inverse():
    coord = [10, 13]
    transform = ScaleTranslate(scale=[2, 3], translate=[8, -5])
    new_coord = transform(coord)
    target_coord = [2 * 10 + 8, 3 * 13 - 5]
    npt.assert_allclose(new_coord, target_coord)

    inverted_new_coord = transform.inverse(new_coord)
    npt.assert_allclose(inverted_new_coord, coord)
Esempio n. 5
0
def test_transform_chain():
    coord = [10, 13]
    transform_a = ScaleTranslate(scale=[2, 3], translate=[8, -5])
    transform_b = ScaleTranslate(scale=[0.3, 1.4], translate=[-2.2, 3])
    transform_c = transform_b.compose(transform_a)

    transform_chain = TransformChain([transform_a, transform_b])

    new_coord_1 = transform_c(coord)
    new_coord_2 = transform_chain(coord)
    npt.assert_allclose(new_coord_1, new_coord_2)
Esempio n. 6
0
def test_transform_chain_inverse():
    coord = [10, 13]
    transform_a = ScaleTranslate(scale=[2, 3], translate=[8, -5])
    transform_b = ScaleTranslate(scale=[0.3, 1.4], translate=[-2.2, 3])

    transform_chain = TransformChain([transform_a, transform_b])
    transform_chain_inverse = transform_chain.inverse

    new_coord = transform_chain(coord)
    orig_coord = transform_chain_inverse(new_coord)
    npt.assert_allclose(coord, orig_coord)
Esempio n. 7
0
def test_transform_chain_expanded():
    coord = [10, 3, 13]
    transform_a = ScaleTranslate(scale=[2, 1, 3], translate=[8, 0, -5])
    transform_b = ScaleTranslate(scale=[0.3, 1, 1.4], translate=[-2.2, 0, 3])
    transform_c = ScaleTranslate(scale=[2, 3], translate=[8, -5])
    transform_d = ScaleTranslate(scale=[0.3, 1.4], translate=[-2.2, 3])

    transform_chain_a = TransformChain([transform_a, transform_b])
    transform_chain_b = TransformChain([transform_c, transform_d])
    transform_chain_expandded = transform_chain_b.expand_dims([1])

    new_coord_2 = transform_chain_a(coord)
    new_coord_1 = transform_chain_expandded(coord)
    npt.assert_allclose(new_coord_1, new_coord_2)
Esempio n. 8
0
def test_transform_chain_slice():
    coord = [10, 13]
    transform_a = ScaleTranslate(scale=[2, 3, 3], translate=[8, 2, -5])
    transform_b = ScaleTranslate(scale=[0.3, 1, 1.4], translate=[-2.2, 4, 3])
    transform_c = ScaleTranslate(scale=[2, 3], translate=[8, -5])
    transform_d = ScaleTranslate(scale=[0.3, 1.4], translate=[-2.2, 3])

    transform_chain_a = TransformChain([transform_a, transform_b])
    transform_chain_b = TransformChain([transform_c, transform_d])

    transform_chain_sliced = transform_chain_a.set_slice([0, 2])

    new_coord_1 = transform_chain_sliced(coord)
    new_coord_2 = transform_chain_b(coord)
    npt.assert_allclose(new_coord_1, new_coord_2)
Esempio n. 9
0
def test_scale_translate():
    coord = [10, 13]
    transform = ScaleTranslate(scale=[2, 3], translate=[8, -5], name='st')
    new_coord = transform(coord)
    target_coord = [2 * 10 + 8, 3 * 13 - 5]
    assert transform.name == 'st'
    npt.assert_allclose(new_coord, target_coord)
Esempio n. 10
0
def test_scale_translate_expand_dims():
    transform_a = ScaleTranslate(scale=[2, 3], translate=[8, -5], name='st')
    transform_b = ScaleTranslate(scale=[2, 1, 3], translate=[8, 0, -5])
    npt.assert_allclose(transform_a.expand_dims([1]).scale, transform_b.scale)
    npt.assert_allclose(
        transform_a.expand_dims([1]).translate, transform_b.translate)
    assert transform_a.expand_dims([1]).name == 'st'
Esempio n. 11
0
def test_scale_translate_identity_default():
    coord = [10, 13]
    transform = ScaleTranslate()
    new_coord = transform(coord)
    npt.assert_allclose(new_coord, coord)