Repository navigation
grass.pygrass: Support coordinate tuples in Bbox.contains and Area.contains_point - #8025
Merged
echoix merged 2 commits intoOct 18, 2026
Conversation
…ntains_point In `python/grass/pygrass/vector/basic.py` and `python/grass/pygrass/vector/geometry.py`, `Bbox.contains()` and `Area.contains_point()` document that the `point` argument can be a `Point` object or a coordinate tuple (e.g. `(x, y)` or `(x, y, z)`). However, both methods previously accessed `point.x`, `point.y`, and `point.z` directly, raising an `AttributeError` when a tuple was passed. Fix this by: - Unpacking coordinates in `Bbox.contains()` for both `Point` instances and 2D/3D coordinate sequences, raising `ValueError` on invalid formats. - Using `get_xyz(point)` in `Area.contains_point()`. - Adding unit tests for coordinate tuple support in `test_geometry.py`. Fixes OSGeo#8024. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
echoix
reviewed
Oct 12, 2026
Convert the coordinates to float before calling the C functions so that non-numeric input raises a clear ValueError. Avoid naming the unused z coordinate _, which would shadow the gettext function.
echoix
approved these changes
Oct 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In
python/grass/pygrass/vector/basic.pyandpython/grass/pygrass/vector/geometry.py,Bbox.contains()andArea.contains_point()document support for passing either aPointobject or a coordinate tuple (e.g.(x, y)or(x, y, z)).However, both methods previously accessed
point.x,point.y, andpoint.zdirectly without unpacking or checking if a tuple was provided, resulting in an immediateAttributeError: 'tuple' object has no attribute 'x'.This change:
Bbox.contains()for bothPointinstances and 2D/3D sequences, raisingValueErroron unsupported formats.get_xyz(point)inArea.contains_point()to extract coordinates from bothPointand coordinate tuples.test_geometry.pycoveringBbox.contains()andArea.contains_point()withPointinstances, 2D tuples, and 3D tuples.Motivation and context
This aligns
Bbox.contains()andArea.contains_point()with their documented interfaces and allows callers to test point containment using simple coordinate tuples without having to constructPointobjects first.Fixes #8024.
How has this been tested?
Added unit tests in
python/grass/pygrass/vector/testsuite/test_geometry.py(AreaTestCase.test_contains_pointandBboxTestCase), verified formatting withruff format --checkand linting withruff check.Screenshots (if appropriate)
N/A
Types of changes
Checklist