Python package for performing set type operations on any layout of discrete space in any dimension.
Project description
blocksets
A python package for performing set operations on layouts 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 takes a layout and resolves it to a disjoint set of Blocks in a consistent fashion, regardless of how the layout was composed.
Why?
You might choose to use a BlockSet
instead of a set
of tuples because the
resolution/granularity is sufficiently high to warrant it.
Or in other words, the number of pixels/points being modelled pushes the limits of the available computing power due to the expanse of the space they take up.
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
blocksets is available on pypi.org and can be installed using pip (there are no dependent packages).
pip install blocksets
Usage
Visit readthedocs
Review and run the example_use.py
module via python -m blocksets.example_use
for a few examples, one of which follows here.
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
. See
readthedocs
for code snippet to generate this
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.3.0.tar.gz
.
File metadata
- Download URL: blocksets-0.3.0.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47067056c3d6bab52c54dad7de7407e2751b4acb0990a53dd282c5562f2b09e8 |
|
MD5 | 8f6b8c52d5b473c9bac613eb5e9d8300 |
|
BLAKE2b-256 | 1083d4aca315892bab119742f331860b14181b2577e025148d6367e869b93b4e |
File details
Details for the file blocksets-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: blocksets-0.3.0-py3-none-any.whl
- Upload date:
- Size: 15.9 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 | 199d2a1d4766af531d5320aa9231eb45bd2bf3e06ec6a323fea2415d5e5e7052 |
|
MD5 | 309dccbb48c7a8b5c8bbba0f1df701c5 |
|
BLAKE2b-256 | 5a16883c8f3f7c74a5f856b5dd6386cb2448013b48ebfea6123f650fa602fcfd |