| 8628 | |
| 8629 | |
| 8630 | class Matrix: |
| 8631 | |
| 8632 | def __abs__(self): |
| 8633 | return math.sqrt(sum([c*c for c in self])) |
| 8634 | |
| 8635 | def __add__(self, m): |
| 8636 | if hasattr(m, "__float__"): |
| 8637 | return Matrix(self.a + m, self.b + m, self.c + m, |
| 8638 | self.d + m, self.e + m, self.f + m) |
| 8639 | if len(m) != 6: |
| 8640 | raise ValueError("Matrix: bad seq len") |
| 8641 | return Matrix(self.a + m[0], self.b + m[1], self.c + m[2], |
| 8642 | self.d + m[3], self.e + m[4], self.f + m[5]) |
| 8643 | |
| 8644 | def __bool__(self): |
| 8645 | return not (max(self) == min(self) == 0) |
| 8646 | |
| 8647 | def __eq__(self, mat): |
| 8648 | if not hasattr(mat, "__len__"): |
| 8649 | return False |
| 8650 | return len(mat) == 6 and not (self - mat) |
| 8651 | |
| 8652 | def __getitem__(self, i): |
| 8653 | return (self.a, self.b, self.c, self.d, self.e, self.f)[i] |
| 8654 | |
| 8655 | def __init__(self, *args, a=None, b=None, c=None, d=None, e=None, f=None): |
| 8656 | """ |
| 8657 | Matrix() - all zeros |
| 8658 | Matrix(a, b, c, d, e, f) |
| 8659 | Matrix(zoom-x, zoom-y) - zoom |
| 8660 | Matrix(shear-x, shear-y, 1) - shear |
| 8661 | Matrix(degree) - rotate |
| 8662 | Matrix(Matrix) - new copy |
| 8663 | Matrix(sequence) - from 'sequence' |
| 8664 | Matrix(mupdf.FzMatrix) - from MuPDF class wrapper for fz_matrix. |
| 8665 | |
| 8666 | Explicit keyword args a, b, c, d, e, f override any earlier settings if |
| 8667 | not None. |
| 8668 | """ |
| 8669 | if not args: |
| 8670 | self.a = self.b = self.c = self.d = self.e = self.f = 0.0 |
| 8671 | elif len(args) > 6: |
| 8672 | raise ValueError("Matrix: bad seq len") |
| 8673 | elif len(args) == 6: # 6 numbers |
| 8674 | self.a, self.b, self.c, self.d, self.e, self.f = map(float, args) |
| 8675 | elif len(args) == 1: # either an angle or a sequ |
| 8676 | if isinstance(args[0], mupdf.FzMatrix): |
| 8677 | self.a = args[0].a |
| 8678 | self.b = args[0].b |
| 8679 | self.c = args[0].c |
| 8680 | self.d = args[0].d |
| 8681 | self.e = args[0].e |
| 8682 | self.f = args[0].f |
| 8683 | elif hasattr(args[0], "__float__"): |
| 8684 | theta = math.radians(args[0]) |
| 8685 | c_ = round(math.cos(theta), 8) |
| 8686 | s_ = round(math.sin(theta), 8) |
| 8687 | self.a = self.d = c_ |
no outgoing calls
no test coverage detected
searching dependent graphs…