def test_minimal_se(self): """ Test resizing of element by dragging it SE handle. """ canvas = Canvas() box = Box() handles = box.handles() canvas.add(box) h_nw, h_ne, h_se, h_sw = handles assert h_nw is handles[NW] assert h_ne is handles[NE] assert h_sw is handles[SW] assert h_se is handles[SE] h_se.pos.x -= 20 # h.se.{x,y} == -10 h_se.pos.y -= 20 assert h_se.pos.x == h_se.pos.y == -10 box.request_update() canvas.update() self.assertEqual(10, h_se.pos.x) # h_se changed above, should be 10 self.assertEqual(10, h_se.pos.y) self.assertEqual(10, h_ne.pos.x) self.assertEqual(10, h_sw.pos.y)
def test_minimal_se(self): """ Test resizing of element by dragging it SE handle. """ canvas = Canvas() box = Box() handles = box.handles() canvas.add(box) h_nw, h_ne, h_se, h_sw = handles assert h_nw is handles[NW] assert h_ne is handles[NE] assert h_sw is handles[SW] assert h_se is handles[SE] h_se.pos.x -= 20 # h.se.{x,y} == -10 h_se.pos.y -= 20 assert h_se.pos.x == h_se.pos.y == -10 box.request_update() canvas.update() self.assertEquals(10, h_se.pos.x) # h_se changed above, should be 10 self.assertEquals(10, h_se.pos.y) self.assertEquals(10, h_ne.pos.x) self.assertEquals(10, h_sw.pos.y)
def test_creation_with_size(self): """ Test if initial size holds when added to a canvas. """ canvas = Canvas() box = Box(150, 153) assert box.width == 150, box.width assert box.height == 153, box.height assert box.handles()[SE].pos.x == 150, box.handles()[SE].pos.x assert box.handles()[SE].pos.y == 153, box.handles()[SE].pos.y canvas.add(box) assert box.width == 150, box.width assert box.height == 153, box.height assert box.handles()[SE].pos.x == 150, box.handles()[SE].pos.x assert box.handles()[SE].pos.y == 153, box.handles()[SE].pos.y
def test_get_handle_at_point(view_fixture): box = Box() box.min_width = 20 box.min_height = 30 box.matrix.translate(20, 20) box.matrix.rotate(math.pi / 1.5) view_fixture.canvas.add(box) i, h = view_fixture.view.get_handle_at_point((20, 20)) assert i is box assert h is box.handles()[0]
def test_get_handle_at_point(self): canvas = Canvas() view = GtkView(canvas) window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.add(view) window.show_all() box = Box() box.min_width = 20 box.min_height = 30 box.matrix.translate(20, 20) box.matrix.rotate(math.pi/1.5) canvas.add(box) i, h = view.get_handle_at_point((20, 20)) assert i is box assert h is box.handles()[0]
def test_get_handle_at_point(self): canvas = Canvas() view = GtkView(canvas) window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL) window.add(view) window.show_all() box = Box() box.min_width = 20 box.min_height = 30 box.matrix.translate(20, 20) box.matrix.rotate(old_div(math.pi, 1.5)) canvas.add(box) i, h = view.get_handle_at_point((20, 20)) assert i is box assert h is box.handles()[0]
def test_get_handle_at_point_at_pi_div_2(self): canvas = Canvas() view = GtkView(canvas) window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.add(view) window.show_all() box = Box() box.min_width = 20 box.min_height = 30 box.matrix.translate(20, 20) box.matrix.rotate(math.pi / 2) canvas.add(box) p = canvas.get_matrix_i2c(box).transform_point(0, 20) p = canvas.get_matrix_c2i(box).transform_point(20, 20) i, h = view.get_handle_at_point((20, 20)) assert i is box assert h is box.handles()[0]
def test_line_projection(self): """Test projection with line's handle on element's side""" line = Line() line.matrix.translate(15, 50) h1, h2 = line.handles() h1.x, h1.y = 0, 0 h2.x, h2.y = 20, 20 box = Box() box.matrix.translate(10, 10) box.width = 40 box.height = 20 h_nw, h_ne, h_se, h_sw = box.handles() canvas = Canvas() canvas.add(line) canvas.add(box) # move line's second handle on box side h2.x, h2.y = 5, -20
def test_resize_se(self): """ Test resizing of element by dragging it SE handle. """ canvas = Canvas() box = Box() handles = box.handles() canvas.add(box) h_nw, h_ne, h_se, h_sw = handles assert h_nw is handles[NW] assert h_ne is handles[NE] assert h_sw is handles[SW] assert h_se is handles[SE] # to see how many solver was called: # GAPHAS_TEST_COUNT=3 nosetests -s --with-prof --profile-restrict=gaphas gaphas/tests/test_element.py | grep -e '\<solve\>' -e dirty count = getenv('GAPHAS_TEST_COUNT') if count: count = int(count) else: count = 1 for i in range(count): h_se.pos.x += 100 # h.se.{x,y} = 10, now h_se.pos.y += 100 box.request_update() canvas.update() self.assertEqual( 110 * count, h_se.pos.x) # h_se changed above, should remain the same self.assertEqual(110 * count, float(h_se.pos.y)) self.assertEqual(110 * count, float(h_ne.pos.x)) self.assertEqual(110 * count, float(h_sw.pos.y))
def test_resize_se(self): """ Test resizing of element by dragging it SE handle. """ canvas = Canvas() box = Box() handles = box.handles() canvas.add(box) h_nw, h_ne, h_se, h_sw = handles assert h_nw is handles[NW] assert h_ne is handles[NE] assert h_sw is handles[SW] assert h_se is handles[SE] # to see how many solver was called: # GAPHAS_TEST_COUNT=3 nosetests -s --with-prof --profile-restrict=gaphas gaphas/tests/test_element.py | grep -e '\<solve\>' -e dirty count = getenv('GAPHAS_TEST_COUNT') if count: count = int(count) else: count = 1 for i in range(count): h_se.pos.x += 100 # h.se.{x,y} = 10, now h_se.pos.y += 100 box.request_update() canvas.update() self.assertEquals(110 * count, h_se.pos.x) # h_se changed above, should remain the same self.assertEquals(110 * count, float(h_se.pos.y)) self.assertEquals(110 * count, float(h_ne.pos.x)) self.assertEquals(110 * count, float(h_sw.pos.y))
class CanvasBox: def __init__(self): self.canvas = Canvas() self.box = Box() self.handles = self.box.handles()
class CanvasBox(object): def __init__(self): self.canvas = Canvas() self.box = Box() self.handles = self.box.handles()