def resize(self, w: int, h: int): self.position = self.coordinate.copy() self.position = self.position * Point((w, h)) for i in self.recipe_widget: i.resize(w, h)
def __init__(self, x1=0, y1=0, x2=0, y2=0): # Point class will return Value Erros in case variables are not numbers self.pt1 = Point(x1, y1) self.pt2 = Point(x2, y2)
def center(self): return Point((self.pt1.x + self.pt2.x) / 2, (self.pt1.y + self.pt2.y) / 2)
def lay(self) -> None: self.position = self.start_coordinate.copy() self.position = self.position * Point((self.screen_w, self.screen_h)) self.is_clicked = False
def __init__(self, x, y, radius): if radius < 0: raise ValueError("promień ujemny") self.pt = Point(x, y) self.radius = radius
def __init__(self, x1, y1, x2, y2): if x1 >= x2 or y1 >= y2: raise ValueError("x1 needs to be lesser than x2 and y1 needs to be lesser than y2") self.pt1 = Point(x1, y1) self.pt2 = Point(x2, y2)
def resize(self, w: int, h: int) -> None: self.position = self.position * Point((1 / self.screen_w, 1 / self.screen_h)) self.position = self.position * Point((w, h)) self.im = pygame.transform.scale(self.image, self.position.size.to_int()) self.screen_w, self.screen_h = w, h
def center(self): # zwraca środek prostokąta point = Point() point.x = (self.pt1.x + self.pt2.x)/2.0 point.y = (self.pt1.y + self.pt2.y)/2.0 return point
def __init__(self, x1=0, y1=0, x2=0, y2=0): self.pt1 = Point(x1, y1) self.pt2 = Point(x2, y2)
def move(self, x, y): self.pt1 += Point(x, y) self.pt2 += Point(x, y) self.pt3 += Point(x, y)
def test__center(self): self.assertEqual(self.rec1.center(), Point(3, 3)) self.assertEqual(self.rec2.center(), Point(1, 1))
def center(self): return Point((self.pt1.x + self.pt2.x + self.pt3.x) / 3.0, (self.pt1.y + self.pt2.y + self.pt3.y) / 3.0)
def test_center(self): self.assertEqual(self.t1.center(), Point(1.0 / 3.0, 1.0 / 3.0)) self.assertEqual(self.t4.center(), Point(4.0 / 3.0, 4.0 / 3.0)) self.assertEqual(self.t5.center(), Point(-1, -1))
def __init__(self, x1=0, y1=0, x2=0, y2=0, x3=0, y3=0): self.pt1 = Point(x1, y1) self.pt2 = Point(x2, y2) self.pt3 = Point(x3, y3) if (self.area() == 0): return ValueError("Punkty wspolliniowe")
def test_slope(self): a = Point(1,1) b = Point(2,2) self.assertEqual(a.slope(b), 1, "incorrect slope between (%d, %d) and (%d, %d)" % (a.x, a.y, b.x, b.y)) a = Point(1,1) b = Point(2,3) self.assertEqual(a.slope(b), 2, "incorrect slope between (%d, %d) and (%d, %d)" % (a.x, a.y, b.x, b.y)) a = Point(1,1) b = Point(3,2) self.assertEqual(a.slope(b), 0.5, "incorrect slope between (%d, %d) and (%d, %d)" % (a.x, a.y, b.x, b.y)) a = Point(5,3) b = Point(6,2) self.assertEqual(a.slope(b), -1, "incorrect slope between (%d, %d) and (%d, %d)" % (a.x, a.y, b.x, b.y)) a = Point(5,3) b = Point(4,3) self.assertEqual(a.slope(b), 0, "incorrect slope between (%d, %d) and (%d, %d)" % (a.x, a.y, b.x, b.y)) a = Point(5,3) b = Point(5,0) self.assertIsNone(a.slope(b), "incorrect slope between (%d, %d) and (%d, %d)" % (a.x, a.y, b.x, b.y))
def center(self): x = round(abs(float(self.pt2.x - self.pt1.x))/2 + self.pt1.x, 2) y = round(abs(float(self.pt2.y - self.pt1.y))/2 + self.pt1.y, 2) return Point(x, y)
def test_center(self): assert(Rectangle(2, 2, 4, 4).center() == Point(3, 3))
def __init__(self, x1=0, y1=0, x2=0, y2=0): # lewy dolny wierzcholek self.pt1 = Point(x1, y1) # prawy gorny wierzcholek self.pt2 = Point(x2, y2)
def center(self): # zwraca środek prostokąta return Point((self.pt1.x+self.pt2.x)/2, (self.pt1.y+self.pt2.y)/2)
def test_init(self): pt = Point(3,4) self.assertTrue(hasattr(pt, 'x'), "point missing 'x' attribute") self.assertTrue(hasattr(pt, 'y'), "point missing 'y' attribute") self.assertEqual(pt.x, 3, "point has incorrect 'x' value") self.assertEqual(pt.y, 4, "point has incorrect 'y' value")
def click(self, pos: tuple): if self.position.is_in_area(Point(pos)): self.is_clicked = True self.cursor = Point(pos) return self
def test_move(self): pt = Point(4,5) pt.move(2,3) self.assertEqual(pt.x, 2, "pt.x did not move from 4 to 2") self.assertEqual(pt.y, 3, "pt.y did not move from 5 to 3")
def move(self, pos: tuple): if self.is_clicked: point = Point(pos) self.dp = Point(pos) - self.cursor self.position.move(self.dp) self.cursor = point
def test_translate(self): pt = Point(4,5) pt.translate(-1, 1) self.assertEqual(pt.x, 3, "pt.x did not translate by -1 from 4 to 3") self.assertEqual(pt.y, 6, "pt.y did not translate by 1 from 5 to 6")
def __init__(self, x1, y1, x2, y2): self.pt1 = Point(x1, y1) self.pt2 = Point(x2, y2)
def test_to_string(self): self.assertEqual(str(Point(1,1)), "(1,1)") self.assertEqual(str(Point(1.5,2.0)), "(1.5,2.0)")
def test_center(self): self.assertEqual(self.r1.center(), Point(0, 0)) self.assertEqual(self.r4.center(), Point(1, 2)) self.assertEqual(self.r5.center(), Point(-4, -2)) self.assertEqual(self.r6.center(), Point(0, 0))
def test_equality(self): self.assertEqual(Point(1,1), Point(1,1)) self.assertNotEqual(Point(1,1), [1,1]) self.assertNotEqual(Point(1,1), Point(1,2)) self.assertNotEqual(Point(1,1), Point(2,1)) self.assertNotEqual(Point(1,1), Point(2,2))
def move(self, x, y): # if x or are not numbers, exception will be raised by Point class self.pt1 += Point(x, y) self.pt2 += Point(x, y)
def move(self, x, y): # przesunięcie o (x, y) self.pt1 = Point(self.pt1.x + x, self.pt1.y + y) self.pt2 = Point(self.pt2.x + x, self.pt2.y + y)