(page, clip=None, tset=None, paths=None, add_lines=None, add_boxes=None)
| 2244 | # else to lines. |
| 2245 | # ------------------------------------------------------------------------ |
| 2246 | def make_edges(page, clip=None, tset=None, paths=None, add_lines=None, add_boxes=None): |
| 2247 | snap_x = tset.snap_x_tolerance |
| 2248 | snap_y = tset.snap_y_tolerance |
| 2249 | min_length = tset.edge_min_length |
| 2250 | lines_strict = ( |
| 2251 | tset.vertical_strategy == "lines_strict" |
| 2252 | or tset.horizontal_strategy == "lines_strict" |
| 2253 | ) |
| 2254 | page_height = page.rect.height |
| 2255 | doctop_basis = page.number * page_height |
| 2256 | page_number = page.number + 1 |
| 2257 | prect = page.rect |
| 2258 | if page.rotation in (90, 270): |
| 2259 | w, h = prect.br |
| 2260 | prect = pymupdf.Rect(0, 0, h, w) |
| 2261 | if clip is not None: |
| 2262 | clip = pymupdf.Rect(clip) |
| 2263 | else: |
| 2264 | clip = prect |
| 2265 | |
| 2266 | def are_neighbors(r1, r2): |
| 2267 | """Detect whether r1, r2 are neighbors. |
| 2268 | |
| 2269 | Defined as: |
| 2270 | The minimum distance between points of r1 and points of r2 is not |
| 2271 | larger than some delta. |
| 2272 | |
| 2273 | This check supports empty rect-likes and thus also lines. |
| 2274 | |
| 2275 | Note: |
| 2276 | This type of check is MUCH faster than native Rect containment checks. |
| 2277 | """ |
| 2278 | if ( # check if x-coordinates of r1 are within those of r2 |
| 2279 | r2.x0 - snap_x <= r1.x0 <= r2.x1 + snap_x |
| 2280 | or r2.x0 - snap_x <= r1.x1 <= r2.x1 + snap_x |
| 2281 | ) and ( # ... same for y-coordinates |
| 2282 | r2.y0 - snap_y <= r1.y0 <= r2.y1 + snap_y |
| 2283 | or r2.y0 - snap_y <= r1.y1 <= r2.y1 + snap_y |
| 2284 | ): |
| 2285 | return True |
| 2286 | |
| 2287 | # same check with r1 / r2 exchanging their roles (this is necessary!) |
| 2288 | if ( |
| 2289 | r1.x0 - snap_x <= r2.x0 <= r1.x1 + snap_x |
| 2290 | or r1.x0 - snap_x <= r2.x1 <= r1.x1 + snap_x |
| 2291 | ) and ( |
| 2292 | r1.y0 - snap_y <= r2.y0 <= r1.y1 + snap_y |
| 2293 | or r1.y0 - snap_y <= r2.y1 <= r1.y1 + snap_y |
| 2294 | ): |
| 2295 | return True |
| 2296 | return False |
| 2297 | |
| 2298 | def clean_graphics(npaths=None): |
| 2299 | """Detect and join rectangles of "connected" vector graphics.""" |
| 2300 | if npaths is None: |
| 2301 | allpaths = page.get_drawings() |
| 2302 | else: # accept passed-in vector graphics |
| 2303 | allpaths = npaths[:] # paths relevant for table detection |
no test coverage detected
searching dependent graphs…