geometry.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:vectorvondoom 作者: bcj 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号