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

Function make_line

src/table.py:2353–2405  ·  view source on GitHub ↗

Given 2 points, make a line dictionary for table detection.

(p, p1, p2, clip)

Source from the content-addressed store, hash-verified

2351 return False
2352
2353 def make_line(p, p1, p2, clip):
2354 """Given 2 points, make a line dictionary for table detection."""
2355 if not is_parallel(p1, p2): # only accepting axis-parallel lines
2356 return {}
2357 # compute the extremal values
2358 x0 = min(p1.x, p2.x)
2359 x1 = max(p1.x, p2.x)
2360 y0 = min(p1.y, p2.y)
2361 y1 = max(p1.y, p2.y)
2362
2363 # check for outside clip
2364 if x0 > clip.x1 or x1 < clip.x0 or y0 > clip.y1 or y1 < clip.y0:
2365 return {}
2366
2367 if x0 < clip.x0:
2368 x0 = clip.x0 # adjust to clip boundary
2369
2370 if x1 > clip.x1:
2371 x1 = clip.x1 # adjust to clip boundary
2372
2373 if y0 < clip.y0:
2374 y0 = clip.y0 # adjust to clip boundary
2375
2376 if y1 > clip.y1:
2377 y1 = clip.y1 # adjust to clip boundary
2378
2379 width = x1 - x0 # from adjusted values
2380 height = y1 - y0 # from adjusted values
2381 if width == height == 0:
2382 return {} # nothing left to deal with
2383 line_dict = {
2384 "x0": x0,
2385 "y0": page_height - y0,
2386 "x1": x1,
2387 "y1": page_height - y1,
2388 "width": width,
2389 "height": height,
2390 "pts": [(x0, y0), (x1, y1)],
2391 "linewidth": p["width"],
2392 "stroke": True,
2393 "fill": False,
2394 "evenodd": False,
2395 "stroking_color": p["color"] if p["color"] else p["fill"],
2396 "non_stroking_color": None,
2397 "object_type": "line",
2398 "page_number": page_number,
2399 "stroking_pattern": None,
2400 "non_stroking_pattern": None,
2401 "top": y0,
2402 "bottom": y1,
2403 "doctop": y0 + doctop_basis,
2404 }
2405 return line_dict
2406
2407 for p in paths:
2408 items = p["items"] # items in this path

Callers 1

make_edgesFunction · 0.85

Calls 1

is_parallelFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…