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_init_tuple(self): tobj = Point((5, 9), 27) self.assertIsNotNone(tobj) self.assertEqual(5, tobj.x) self.assertEqual(9, tobj.y)
def on_drag(self, newPos): newPos = Point(newPos) logger.debug(f'Drag to pos={newPos}')
def test_width(self): s = Point(3, 9) e = Point(5, 1) tobj = Rectangle(s, e) self.assertEqual(2, tobj.width)
def test_init_Point(self): pt = Point(7.0, 13.78) tobj = Point(pt) self.assertIsNotNone(tobj) self.assertEqual(7, tobj.x) self.assertEqual(13.78, tobj.y)
def f2(): return Point((1, 2, 3))
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_div(self): p1 = Point(1, 3) tobj = p1 / 2 self.assertEqual(Point(0.5, 1.5), tobj) tobj = p1 / Point(3, 2) self.assertEqual(Point(1 / 3, 3 / 2), tobj)
def __init__(self, owner, startPos): self.owner = owner self.startPos = Point(startPos) logger.debug(f'Start Drp on pos={startPos}')
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 on_drop(self, dropPos): dropPos = Point(dropPos) rPos = self.owner.transposeBack(dropPos) logger.debug(f'Drop on pos={dropPos} rPos={rPos}') self.lineObj.end = rPos self.owner.redraw()
def on_drag(self, newPos): newPos = Point(newPos) sx, sy = self.startPos.xy ex, ey = newPos.xy self.owner.coords(self.lineObj.widget, sx, sy, ex, ey)
def on_drop(self, dropPos): dropPos = Point(dropPos) rPos = self.owner.transposeBack(dropPos) logger.debug(f'Drop on pos={dropPos} rPos={rPos}')
def test_center(self): tobj = Rectangle([100, 100], [300, 300]) center = tobj.center() self.assertEqual(Point(200, 200), center)
def test_init(self): tobj = Point(5, 9) self.assertIsNotNone(tobj) self.assertEqual(5, tobj.x) self.assertEqual(9, tobj.y)
def test_init_float(self): tobj = Point(5.0, 3) self.assertIsNotNone(tobj) self.assertEqual(5, tobj.x) self.assertEqual(3, tobj.y)
def test_ng(self): p1 = Point(1, 3) tobj = -p1 self.assertEqual(Point(1, 3), p1) self.assertEqual(Point(-1, -3), tobj)
def f1(): return Point({'x': 3, 'y': 4})
def test_init_Rectangle(self): oRect = Rectangle((1, 3, 5, 9)) tobj = Rectangle(oRect) self.assertEqual(tobj.start, Point(1, 3))
def test_xy(self): tobj = Point(5, 9) self.assertEqual((5, 9), tobj.xy)
def __init__(self, start, end): super().__init__() self.start = Point(start) self.end = Point(end)