Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.2.6-beta instead.
Reason given by maintainers: superseded by 0.2.2-Beta

GitHub release (latest by date) license Build Status codecov

pyraxial

An algebraic take on axis-aligned rectangles.

This module aims to simplify working with bounding boxes.

It defines the class Rect with the following methods and attributes:

  • Two binary operators | ("join") and & ("meet").
  • Two identity elements with respect to | and &, Rect.EMPTY and Rect.PLANE.
  • Two polyadic class methods Rect.enclose(rects) and Rect.overlap(rects) as generalizations of | and & over arbitrary numbers of rectangles.
  • A set of operators that define containment relations between rectangles.
  • A class method Rect.closed_regions(rects) that computes the bounding boxes for all subsets of "transitively" overlapping rectangles in a given set of rectangles.

The Rect class together with the | and & operations and the identity elements forms a complete bounded lattice so that for all Rect objects a, b and c the following laws hold:

Identity Elements:

    a | Rect.EMPTY  ≡  a
    a & Rect.PLANE  ≡  a

Absorbing Elements:

    a | Rect.PLANE  ≡  Rect.PLANE
    a & Rect.EMPTY  ≡  Rect.EMPTY

Idempotency:

    a | a  ≡  a
    a & a  ≡  a

Commutativity:

    a | b  ≡  b | a
    a & b  ≡  b & a

Associativity:

    (a | b) | c  ≡  a | (b | c)
    (a & b) & c  ≡  a & (b & c)

Absorption:

    a | (a & b)  ≡  a
    a & (a | b)  ≡  a

Since these laws already define a partially ordered set, the following laws also hold:

Least Element:

    Rect.EMPTY ≦ a

Greatest Element:

    a ≦ Rect.PLANE

Reflexivity:

    a ≦ a

Transitivity:

    a ≦ b  and  b ≦ c   🡒   a ≦ c

Antisymmetry:

    a ≦ b  and  b ≦ a   🡘   a = b

Monotonicity:

    a1 ≦ a2  and  b1 ≦ b2   🡒   a1 | b1  ≦  a2 | b2
    a1 ≦ a2  and  b1 ≦ b2   🡒   a1 & b1  ≦  a2 & b2

Semidistributivity:

    (a & b) | (a & c)  ≦  a & (b | c)
    a | (b & c)  ≦  (a | b) & (a | c)

Notice the absence of the laws of distribution and modularity.

A rectangle is created like so:

    r = Rect(box)

where box is an already existing Rect object, tuple, list, iterator or other iterable, provided it is either empty or contains/yields four numbers that denote the left, top, right and bottom coordinates (in that order). Otherwise, a ValueError is raised.

Coordinate values increase from left to right and from top to bottom. Therefor, if left ≦ right and top ≦ bottom the resulting rectangle will be a Rect with the specified coordinates. If left > right or top > bottom the resulting rectangle will equal Rect.EMPTY.

Rect objects are immutable and the properties have no setters.

All method results are covariant under subtyping.

Rect() and closed_regions() accept any type of iterable. The operators however work reliably only on sequence-like objects, but not iterators. If you pass an iterator as an argument, the behavior will be undefined, probably raising an exception, or worse, causing inexplicably wrong results.

Rects can be used as a drop-in in contexts where paraxial rectangles are represented by 4-tuples, like e.g. Pillow's Image.crop() method. For contexts where such rectangles are represented as pairs of point coordinates the class method Rect.from_points and the Rect.points property can be used.

See API documentation here:

https://pillmuncher.github.io/pyraxial

Metadata

Release files for pyraxial 0.2.1-beta

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyraxial 0.2.1-beta
File Size Uploaded
pyraxial-0.2.1b0.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyraxial 0.2.1-beta
File Interpreter ABI Platform
pyraxial-0.2.1b0-py3-none-any.whl Python 3 none any Details

Total release size: 22.6 kB

Release files / pyraxial-0.2.1b0.tar.gz

Download URL pyraxial-0.2.1b0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c0282a090367cbf89807d26fc0f165196cfeac55f5d11bb263675eb2bd42927a
BLAKE2b-256 checksum
How to use checksums
0386c9163561daeff63b92e552d865a7b1eb02233e8e7cce58aaa16c01d6b82c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / pyraxial-0.2.1b0-py3-none-any.whl

Download URL pyraxial-0.2.1b0-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
519b60a85c13f9a298c349be39891664bba05fb3893735c7b0ae5565cef85aad
BLAKE2b-256 checksum
How to use checksums
27e7b77cd7bbad093fd2bfcd912835e91382c9facedd0fbd3653b862677870f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.2.1-beta This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page