def __init__(self, a: Point, b: Point, precision: int=PRECISION) -> None:
x_diff = round(a.x, precision) - round(b.x, precision)
y_diff = round(a.y, precision) - round(b.y, precision)
if x_diff < 0 or (x_diff == 0 and a.y < b.y):
self._start, self._end = a, b
else:
self._start, self._end = b, a
if a == b:
self._slope = None
self._offset = None
elif x_diff == 0:
self._slope = math.inf
self._offset = self._start.x
else:
self._slope = y_diff / x_diff
self._offset = self._start.y - (self._start.x * self._slope)
self._precision = precision
评论列表
文章目录