Debian Codegraph @

test-crates/cffi-mixed/cffi_mixed/line.py

raw
1 import math
2
3 from .cffi_mixed import ffi
4
5
6 class Line:
7 def __init__(self, x1: float, y1: float, x2: float, y2: float):
8 # You can pass a tuple/list or a dict as value for a public rust struct
9 self.start = ffi.new("Point *", {"x": x1, "y": y1})
10 self.end = ffi.new("Point *", (x2, y2))
11
12 def length(self) -> float:
13 """Returns the length of the line."""
14 return math.sqrt((self.end.x - self.start.x) ** 2 + (self.end.y - self.start.y) ** 2)
15
16 def __str__(self) -> str:
17 return "Line from ({},{}) to ({},{})".format(self.start.x, self.start.y, self.end.x, self.end.y)