simplify a pslg with iterated snap rounding
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
snap_pslg-0.3.0.tar.gz
(11.5 kB
view details)
Built Distribution
snap_pslg-0.3.0-py3-none-any.whl
(13.2 kB
view details)
File details
Details for the file snap_pslg-0.3.0.tar.gz
.
File metadata
- Download URL: snap_pslg-0.3.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.2 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f14e9f0d9b1e5ffbc7c5ce8c32cd1ce798095d5a982e7be3524a8d6ebfda011b |
|
MD5 | a8a11d3f681180dff2272b92c9c66e3e |
|
BLAKE2b-256 | 6023aa63bef8d7332fb40a6f00ac2392e0c8ccef796ae80be325ef0ba0b23018 |
File details
Details for the file snap_pslg-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: snap_pslg-0.3.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.2 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a4bbde0a341021f28221321bef678114df1c7b980d438a89cec4362e2f1833e |
|
MD5 | 84931f63d6e9b59cfc14238fb0b669dd |
|
BLAKE2b-256 | c77d21c6c4c0a5228cef54f13fcec85d51da1fedd6cd7ae05f2d36f84acc2245 |