Skip to content

grass.pygrass: Support coordinate tuples in Bbox.contains and Area.contains_point - #8025

Merged
echoix merged 2 commits into
OSGeo:mainfrom
bhuvan-somisetty:fix-8024-pygrass-bbox-area-contains-tuple
Oct 18, 2026
Merged

echoix merged 2 commits into
OSGeo:mainfrom
bhuvan-somisetty:fix-8024-pygrass-bbox-area-contains-tuple

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown
Contributor

Description

In python/grass/pygrass/vector/basic.py and python/grass/pygrass/vector/geometry.py, Bbox.contains() and Area.contains_point() document support for passing either 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 without unpacking or checking if a tuple was provided, resulting in an immediate AttributeError: 'tuple' object has no attribute 'x'.

This change:

  • Unpacks coordinates in Bbox.contains() for both Point instances and 2D/3D sequences, raising ValueError on unsupported formats.
  • Uses get_xyz(point) in Area.contains_point() to extract coordinates from both Point and coordinate tuples.
  • Adds unit tests in test_geometry.py covering Bbox.contains() and Area.contains_point() with Point instances, 2D tuples, and 3D tuples.

Motivation and context

This aligns Bbox.contains() and Area.contains_point() with their documented interfaces and allows callers to test point containment using simple coordinate tuples without having to construct Point objects first.

Fixes #8024.

How has this been tested?

Added unit tests in python/grass/pygrass/vector/testsuite/test_geometry.py (AreaTestCase.test_contains_point and BboxTestCase), verified formatting with ruff format --check and linting with ruff check.

Screenshots (if appropriate)

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • PR title provides summary of the changes and starts with one of the pre-defined prefixes
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

…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>
@github-actions github-actions Bot added Python Related code is in Python libraries tests Related to Test Suite labels Oct 5, 2026
Comment thread python/grass/pygrass/vector/basic.py Outdated
Comment thread python/grass/pygrass/vector/geometry.py Outdated
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
echoix merged commit 0e60eb2 into OSGeo:main Oct 18, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] grass.pygrass: Bbox.contains and Area.contains_point fail with AttributeError when passed coordinate tuples

2 participants