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

Class Shape

src/__init__.py:14832–15819  ·  view source on GitHub ↗

Create a new shape.

Source from the content-addressed store, hash-verified

14830
14831
14832class Shape:
14833 """Create a new shape."""
14834
14835 @staticmethod
14836 def horizontal_angle(C, P):
14837 """Return the angle to the horizontal for the connection from C to P.
14838 This uses the arcus sine function and resolves its inherent ambiguity by
14839 looking up in which quadrant vector S = P - C is located.
14840 """
14841 S = Point(P - C).unit # unit vector 'C' -> 'P'
14842 alfa = math.asin(abs(S.y)) # absolute angle from horizontal
14843 if S.x < 0: # make arcsin result unique
14844 if S.y <= 0: # bottom-left
14845 alfa = -(math.pi - alfa)
14846 else: # top-left
14847 alfa = math.pi - alfa
14848 else:
14849 if S.y >= 0: # top-right
14850 pass
14851 else: # bottom-right
14852 alfa = -alfa
14853 return alfa
14854
14855 def __init__(self, page: Page):
14856 CheckParent(page)
14857 self.page = page
14858 self.doc = page.parent
14859 if not self.doc.is_pdf:
14860 raise ValueError("is no PDF")
14861 self.height = page.mediabox_size.y
14862 self.width = page.mediabox_size.x
14863 self.x = page.cropbox_position.x
14864 self.y = page.cropbox_position.y
14865
14866 self.pctm = page.transformation_matrix # page transf. matrix
14867 self.ipctm = ~self.pctm # inverted transf. matrix
14868
14869 self.draw_cont = ""
14870 self.text_cont = ""
14871 self.totalcont = ""
14872 self.last_point = None
14873 self.rect = None
14874
14875 def updateRect(self, x):
14876 if self.rect is None:
14877 if len(x) == 2:
14878 self.rect = Rect(x, x)
14879 else:
14880 self.rect = Rect(x)
14881
14882 else:
14883 if len(x) == 2:
14884 x = Point(x)
14885 self.rect.x0 = min(self.rect.x0, x.x)
14886 self.rect.y0 = min(self.rect.y0, x.y)
14887 self.rect.x1 = max(self.rect.x1, x.x)
14888 self.rect.y1 = max(self.rect.y1, x.y)
14889 else:

Callers 1

new_shapeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…