Python package for performing set type operations on any layout of discrete space in any dimension.
Project description
blocksets
Python package for performing set type operations on any layout of discrete space in any dimension.
-
Block is an orthogonal clump of units/pixels (i.e. a line segment, rectangle, cuboid, hyper... you get the idea)
-
BlockSet is a set of blocks that resolves any make-up of blocks to a disjoint set in a consistent fashion
Why?
You might choose to use a BlockSet
instead of a regular python set
of
points/pixels because the resolution/granularity is sufficiently high, meaning
the number of pixels/points being modelled due to the expanse of the space
pushes the limits of the available computing power.
How?
- Create any layout (as a blockset) using a stacked list of block operations
which
add
remove
ortoggle
blocks over the current blockset state. - Perform the usual set arithmetic
union
intersection
difference
etc. on blockset objects. - Compare 2 blockset objects using the standard set comparison methods and
operators
==
<=
>=
. - Results are always consistent regardless of how they were constructed.
Installation
Requires python 3.11 or higher, there are no dependencies.
pip install blocksets
Usage
Full documentation is available (work in progress) at readthedocs
It's worth reviewing and running the example_use.py
module via
python -m blocksets.example_use
TL;DR
from blocksets import Block, BlockSet
# A block is defined by the co-ordinates of the opposite corners
big_rubik = Block((0, 0, 0), (99999, 99999, 99999))
assert big_rubik.measure == 999970000299999
# A single argument is a unit block
centre_cube = Block((49999, 49999, 49999))
assert centre_cube.measure == 1
# Create a large 3 dimensional cube with the centre missing
bs = BlockSet(3)
bs.add(big_rubik)
bs.remove(centre_cube)
assert bs.measure == 999970000299998
assert len(bs) == 6
sorted_blocks = sorted(bs, key=lambda x: x.norm)
for blk in sorted_blocks:
print(f"{blk:50} {blk.measure}")
The resulting space is modelled using 6 objects (effectively tuples) instead of 999970000299998
(0, 0, 0)..(49999, 99999, 99999) 499980000249999
(49999, 0, 0)..(50000, 49999, 99999) 4999850001
(49999, 49999, 0)..(50000, 50000, 49999) 49999
(49999, 49999, 50000)..(50000, 50000, 99999) 49999
(49999, 50000, 0)..(50000, 99999, 99999) 4999850001
(50000, 0, 0)..(99999, 99999, 99999) 499980000249999
Visualisation
An example of 2D set operations on some randomly generated block sets A, B and
drawn using matplotlib
.
Contribution
At the moment it is early days so whilst the foundations are forming I am only inviting comments which can be given via github issues
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
Built Distribution
File details
Details for the file blocksets-0.1.13.tar.gz
.
File metadata
- Download URL: blocksets-0.1.13.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 987e0f5ce30a5aebe862f2b1f830e4b5f1ee248aee487c4d767046a50512916e |
|
MD5 | f17e8bec259f99e22b71f7a145526a49 |
|
BLAKE2b-256 | 4dd3c9520f5f1661e902ea4f366ec1d5999713595e28842320f6cf326ec6579d |
File details
Details for the file blocksets-0.1.13-py3-none-any.whl
.
File metadata
- Download URL: blocksets-0.1.13-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0ec7e4899f88e07d4a38607a993c0d9161c57634b3e385c69ea4cd5d0956b41 |
|
MD5 | 50c69ee9f153e8394ec1505f5fd95bad |
|
BLAKE2b-256 | aba5da6bfb3430a3e106d8294c7e371591f50b6500aebe704f87554af8616896 |