Skip to content

Commit

Permalink
Update regions from sixel branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
salt-die committed Nov 26, 2024
1 parent 994f7a5 commit 01c5f2f
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 258 deletions.
13 changes: 13 additions & 0 deletions src/batgrl/geometry/regions.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cdef struct Band:
int y1, y2
Py_ssize_t size, len
int* walls


cdef struct CRegion:
Py_ssize_t size, len
Band* bands


cdef class Region:
cdef CRegion cregion
41 changes: 8 additions & 33 deletions src/batgrl/geometry/regions.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Functions and classes for determining gadget regions.
Notes
-----
A gadget's region is calculated as a first step in compositing to determine its visible
area in the terminal.
Expand Down Expand Up @@ -46,39 +48,15 @@ bottom y-coordinate. And finally, Regions are a sorted list of non-intersecting
"""

from collections.abc import Iterator
from typing import Self

from .basic import Point, Size

__all__ = ["Region"]

class _Band:
"""A row of mutually exclusive rects."""

y1: int
"""The y-coordinate of the top of the band."""
y2: int
"""The y-coordinate of the bottom of the band."""
walls: list[int]
"""
Each contiguous pair of ints in `walls` represent the left and right side of a rect
in the band.
"""

class Region:
"""
Collection of mutually exclusive bands of rects.
Parameters
----------
bands : list[_Band], default: []
Bands that make up the region.
Attributes
----------
bands : list[_Band]
Bands that make up the region.
Methods
-------
rects()
Expand All @@ -87,22 +65,19 @@ class Region:
Return a new region from a rect position and size.
"""

bands: list[_Band]
"""Bands that make up the region."""

def __and__(self, other: Self) -> Self:
def __and__(self, other: Region) -> Region:
"""Return the intersection of self and other."""

def __or__(self, other: Self) -> Self:
def __or__(self, other: Region) -> Region:
"""Return the union of self and other."""

def __add__(self, other: Self) -> Self:
def __add__(self, other: Region) -> Region:
"""Return the union of self and other."""

def __sub__(self, other: Self) -> Self:
def __sub__(self, other: Region) -> Region:
"""Return the difference of self and other."""

def __xor__(self, other: Self) -> Self:
def __xor__(self, other: Region) -> Region:
"""Return the symmetric difference of self and other."""

def __bool__(self) -> bool:
Expand All @@ -122,7 +97,7 @@ class Region:
"""

@classmethod
def from_rect(cls, pos: Point, size: Size) -> Self:
def from_rect(cls, pos: Point, size: Size) -> Region:
"""
Return a region from a rect position and size.
Expand Down
Loading

0 comments on commit 01c5f2f

Please sign in to comment.