Skip to main content

An algebraic take on axis-aligned rectangles.

Reason this release was yanked:

superseded by 0.2.5-beta

Project description

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 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 axis-aligned 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyraxial-0.2.4b0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

pyraxial-0.2.4b0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file pyraxial-0.2.4b0.tar.gz.

File metadata

  • Download URL: pyraxial-0.2.4b0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pyraxial-0.2.4b0.tar.gz
Algorithm Hash digest
SHA256 2ce138eaea825a7ee5cedcef9e96e6d615d4b323714cea2bdf5a3c775f453072
MD5 5c6900443468b28372e67f5f8b92bdcd
BLAKE2b-256 ec86950d53c446b54ce991d116e7a3f7c1df72f2b5f0dee6f4cc8204b1d6780e

See more details on using hashes here.

File details

Details for the file pyraxial-0.2.4b0-py3-none-any.whl.

File metadata

  • Download URL: pyraxial-0.2.4b0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pyraxial-0.2.4b0-py3-none-any.whl
Algorithm Hash digest
SHA256 738168a2450acad03084c7694d79fa48d45324afad37f2e1127b9e7ad4840cd1
MD5 bd1560a863b0f21d6c24d4ff81eb8d13
BLAKE2b-256 4d9fc83ea965102a7ffcae5e12ff714fc769dc602b489b23d1dae799ce41339b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page