PK!-ߝtwod/__init__.py__version__ = "0.1.0" from .point import Point from .rect import Rect from .exceptions import ColinearPoints __all__ = ["Point", "Rect", "ColinearPoints"] PK!"44twod/exceptions.py""" """ class ColinearPoints(Exception): pass PK!Y|bb twod/point.pyimport math from dataclasses import dataclass from .exceptions import ColinearPoints @dataclass class Point: x: int = 0 y: int = 0 @property def is_origin(self): """ """ return self.x == 0 and self.y == 0 def __iter__(self): """ """ return iter((self.x, self.y)) def __add__(self, other): """ """ try: return Point(self.x + other.x, self.y + other.y) except AttributeError: pass return Point(self.x + other, self.y + other) def __iadd__(self, other): """ """ try: self.x += other.x self.y += other.y return self except AttributeError: pass self.x += other self.y += other return self def __sub__(self, other): """ """ try: return Point(self.x - other.x, self.y - other.y) except AttributeError: pass return Point(self.x - other, self.y - other) def __isub__(self, other): """ """ try: self.x -= other.x self.y -= other.y return self except AttributeError: pass self.x -= other self.y -= other return self def __mul__(self, other): """ """ try: return Point(self.x * other.x, self.y * other.y) except AttributeError: pass return Point(self.x * other, self.y * other) def __imul__(self, other): """ """ try: self.x *= other.x self.y *= other.y return self except AttributeError: pass self.x *= other self.y *= other return self def __truediv__(self, other): """ """ try: return Point(self.x / other.x, self.y / other.y) except AttributeError: pass return Point(self.x / other, self.y / other) def __itruediv__(self, other): """ """ try: self.x /= other.x self.y /= other.y return self except AttributeError: pass self.x /= other self.y /= other return self def __floordiv__(self, other): """ """ try: return Point(self.x // other.x, self.y // other.y) except AttributeError: pass return Point(self.x // other, self.y // other) def __ifloordiv__(self, other): """ """ try: self.x //= other.x self.y //= other.y return self except AttributeError: pass self.x //= other self.y //= other return self def __pow__(self, exponent): """ """ return Point(self.x ** exponent, self.y ** exponent) def __ipow__(self, exponent): """ """ self.x **= exponent self.y **= exponent return self def __abs__(self): """ """ return Point(abs(self.x), abs(self.y)) def __neg__(self): """ """ return Point(-self.x, -self.y) def distance(self, other=None): """ """ return math.sqrt(self.distance_squared(other or Point())) def distance_squared(self, other=None): """ """ return sum((((other or Point()) - self) ** 2)) def dot(self, other): """ """ return sum(self * other) def cross(self, other): """ """ return (self.x * other.y) + (self.y * other.x) def ccw(self, b, c): """ """ return ((b.x - self.x) * (c.y - self.y)) - ((c.x - self.x) * (b.y - self.y)) def is_ccw(self, b, c): """ """ result = self.ccw(b, c) if result == 0: raise ColinearPoints(self, b, c) return result > 0 def is_colinear(self, b, c): """ """ return self.ccw(b, c) == 0 def midpoint(self, other=None): """ """ return (self + (other or Point())) / 2 def between(self, p, q): """ """ i = (p.x <= self.x <= q.x) or (q.x <= self.x <= p.x) j = (p.y <= self.y <= q.y) or (p.y <= self.y <= p.y) return i and j PK!we twod/rect.py""" """ from .point import Point from dataclasses import dataclass @dataclass class Rect(Point): w: int = 0 h: int = 0 def __iter__(self): return iter((self.x, self.y, self.w, self.h)) @property def A(self): return Point(self.x, self.y) @property def B(self): return Point(self.x + self.w, self.y) @property def C(self): return Point(self.x, self.y) + Point(self.w, self.h) @property def D(self): return Point(self.x, self.y + self.h) @property def vertices(self): return [self.A, self.B, self.C, self.D] @property def center(self): return self.A.midpoint(self.C) def __contains__(self, other): if not isinstance(other, Rect): return other.between(self.A, self.C) for v in other.vertices: if v.between(self.A, self.C): return True for v in self.vertices: if v.between(other.A, other.C): return True return False def __add__(self, other): return Rect( self.x + other.x, self.y + other.y, self.w + other.w, self.h + other.h ) def __iadd__(self, other): self.x += other.x self.y += other.y self.w += other.w self.h += other.h return self def __sub__(self, other): return Rect( self.x - other.x, self.y - other.y, self.w - other.w, self.h - other.h ) def __isub__(self, other): self.x -= other.x self.y -= other.y self.w -= other.w self.h -= other.h return self def __mul__(self, other): return Rect( self.x * other.x, self.y * other.y, self.w * other.w, self.h * other.h ) def __imul__(self, other): self.x *= other.x self.y *= other.y self.w *= other.w self.h *= other.h return self def __truediv__(self, other): try: return Rect( self.x / other.x, self.y / other.y, self.w / other.w, self.h / other.h ) except ZeroDivisionError: raise ZeroDivisionError(value) def __itruediv__(self, other): try: self.x /= other.x self.y /= other.y self.w /= other.w self.h /= other.h return self except ZeroDivisionError: raise ZeroDivisonError(value) def __floordiv__(self, other): try: return Rect( self.x // other.x, self.y // other.y, self.w // other.w, self.h // other.h, ) except ZeroDivisionError: raise ZeroDivisionError(value) def __ifloordiv__(self, value): try: self.x //= other.x self.y //= other.y self.w //= other.w self.h //= other.h return self except ZeroDivisionError: raise ZeroDivisionError(value) PK!HlUTtwod-0.1.0.dist-info/WHEEL HM K-*ϳR03rOK-J,/R(O-)T0343 /, (-JLR()*M IL*4KM̫PK!Hrtwod-0.1.0.dist-info/METADATA 0 }>+EE"8PsbW][mWdoo'"^/[젆Z'tRBNɗ,a19xQAsArYv?`XN#T [N3/ 1,XeK.*` 糔e$DXH Kk4-|CyoХYF^PK!HdNtwod-0.1.0.dist-info/RECORDmn@{e@B=A\QDeЙ Mcx^p6uB I?@Kd=7!! <~Wp\TG d95/+o4)yz'3őjwxi'Kg׏)^11ʆ޶.< ehj(uQ:d$s嚧HcQ.{;zPȾRE]u2|I;" rcyc3D(ςaȈyuĢbTxpkVe]Mi\ko&}x.DL-+7[1mnA (k3[OPK!-ߝtwod/__init__.pyPK!"44twod/exceptions.pyPK!Y|bb /twod/point.pyPK!we twod/rect.pyPK!HlUTtwod-0.1.0.dist-info/WHEELPK!Hr_twod-0.1.0.dist-info/METADATAPK!HdNP twod-0.1.0.dist-info/RECORDPK!