def test_init_srcUdst_translated(self): src = Rectangle([100, 100, 300, 200]) dst = Rectangle([10, 10, 200, 100]) tobj = DrawingContext(src, dst) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(15.0, 10.0), tobj.t_translate()) self.assertEqual(0.9, tobj.scale()) src = Rectangle([100, 100, 300, 200]) dst = Rectangle([10, 10, 200, 100]) tobj = DrawingContext(src, dst, border=0.25) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(60.0, 32.5), tobj.t_translate()) self.assertEqual(0.45, tobj.scale()) src = Rectangle([100, 100, 300, 200]) dst = Rectangle([10, 10, 2000, 1000]) tobj = DrawingContext(src, dst, border=0) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(15.0, 10.0), tobj.t_translate()) self.assertEqual(9.9, tobj.scale()) src = Rectangle([100, 100, 300, 200]) dst = Rectangle([10, 10, 2000, 1000]) tobj = DrawingContext(src, dst, border=0.25) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(510.0, 257.5), tobj.t_translate()) self.assertEqual(4.95, tobj.scale()) src = Rectangle([100, 100, 300, 200]) dst = Rectangle([10, 10, 2000, 100]) tobj = DrawingContext(src, dst, border=0.25) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(960.0, 32.5), tobj.t_translate()) self.assertEqual(0.45, tobj.scale())
def test_init_src_translated(self): src = Rectangle([100, 100, 300, 200]) dst = Rectangle([0, 0, 200, 100]) tobj = DrawingContext(src, dst) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(0, 0), tobj.t_translate()) self.assertEqual(1, tobj.scale()) src = Rectangle([100, 100, 300, 200]) dst = Rectangle([0, 0, 200, 100]) tobj = DrawingContext(src, dst, border=0.25) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(50, 25), tobj.t_translate()) self.assertEqual(0.5, tobj.scale()) src = Rectangle([100, 100, 300, 200]) dst = Rectangle([0, 0, 2000, 1000]) tobj = DrawingContext(src, dst, border=0) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(0, 0), tobj.t_translate()) self.assertEqual(10, tobj.scale()) src = Rectangle([100, 100, 300, 200]) dst = Rectangle([0, 0, 2000, 1000]) tobj = DrawingContext(src, dst, border=0.25) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(500.0, 250.0), tobj.t_translate()) self.assertEqual(5, tobj.scale()) src = Rectangle([100, 100, 300, 200]) dst = Rectangle([0, 0, 2000, 100]) tobj = DrawingContext(src, dst, border=0.25) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(950.0, 25.0), tobj.t_translate()) self.assertEqual(0.5, tobj.scale())
def test_eq(self): s = Point(3, 9) e = Point(5, 1) tobj = Rectangle(s, e) self.assertTrue(tobj == Rectangle((3, 1, 5, 9))) self.assertTrue(tobj == (3, 1, 5, 9)) self.assertFalse(tobj == (3, 1, 5, 9, 8)) self.assertFalse(tobj == [3, 1, 5, 9, 8]) self.assertFalse(tobj == {3, 1, 5, 9, 8})
def test_init(self): s = Point(1, 3) e = Point(5, 9) tobj = Rectangle(s, e) self.assertEqual(s, tobj.start) self.assertEqual(e, tobj.end) tobj = Rectangle(e, s) self.assertEqual(s, tobj.start) self.assertEqual(e, tobj.end)
def test_init_list(self): tobj = Rectangle((1, 3, 5, 9)) self.assertEqual(tobj.start, Point(1, 3)) tobj = Rectangle([1, 3, 5, 9]) self.assertEqual(tobj.start, Point(1, 3)) sobj = {1, 3, 5, 9} tobj = Rectangle(sobj) self.assertEqual(tobj.start, Point(1, 3))
def test_init_Points(self): tobj = Rectangle(Point(5, 9), Point(1, 3)) self.assertEqual(tobj.start, Point(1, 3)) tobj = Rectangle(Point(1, 3)) self.assertEqual(tobj.start, Point(0, 0)) self.assertEqual(tobj.end, Point(1, 3)) tobj = Rectangle(Point(-1, -3)) self.assertEqual(tobj.end, Point(0, 0)) self.assertEqual(tobj.start, Point(-1, -3))
def test_repr(self): src = Rectangle([100, 100, 300, 200]) dst = Rectangle([10, 10, 2000, 100]) tobj = DrawingContext(src, dst, border=0.25) self.assertEqual(Point(-100, -100), tobj.o_translate()) self.assertEqual(Point(960.0, 32.5), tobj.t_translate()) self.assertEqual(0.45, tobj.scale()) s_ref = 'DrawingContext(orig=Rectangle(Point(100,100),Point(300,200)),target=Rectangle(Point(10,10),Point(2000,100)),border=0.25)' self.assertEqual(s_ref, repr(tobj)) s_ref = '(orig=Rectangle(Point(100,100),Point(300,200)),target=[(10,10)-(2000,100)],border=0.25) -> o_translate=(-100,-100),scale=0.45,t_translate=(960.0,32.5)' self.assertEqual(s_ref, str(tobj))
def test_contains_point(self): tobj = Rectangle([100, 100], [300, 300]) self.assertTrue(tobj.contains_point((200, 200))) self.assertTrue(tobj.contains_point((100, 100))) self.assertTrue(tobj.contains_point((300, 300))) self.assertFalse(tobj.contains_point((99, 100))) self.assertFalse(tobj.contains_point((100, 99))) self.assertFalse(tobj.contains_point((301, 100))) self.assertFalse(tobj.contains_point((100, 301)))
def test_transpose(self): src = Rectangle([100, 100, 300, 200]) dst = Rectangle([10, 10, 210, 110]) ctx = DrawingContext(src, dst, border=0) self.assertEqual(Point(10, 10), ctx.transpose(Point(100, 100))) self.assertEqual(Point(210, 110), ctx.transpose(Point(300, 200))) ctx = DrawingContext(src, dst, border=0.1) self.assertEqual(Point(30, 20), ctx.transpose(Point(100, 100))) self.assertEqual(Point(190, 100), ctx.transpose(Point(300, 200))) ctx = DrawingContext(src, dst, border=0.5) self.assertEqual(Point(110, 60), ctx.transpose(Point(100, 100))) self.assertEqual(Point(110, 60), ctx.transpose(Point(300, 200))) ctx = DrawingContext(src, dst, border=1) self.assertEqual(Point(210, 110), ctx.transpose(Point(100, 100))) self.assertEqual(Point(10, 10), ctx.transpose(Point(300, 200)))
def test_transpose_back(self): src = Rectangle([100, 100, 300, 200]) dst = Rectangle([10, 10, 210, 110]) ctx = DrawingContext(src, dst, border=0) self.assertEqual(Point(100, 100), ctx.transposeBack(Point(10, 10))) self.assertEqual(Point(300, 200), ctx.transposeBack(Point(210, 110))) for src in [Point(100, 100), Point(300, 200)]: self.assertEqual(src, ctx.transposeBack(ctx.transpose(src))) ctx = DrawingContext(src, dst, border=0.1) for src in [Point(100, 100), Point(300, 200)]: self.assertEqual(src, ctx.transposeBack(ctx.transpose(src))) ctx = DrawingContext(src, dst, border=0.5) for src in [Point(100, 100), Point(300, 200)]: self.assertEqual(src, ctx.transposeBack(src)) ctx = DrawingContext(src, dst, border=1) for src in [Point(100, 100), Point(300, 200)]: p = ctx.transposeBack(ctx.transpose(src)) x, y = round(p.x), round(p.y) self.assertEqual(src, Point(x, y))
def test_init_simple(self): src = Rectangle([0, 0, 200, 100]) dst = Rectangle([0, 0, 200, 100]) tobj = DrawingContext(src, dst, border=0) self.assertEqual(Point(0, 0), tobj.o_translate()) self.assertEqual(Point(0, 0), tobj.t_translate()) self.assertEqual(1, tobj.scale()) src = Rectangle([0, 0, 200, 100]) dst = Rectangle([0, 0, 300, 100]) tobj = DrawingContext(src, dst, border=0) self.assertEqual(Point(0, 0), tobj.o_translate()) self.assertEqual(Point(50, 0), tobj.t_translate()) self.assertEqual(1, tobj.scale()) src = Rectangle([0, 0, 200, 100]) dst = Rectangle([0, 0, 200, 200]) tobj = DrawingContext(src, dst, border=0) self.assertEqual(Point(0, 0), tobj.o_translate()) self.assertEqual(Point(0, 50), tobj.t_translate()) self.assertEqual(1, tobj.scale())
def orig_rect(self, newValue): self._orig_rect = Rectangle(newValue) self.set_dirty()
def test_center(self): tobj = Rectangle([100, 100], [300, 300]) center = tobj.center() self.assertEqual(Point(200, 200), center)
def test_str(self): tobj = Rectangle([1, 3], [5, 9]) s = str(tobj) self.assertTrue(s == '[(1,3)-(5,9)]') self.assertTrue(f'{tobj}' == '[(1,3)-(5,9)]')
def test_repr(self): tobj = Rectangle([1, 3, 5, 9]) r = repr(tobj) self.assertEqual('Rectangle(Point(1,3),Point(5,9))', r)
def test_extent(self): s = Point(3, 9) e = Point(5, 1) tobj = Rectangle(s, e) self.assertEqual((2, 8), tobj.extent)
def test_height(self): s = Point(3, 9) e = Point(5, 1) tobj = Rectangle(s, e) self.assertEqual(8, tobj.height)
def test_width(self): s = Point(3, 9) e = Point(5, 1) tobj = Rectangle(s, e) self.assertEqual(2, tobj.width)
def on_resize(self, event): self.canvas_area = Rectangle((0, 0, self.winfo_width(), self.winfo_height())) self.drawing_context.target_rect = self.canvas_area self.redraw()
def target_rect(self, newValue): self._target_rect = Rectangle(newValue) self.set_dirty()
def test_init_Rectangle(self): oRect = Rectangle((1, 3, 5, 9)) tobj = Rectangle(oRect) self.assertEqual(tobj.start, Point(1, 3))
def __init__(self, orig, target, border=0): self.orig_rect = Rectangle(orig) self.target_rect = Rectangle(target) self.target_border = border
def init_context(self): self.drawing_area = Rectangle((0, 0, 1000, 1000)) self.canvas_area = Rectangle((0, 0, self.winfo_width(), self.winfo_height())) self.drawing_context = DrawingContext(orig=self.drawing_area, target=self.canvas_area, border=0.05)