MCPcopy
hub / github.com/datalab-to/marker / PolygonBox

Class PolygonBox

marker/schema/polygon.py:9–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8
9class PolygonBox(BaseModel):
10 polygon: List[List[float]]
11
12 @field_validator('polygon')
13 @classmethod
14 def check_elements(cls, v: List[List[float]]) -> List[List[float]]:
15 if len(v) != 4:
16 raise ValueError('corner must have 4 elements')
17
18 for corner in v:
19 if len(corner) != 2:
20 raise ValueError('corner must have 2 elements')
21
22 min_x = min([corner[0] for corner in v])
23 min_y = min([corner[1] for corner in v])
24
25 # Ensure corners are clockwise from top left
26 corner_error = f" .Corners are {v}"
27 assert v[2][1] >= min_y, f'bottom right corner should have a greater y value than top right corner' + corner_error
28 assert v[3][1] >= min_y, 'bottom left corner should have a greater y value than top left corner' + corner_error
29 assert v[1][0] >= min_x, 'top right corner should have a greater x value than top left corner' + corner_error
30 assert v[2][0] >= min_x, 'bottom right corner should have a greater x value than bottom left corner' + corner_error
31 return v
32
33 @property
34 def height(self):
35 return self.bbox[3] - self.bbox[1]
36
37 @property
38 def width(self):
39 return self.bbox[2] - self.bbox[0]
40
41 @property
42 def area(self):
43 return self.width * self.height
44
45 @property
46 def center(self):
47 return [(self.bbox[0] + self.bbox[2]) / 2, (self.bbox[1] + self.bbox[3]) / 2]
48
49 @property
50 def size(self):
51 return [self.width, self.height]
52
53 @property
54 def x_start(self):
55 return self.bbox[0]
56
57 @property
58 def y_start(self):
59 return self.bbox[1]
60
61 @property
62 def x_end(self):
63 return self.bbox[2]
64
65 @property
66 def y_end(self):

Callers 10

add_blocks_to_pagesMethod · 0.90
get_all_linesMethod · 0.90
spans_from_html_charsMethod · 0.90
__call__Method · 0.90
expandMethod · 0.85
expand_y2Method · 0.85
expand_y1Method · 0.85
rescaleMethod · 0.85
fit_to_boundsMethod · 0.85
mergeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…