<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from numpy . testing import assert_allclose as ac <EOL> from pytest import yield_fixture <EOL> from vispy . app import MouseEvent <EOL> from vispy . util import keys <EOL> from . . base import BaseVisual <EOL> from . . panzoom import PanZoom <EOL> class MyTestVisual ( BaseVisual ) : <EOL> def __init__ ( self ) : <EOL> super ( MyTestVisual , self ) . __init__ ( ) <EOL> self . set_shader ( '<STR_LIT>' ) <EOL> self . set_primitive_type ( '<STR_LIT>' ) <EOL> def set_data ( self ) : <EOL> self . program [ '<STR_LIT>' ] = [ [ - <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:0> ] ] <EOL> self . program [ '<STR_LIT>' ] = [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> @ yield_fixture <EOL> def panzoom ( qtbot , canvas_pz ) : <EOL> c = canvas_pz <EOL> visual = MyTestVisual ( ) <EOL> c . add_visual ( visual ) <EOL> visual . set_data ( ) <EOL> c . show ( ) <EOL> qtbot . waitForWindowShown ( c . native ) <EOL> yield c . panzoom <EOL> def test_panzoom_basic_attrs ( ) : <EOL> pz = PanZoom ( ) <EOL> assert pz . aspect == <NUM_LIT:1.> <EOL> pz . aspect = <NUM_LIT> <EOL> assert pz . aspect == <NUM_LIT> <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> assert getattr ( pz , name ) is None <EOL> setattr ( pz , name , <NUM_LIT:1.> ) <EOL> assert getattr ( pz , name ) == <NUM_LIT:1.> <EOL> for name , v in ( ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ) : <EOL> assert getattr ( pz , name ) == v <EOL> setattr ( pz , name , v * <NUM_LIT:2> ) <EOL> assert getattr ( pz , name ) == v * <NUM_LIT:2> <EOL> def test_panzoom_basic_constrain ( ) : <EOL> pz = PanZoom ( constrain_bounds = ( - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> assert pz . aspect == <NUM_LIT:1.> <EOL> pz . aspect = <NUM_LIT> <EOL> assert pz . aspect == <NUM_LIT> <EOL> assert pz . xmin == pz . ymin == - <NUM_LIT:1> <EOL> assert pz . xmax == pz . ymax == + <NUM_LIT:1> <EOL> def test_panzoom_basic_pan_zoom ( ) : <EOL> pz = PanZoom ( ) <EOL> assert pz . pan == [ <NUM_LIT:0.> , <NUM_LIT:0.> ] <EOL> pz . pan = ( <NUM_LIT:1.> , - <NUM_LIT:1.> ) <EOL> assert pz . pan == [ <NUM_LIT:1.> , - <NUM_LIT:1.> ] <EOL> assert pz . zoom == [ <NUM_LIT:1.> , <NUM_LIT:1.> ] <EOL> pz . zoom = ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert pz . zoom == [ <NUM_LIT> , <NUM_LIT> ] <EOL> pz . zoom = ( <NUM_LIT:1.> , <NUM_LIT:1.> ) <EOL> pz . pan_delta ( ( - <NUM_LIT:1.> , <NUM_LIT:1.> ) ) <EOL> assert pz . pan == [ <NUM_LIT:0.> , <NUM_LIT:0.> ] <EOL> pz . zoom_delta ( ( <NUM_LIT:1.> , <NUM_LIT:1.> ) ) <EOL> assert pz . zoom [ <NUM_LIT:0> ] > <NUM_LIT:2> <EOL> assert pz . zoom [ <NUM_LIT:0> ] == pz . zoom [ <NUM_LIT:1> ] <EOL> pz . zoom = ( <NUM_LIT:1.> , <NUM_LIT:1.> ) <EOL> pz . zoom_delta ( ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert pz . zoom [ <NUM_LIT:0> ] > <NUM_LIT:2> <EOL> assert pz . zoom [ <NUM_LIT:1> ] > <NUM_LIT:3> * pz . zoom [ <NUM_LIT:0> ] <EOL> def test_panzoom_map ( ) : <EOL> pz = PanZoom ( ) <EOL> pz . pan = ( <NUM_LIT:1.> , - <NUM_LIT:1.> ) <EOL> ac ( pz . map ( [ <NUM_LIT:0.> , <NUM_LIT:0.> ] ) , [ [ <NUM_LIT:1.> , - <NUM_LIT:1.> ] ] ) <EOL> pz . zoom = ( <NUM_LIT> , <NUM_LIT> ) <EOL> ac ( pz . map ( [ <NUM_LIT:0.> , <NUM_LIT:0.> ] ) , [ [ <NUM_LIT> , - <NUM_LIT> ] ] ) <EOL> ac ( pz . imap ( [ <NUM_LIT> , - <NUM_LIT> ] ) , [ [ <NUM_LIT:0.> , <NUM_LIT:0.> ] ] ) <EOL> def test_panzoom_constraints_x ( ) : <EOL> pz = PanZoom ( ) <EOL> pz . xmin , pz . xmax = - <NUM_LIT:2> , <NUM_LIT:2> <EOL> pz . pan_delta ( ( - <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> assert pz . pan == [ - <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> pz . reset ( ) <EOL> pz . zoom_delta ( ( - <NUM_LIT:1> , - <NUM_LIT:2> ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> assert pz . zoom [ <NUM_LIT:0> ] == <NUM_LIT> <EOL> assert pz . zoom [ <NUM_LIT:1> ] < <NUM_LIT> <EOL> def test_panzoom_constraints_y ( ) : <EOL> pz = PanZoom ( ) <EOL> pz . ymin , pz . ymax = - <NUM_LIT:2> , <NUM_LIT:2> <EOL> pz . pan_delta ( ( <NUM_LIT:2> , - <NUM_LIT:2> ) ) <EOL> assert pz . pan == [ <NUM_LIT:2> , - <NUM_LIT:1> ] <EOL> pz . reset ( ) <EOL> pz . zoom_delta ( ( - <NUM_LIT:2> , - <NUM_LIT:1> ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> assert pz . zoom [ <NUM_LIT:0> ] < <NUM_LIT> <EOL> assert pz . zoom [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> def test_panzoom_constraints_z ( ) : <EOL> pz = PanZoom ( ) <EOL> pz . zmin , pz . zmax = <NUM_LIT> , <NUM_LIT:2> <EOL> pz . zoom_delta ( ( - <NUM_LIT:10> , - <NUM_LIT:10> ) ) <EOL> assert pz . zoom == [ <NUM_LIT> , <NUM_LIT> ] <EOL> pz . reset ( ) <EOL> pz . zoom_delta ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> assert pz . zoom == [ <NUM_LIT:2> , <NUM_LIT:2> ] <EOL> def test_panzoom_set_range ( ) : <EOL> pz = PanZoom ( ) <EOL> def _test_range ( * bounds ) : <EOL> pz . set_range ( bounds ) <EOL> ac ( pz . get_range ( ) , bounds ) <EOL> _test_range ( - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> ac ( pz . zoom , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> _test_range ( - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> ac ( pz . zoom , ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> _test_range ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> ac ( pz . zoom , ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> _test_range ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> ac ( pz . zoom , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> pz . set_range ( ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ) , keep_aspect = True ) <EOL> ac ( pz . zoom , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> def test_panzoom_mouse_pos ( ) : <EOL> pz = PanZoom ( ) <EOL> pz . zoom_delta ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> pos = pz . get_mouse_pos ( ( <NUM_LIT> , - <NUM_LIT> ) ) <EOL> ac ( pos , ( <NUM_LIT> , <NUM_LIT> ) , atol = <NUM_LIT> ) <EOL> def test_panzoom_pan_mouse ( qtbot , canvas_pz , panzoom ) : <EOL> c = canvas_pz <EOL> pz = panzoom <EOL> press = MouseEvent ( type = '<STR_LIT>' , pos = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> c . events . mouse_move ( pos = ( <NUM_LIT> , <NUM_LIT:0.> ) , button = <NUM_LIT:1> , <EOL> last_event = press , press_event = press ) <EOL> assert pz . pan [ <NUM_LIT:0> ] > <NUM_LIT:0> <EOL> assert pz . pan [ <NUM_LIT:1> ] == <NUM_LIT:0> <EOL> pz . pan = ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> press = MouseEvent ( type = '<STR_LIT>' , pos = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> c . events . mouse_move ( pos = ( <NUM_LIT> , <NUM_LIT:0.> ) , button = <NUM_LIT:1> , <EOL> last_event = press , press_event = press , <EOL> modifiers = ( keys . CONTROL , ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> def test_panzoom_touch ( qtbot , canvas_pz , panzoom ) : <EOL> c = canvas_pz <EOL> pz = panzoom <EOL> c . events . touch ( type = '<STR_LIT>' , pos = ( <NUM_LIT:0> , <NUM_LIT:0> ) , scale = <NUM_LIT:1> , last_scale = <NUM_LIT:1> ) <EOL> c . events . touch ( type = '<STR_LIT>' , pos = ( <NUM_LIT:0> , <NUM_LIT:0> ) , scale = <NUM_LIT:2> , last_scale = <NUM_LIT:1> ) <EOL> assert pz . zoom [ <NUM_LIT:0> ] >= <NUM_LIT:2> <EOL> c . events . touch ( type = '<STR_LIT:end>' ) <EOL> c . events . touch ( type = '<STR_LIT>' , pos = ( <NUM_LIT:0.1> , <NUM_LIT:0> ) , last_pos = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> assert pz . pan [ <NUM_LIT:0> ] >= <NUM_LIT:1> <EOL> def test_panzoom_pan_keyboard ( qtbot , canvas_pz , panzoom ) : <EOL> c = canvas_pz <EOL> pz = panzoom <EOL> c . events . key_press ( key = keys . UP ) <EOL> assert pz . pan [ <NUM_LIT:0> ] == <NUM_LIT:0> <EOL> assert pz . pan [ <NUM_LIT:1> ] < <NUM_LIT:0> <EOL> c . events . key_press ( key = keys . LEFT ) <EOL> c . events . key_press ( key = keys . DOWN ) <EOL> c . events . key_press ( key = keys . RIGHT ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> c . events . key_press ( key = keys . RIGHT ) <EOL> c . events . key_press ( key = keys . Key ( '<STR_LIT:r>' ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> c . events . key_press ( key = keys . UP , modifiers = ( keys . CONTROL , ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> pz . enable_keyboard_pan = False <EOL> c . events . key_press ( key = keys . UP , modifiers = ( keys . CONTROL , ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> def test_panzoom_zoom_mouse ( qtbot , canvas_pz , panzoom ) : <EOL> c = canvas_pz <EOL> pz = panzoom <EOL> press = MouseEvent ( type = '<STR_LIT>' , pos = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> c . events . mouse_move ( pos = ( <NUM_LIT:0.> , <NUM_LIT:0.> ) , button = <NUM_LIT:2> , <EOL> last_event = press , press_event = press ) <EOL> assert pz . pan [ <NUM_LIT:0> ] < <NUM_LIT:0> <EOL> assert pz . pan [ <NUM_LIT:1> ] < <NUM_LIT:0> <EOL> assert pz . zoom [ <NUM_LIT:0> ] < <NUM_LIT:1> <EOL> assert pz . zoom [ <NUM_LIT:1> ] > <NUM_LIT:1> <EOL> pz . reset ( ) <EOL> size = np . asarray ( c . size ) <EOL> c . events . mouse_wheel ( pos = size / <NUM_LIT> , delta = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> assert pz . zoom [ <NUM_LIT:0> ] > <NUM_LIT:1> <EOL> assert pz . zoom [ <NUM_LIT:1> ] > <NUM_LIT:1> <EOL> pz . reset ( ) <EOL> c . events . mouse_wheel ( pos = ( <NUM_LIT:0.> , <NUM_LIT:0.> ) , delta = ( <NUM_LIT:0.> , <NUM_LIT:1.> ) , <EOL> modifiers = ( keys . CONTROL , ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> assert pz . zoom == [ <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> pz . reset ( ) <EOL> def test_panzoom_zoom_keyboard ( qtbot , canvas_pz , panzoom ) : <EOL> c = canvas_pz <EOL> pz = panzoom <EOL> c . events . key_press ( key = keys . Key ( '<STR_LIT:+>' ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> assert pz . zoom [ <NUM_LIT:0> ] > <NUM_LIT:1> <EOL> assert pz . zoom [ <NUM_LIT:1> ] > <NUM_LIT:1> <EOL> c . events . key_press ( key = keys . Key ( '<STR_LIT:->' ) ) <EOL> assert pz . pan == [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> assert pz . zoom == [ <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> def test_panzoom_resize ( qtbot , canvas_pz , panzoom ) : <EOL> c = canvas_pz <EOL> pz = panzoom <EOL> c . native . resize ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert list ( pz . _canvas_aspect ) == [ <NUM_LIT:1.> , <NUM_LIT> / <NUM_LIT:3> ] </s>
