Skip to content

[Bug] Shape.area calculates inaccurate cell coverage when constructed with overlapping Regions #6508

@glaziermag

Description

@glaziermag

Title: [Bug] Shape.area calculates inaccurate cell coverage when constructed with overlapping Regions

Description:
The Shape geometric class tracks a collection of Region bounds. Currently, the Shape.area property calculates the aggregate coverage by executing a naive sum over each region's individual area:

    @property
    def area(self) -> int:
        """Cells covered by the shape."""
        # TODO: Currently doesn't handle overlapping regions
        return sum(region.area for region in self._regions)

If a Shape is instantiated with regions that intersect or overlap, the intersection cells are double-counted, resulting in a physically invalid area value that exceeds the genuine logical screen matrix coverage.

Expected Behavior:
The area property should correctly aggregate the union of the regions without double-counting intersections. While rigorous planar geometric unions might be expensive, ensuring Shape.area doesn't balloon past real values is critical for accurate UI layer render bounding.

Environment:

  • Located in src/textual/geometry.py:1364

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions