t# snap_pslg
Refine a planar straight-line graph with iterated snap rounding. No numpy dependency.
- floor all points to integer coordinates
- eliminate edge intersections and t-junctions
- if allowed to converge, no point will be within .5 units of an edge. You can remove this constraint entirely, maintaing more of the input shape at the cost of near t-junctions, by setting max_iterations to 0.
This will slightly distort the pslg, but the result will be ready for triangulation and other algorithms.
install
pip install snap_pslg
signature
Vec2 = Annotated[Iterable[float], "2D vector"]
def snap_round_pslg(
points: Iterable[Vec2], edges: Iterable[tuple[int, int]], max_iterations: int = 100
) -> tuple[list[IntPoint], list[tuple[int, int]]]:
"""Perform one iteration of snap rounding.
:param points: A list of 2D points
:param edges: A list of edges, each a pair of indices into points
:param max_iterations: optionally limit number of iterations to perform. By
default, will try 100 iterations to reach convergence.
:return: A list of 2D points, a list of edges, each a pair of indices into points
Some of the points may not have indices. That is fine.
"""
usage
from snap_pslg import snap_round_pslg
points = [(0, 0), (3, 0), (3, 3), (0, 3), (5, 5)]
edges = [(0, 2), (1, 3)]
# You might have noticed that point (5, 5) was never used. This is fine. It
# will be retained as a point and any line segments that pass very close to it
# will be routed through it.
new_points, new_segments = snap_round_pslg(points, edges)
new_points # [(0, 0), (5, 5), (3, 3), (2, 2), (0, 3), (3, 0)]
new_edges # [(0, 3), (4, 3), (3, 2), (3, 5)]
# a new point, (3, 3) has been added at the segment intersection
# each segment is broken into two pieces
Metadata
Release files for snap-pslg 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| snap_pslg-0.5.0.tar.gz | 9.9 kB | Without provenance | Details for snap_pslg-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snap_pslg-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for snap_pslg-0.5.0-py3-none-any.whl |
Total release size: 23.4 kB
Release files / snap_pslg-0.5.0.tar.gz
| Download URL | snap_pslg-0.5.0.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49065a30444055d1d3b02d194084ffde279593e7fc568ae13a515a710bd665ef
|
|
BLAKE2b-256 checksum How to use checksums |
72ddd5da3766ebe243aab1bf58bc623866fa4c0bfc533f5bbb5c8f49bbe56467
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / snap_pslg-0.5.0-py3-none-any.whl
| Download URL | snap_pslg-0.5.0-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a884c497672a22b92f25b70c2f4962ef0b8d3942042ba125128b87a0c35e4b1a
|
|
BLAKE2b-256 checksum How to use checksums |
3149a73864285050ea008ab51a0cadf726da3854e1a9788a87d27d052bfd11ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for snap-pslg 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.