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

Function snap_edges

src/table.py:1066–1081  ·  view source on GitHub ↗

Given a list of edges, snap any within `tolerance` pixels of one another to their positional average.

(
    edges,
    x_tolerance=DEFAULT_SNAP_TOLERANCE,
    y_tolerance=DEFAULT_SNAP_TOLERANCE,
)

Source from the content-addressed store, hash-verified

1064
1065
1066def snap_edges(
1067 edges,
1068 x_tolerance=DEFAULT_SNAP_TOLERANCE,
1069 y_tolerance=DEFAULT_SNAP_TOLERANCE,
1070):
1071 """
1072 Given a list of edges, snap any within `tolerance` pixels of one another
1073 to their positional average.
1074 """
1075 by_orientation = {"v": [], "h": []}
1076 for e in edges:
1077 by_orientation[e["orientation"]].append(e)
1078
1079 snapped_v = snap_objects(by_orientation["v"], "x0", x_tolerance)
1080 snapped_h = snap_objects(by_orientation["h"], "top", y_tolerance)
1081 return snapped_v + snapped_h
1082
1083
1084def resize_object(obj, key: str, value):

Callers 1

merge_edgesFunction · 0.85

Calls 2

snap_objectsFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…