MCPcopy Create free account
hub / github.com/Layout-Parser/layout-parser / union

Method union

src/layoutparser/elements/layout_elements.py:690–715  ·  view source on GitHub ↗
(self, other: BaseCoordElement, strict: bool = True)

Source from the content-addressed store, hash-verified

688
689 @support_textblock
690 def union(self, other: BaseCoordElement, strict: bool = True):
691 """"""
692 if isinstance(other, Interval):
693 return other.intersect(self)
694
695 elif isinstance(other, Rectangle):
696 return self.__class__(
697 min(self.x_1, other.x_1),
698 min(self.y_1, other.y_1),
699 max(self.x_2, other.x_2),
700 max(self.y_2, other.y_2),
701 )
702
703 elif isinstance(other, Quadrilateral):
704 if strict:
705 raise NotSupportedShapeError(
706 "The intersection between an Interval and a Quadrilateral might generate Polygon shapes that are not supported in the current version of layoutparser. You can pass `strict=False` in the input that converts the Quadrilateral to Rectangle to avoid this Exception."
707 )
708 else:
709 warnings.warn(
710 f"With `strict=False`, the other of shape {other.__class__} will be converted to {Rectangle} for obtaining the intersection"
711 )
712 return self.union(other.to_rectangle())
713
714 else:
715 raise Exception(f"Invalid input type {other.__class__} for other")
716
717 def pad(self, left=0, right=0, top=0, bottom=0, safe_mode=True):
718

Callers 1

test_shape_operationsFunction · 0.95

Calls 3

intersectMethod · 0.45
to_rectangleMethod · 0.45

Tested by 1

test_shape_operationsFunction · 0.76