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

Function edges_to_intersections

src/table.py:1322–1344  ·  view source on GitHub ↗

Given a list of edges, return the points at which they intersect within `tolerance` pixels.

(edges, x_tolerance=1, y_tolerance=1)

Source from the content-addressed store, hash-verified

1320
1321
1322def edges_to_intersections(edges, x_tolerance=1, y_tolerance=1) -> dict:
1323 """
1324 Given a list of edges, return the points at which they intersect
1325 within `tolerance` pixels.
1326 """
1327 intersections = {}
1328 v_edges, h_edges = [
1329 list(filter(lambda x: x["orientation"] == o, edges)) for o in ("v", "h")
1330 ]
1331 for v in sorted(v_edges, key=itemgetter("x0", "top")):
1332 for h in sorted(h_edges, key=itemgetter("top", "x0")):
1333 if (
1334 (v["top"] <= (h["top"] + y_tolerance))
1335 and (v["bottom"] >= (h["top"] - y_tolerance))
1336 and (v["x0"] >= (h["x0"] - x_tolerance))
1337 and (v["x0"] <= (h["x1"] + x_tolerance))
1338 ):
1339 vertex = (v["x0"], h["top"])
1340 if vertex not in intersections:
1341 intersections[vertex] = {"v": [], "h": []}
1342 intersections[vertex]["v"].append(v)
1343 intersections[vertex]["h"].append(h)
1344 return intersections
1345
1346
1347def obj_to_bbox(obj):

Callers 1

__init__Method · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…