MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_matrix

Function test_matrix

tests/test_geometry.py:135–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

133
134
135def test_matrix():
136 assert tuple(pymupdf.Matrix()) == (0, 0, 0, 0, 0, 0)
137 assert tuple(pymupdf.Matrix(90)) == (0, 1, -1, 0, 0, 0)
138 if hasattr(pymupdf, 'mupdf'):
139 assert tuple(pymupdf.Matrix(c=1)) == (0, 0, 1, 0, 0, 0)
140 assert tuple(pymupdf.Matrix(90, e=5)) == (0, 1, -1, 0, 5, 0)
141 m45p = pymupdf.Matrix(45)
142 m45m = pymupdf.Matrix(-45)
143 m90 = pymupdf.Matrix(90)
144 assert abs(m90 - m45p * m45p) < pymupdf.EPSILON
145 assert abs(pymupdf.Identity - m45p * m45m) < pymupdf.EPSILON
146 assert abs(m45p - ~m45m) < pymupdf.EPSILON
147 assert pymupdf.Matrix(2, 3, 1) == pymupdf.Matrix(1, 3, 2, 1, 0, 0)
148 m = pymupdf.Matrix(2, 3, 1)
149 m.invert()
150 assert abs(m * pymupdf.Matrix(2, 3, 1) - pymupdf.Identity) < pymupdf.EPSILON
151 assert pymupdf.Matrix(1, 1).pretranslate(2, 3) == pymupdf.Matrix(1, 0, 0, 1, 2, 3)
152 assert pymupdf.Matrix(1, 1).prescale(2, 3) == pymupdf.Matrix(2, 0, 0, 3, 0, 0)
153 assert pymupdf.Matrix(1, 1).preshear(2, 3) == pymupdf.Matrix(1, 3, 2, 1, 0, 0)
154 assert abs(pymupdf.Matrix(1, 1).prerotate(30) - pymupdf.Matrix(30)) < pymupdf.EPSILON
155 small = 1e-6
156 assert pymupdf.Matrix(1, 1).prerotate(90 + small) == pymupdf.Matrix(90)
157 assert pymupdf.Matrix(1, 1).prerotate(180 + small) == pymupdf.Matrix(180)
158 assert pymupdf.Matrix(1, 1).prerotate(270 + small) == pymupdf.Matrix(270)
159 assert pymupdf.Matrix(1, 1).prerotate(small) == pymupdf.Matrix(0)
160 assert pymupdf.Matrix(1, 1).concat(
161 pymupdf.Matrix(1, 2), pymupdf.Matrix(3, 4)
162 ) == pymupdf.Matrix(3, 0, 0, 8, 0, 0)
163 assert pymupdf.Matrix(1, 2, 3, 4, 5, 6) / 1 == pymupdf.Matrix(1, 2, 3, 4, 5, 6)
164 assert m[0] == m.a
165 assert m[1] == m.b
166 assert m[2] == m.c
167 assert m[3] == m.d
168 assert m[4] == m.e
169 assert m[5] == m.f
170 m = pymupdf.Matrix()
171 for i in range(6):
172 m[i] = i + 1
173 assert m == pymupdf.Matrix(1, 2, 3, 4, 5, 6)
174 failed = False
175 try:
176 m = pymupdf.Matrix(1, 2, 3)
177 except:
178 failed = True
179 assert failed
180 failed = False
181 try:
182 m = pymupdf.Matrix(1, 2, 3, 4, 5, 6, 7)
183 except:
184 failed = True
185 assert failed
186
187 failed = False
188 try:
189 m = pymupdf.Matrix((1, 2, 3, 4, 5, 6, 7))
190 except:
191 failed = True
192 assert failed

Callers

nothing calls this directly

Calls 6

invertMethod · 0.95
pretranslateMethod · 0.80
prescaleMethod · 0.80
preshearMethod · 0.80
prerotateMethod · 0.80
concatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…