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

Implement contains for BoundingBox #2896

Closed
MicahGale opened this issue Mar 7, 2024 · 1 comment · Fixed by #2906
Closed

Implement contains for BoundingBox #2896

MicahGale opened this issue Mar 7, 2024 · 1 comment · Fixed by #2906

Comments

@MicahGale
Copy link
Contributor

MicahGale commented Mar 7, 2024

Description

Implement __contains__ for BoundingBox containing either a point, or another BoundingBox. This means that users could then write:

if point in box: or if little_box in big_box.

Alternatives

It is possible for users to accomplish this currently but requires some clever coding to avoid becoming difficult to read:

def in_box(point, box):
   for min_p, p, max_p in zip(box.lower_left, point, box.upper_right):
     if p < min_p or > max_p:
        return False 
   return True

Compatibility

This would be an enhancement, and would not alter the behavior of the existing API.

There is a risk though that users will misinterpret the results. A point in the bounding box of a volume may be in the volume, but not necessarily. A user could misuse this information and create problems for themselves. Also a small volume's bounding box can be completely contained in another volume's bounding box, and be completely outside that other volume.

@MicahGale
Copy link
Contributor Author

Turns out this was added for points in #2759 e0d0381, or 0.14.1dev. I will still implement this for nested bounding boxes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant