| 14120 | |
| 14121 | |
| 14122 | class Point: |
| 14123 | |
| 14124 | def __abs__(self): |
| 14125 | return math.sqrt(self.x * self.x + self.y * self.y) |
| 14126 | |
| 14127 | def __add__(self, p): |
| 14128 | if hasattr(p, "__float__"): |
| 14129 | return Point(self.x + p, self.y + p) |
| 14130 | if len(p) != 2: |
| 14131 | raise ValueError("Point: bad seq len") |
| 14132 | return Point(self.x + p[0], self.y + p[1]) |
| 14133 | |
| 14134 | def __bool__(self): |
| 14135 | return not (max(self) == min(self) == 0) |
| 14136 | |
| 14137 | def __eq__(self, p): |
| 14138 | if not hasattr(p, "__len__"): |
| 14139 | return False |
| 14140 | return len(p) == 2 and not (self - p) |
| 14141 | |
| 14142 | def __getitem__(self, i): |
| 14143 | return (self.x, self.y)[i] |
| 14144 | |
| 14145 | def __hash__(self): |
| 14146 | return hash(tuple(self)) |
| 14147 | |
| 14148 | def __init__(self, *args, x=None, y=None): |
| 14149 | ''' |
| 14150 | Point() - all zeros |
| 14151 | Point(x, y) |
| 14152 | Point(Point) - new copy |
| 14153 | Point(sequence) - from 'sequence' |
| 14154 | |
| 14155 | Explicit keyword args x, y override earlier settings if not None. |
| 14156 | ''' |
| 14157 | if not args: |
| 14158 | self.x = 0.0 |
| 14159 | self.y = 0.0 |
| 14160 | elif len(args) > 2: |
| 14161 | raise ValueError("Point: bad seq len") |
| 14162 | elif len(args) == 2: |
| 14163 | self.x = float(args[0]) |
| 14164 | self.y = float(args[1]) |
| 14165 | elif len(args) == 1: |
| 14166 | l = args[0] |
| 14167 | if isinstance(l, (mupdf.FzPoint, mupdf.fz_point)): |
| 14168 | self.x = l.x |
| 14169 | self.y = l.y |
| 14170 | else: |
| 14171 | if not hasattr(l, "__getitem__"): |
| 14172 | raise ValueError("Point: bad args") |
| 14173 | if len(l) != 2: |
| 14174 | raise ValueError("Point: bad seq len") |
| 14175 | self.x = float(l[0]) |
| 14176 | self.y = float(l[1]) |
| 14177 | else: |
| 14178 | raise ValueError("Point: bad seq len") |
| 14179 | if x is not None: self.x = x |
no outgoing calls
no test coverage detected
searching dependent graphs…