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

Function jm_checkquad

src/__init__.py:22692–22728  ·  view source on GitHub ↗

Check whether the last 4 lines represent a quad. Because of how we count, the lines are a polyline already, i.e. last point of a line equals 1st point of next line. So we check for a polygon (last line's end point equals start point). If not true we return 0.

(dev)

Source from the content-addressed store, hash-verified

22690
22691
22692def jm_checkquad(dev):
22693 '''
22694 Check whether the last 4 lines represent a quad.
22695 Because of how we count, the lines are a polyline already, i.e. last point
22696 of a line equals 1st point of next line.
22697 So we check for a polygon (last line's end point equals start point).
22698 If not true we return 0.
22699 '''
22700 #log(f'{getattr(dev, "pathdict", None)=}')
22701 items = dev.pathdict[ dictkey_items]
22702 len_ = len(items)
22703 f = [0] * 8 # coordinates of the 4 corners
22704 # fill the 8 floats in f, start from items[-4:]
22705 for i in range( 4): # store line start points
22706 line = items[ len_ - 4 + i]
22707 temp = JM_point_from_py( line[1])
22708 f[i * 2] = temp.x
22709 f[i * 2 + 1] = temp.y
22710 lp = JM_point_from_py( line[ 2])
22711 if lp.x != f[0] or lp.y != f[1]:
22712 # not a polygon!
22713 #dev.linecount -= 1
22714 return 0
22715
22716 # we have detected a quad
22717 dev.linecount = 0 # reset this
22718 # a quad item is ("qu", (ul, ur, ll, lr)), where the tuple items
22719 # are pairs of floats representing a quad corner each.
22720
22721 # relationship of float array to quad points:
22722 # (0, 1) = ul, (2, 3) = ll, (6, 7) = ur, (4, 5) = lr
22723 q = mupdf.fz_make_quad(f[0], f[1], f[6], f[7], f[2], f[3], f[4], f[5])
22724 rect = ('qu', JM_py_from_quad(q))
22725
22726 items[ len_ - 4] = rect # replace item -4 by rect
22727 del items[ len_ - 3 : len_] # delete remaining 3 items
22728 return 1
22729
22730
22731def jm_checkrect(dev):

Callers 1

linetoMethod · 0.85

Calls 2

JM_point_from_pyFunction · 0.85
JM_py_from_quadFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…