Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contains method to LTComponent #808

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

Nothing yet.
### Added

- Adds `contains` method to `LTComponent` to check whether it contains another `LTComponent`.

## [20231228]

Expand Down
15 changes: 15 additions & 0 deletions pdfminer/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@ def voverlap(self, obj: "LTComponent") -> float:
else:
return 0

def contains(self, obj: "LTComponent") -> bool:
"""Check whether this object contains another :obj:`LTComponent`.

:param obj: The object to check whether it is contained or not.
:return: :obj:`True` if the object is contained or :obj:`False`
otherwise.
"""
assert isinstance(obj, LTComponent), str(type(obj))
return (
self.x0 <= obj.x0
and self.y0 <= obj.y0
and self.x1 >= obj.x1
and self.y1 >= obj.y1
)


class LTCurve(LTComponent):
"""
Expand Down
Loading