Create a matplotlib patch for the element Args: geometry: bounding box (straight or rotated) of the element page_dimensions: dimensions of the page in format (height, width) **kwargs: keyword arguments for the patch Returns: a matplotlib Patch
(
geometry: BoundingBox | Polygon4P | np.ndarray,
page_dimensions: tuple[int, int],
**kwargs: Any,
)
| 110 | |
| 111 | |
| 112 | def create_obj_patch( |
| 113 | geometry: BoundingBox | Polygon4P | np.ndarray, |
| 114 | page_dimensions: tuple[int, int], |
| 115 | **kwargs: Any, |
| 116 | ) -> patches.Patch: |
| 117 | """Create a matplotlib patch for the element |
| 118 | |
| 119 | Args: |
| 120 | geometry: bounding box (straight or rotated) of the element |
| 121 | page_dimensions: dimensions of the page in format (height, width) |
| 122 | **kwargs: keyword arguments for the patch |
| 123 | |
| 124 | Returns: |
| 125 | a matplotlib Patch |
| 126 | """ |
| 127 | if isinstance(geometry, tuple): |
| 128 | if len(geometry) == 2: # straight word BB (2 pts) |
| 129 | return rect_patch(geometry, page_dimensions, **kwargs) |
| 130 | elif len(geometry) == 4: # rotated word BB (4 pts) |
| 131 | return polygon_patch(np.asarray(geometry), page_dimensions, **kwargs) |
| 132 | elif isinstance(geometry, np.ndarray) and geometry.shape == (4, 2): # rotated line |
| 133 | return polygon_patch(geometry, page_dimensions, **kwargs) |
| 134 | raise ValueError("invalid geometry format") |
| 135 | |
| 136 | |
| 137 | def get_colors(num_colors: int) -> list[tuple[float, float, float]]: |
no test coverage detected