Computes distances to polygon edges and vertices and can check whether points are inside/outside.
$ pip install polygons
If you use this tool in a program or publication, please acknowledge its author(s):
bibtex
@misc{polygons,
author = {Bast, Radovan},
title = {Polygons: Fast points-in-polygon test and distances to polygons},
month = {2},
year = {2021},
publisher = {Zenodo},
version = {v0.2.0},
doi = {10.5281/zenodo.3825616},
url = {https://doi.org/10.5281/zenodo.3825616}
}
```python import polygons
polygon_points = [ [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)], [(0.0, 2.0), (1.0, 2.0), (1.0, 3.0), (0.0, 3.0), (0.0, 2.0)], ]
points = [(0.5, 0.5), (0.5, -0.5)]
numedgeschildren = 4 numnodeschildren = 4 tree = polygons.buildsearchtree( polygonpoints, numedgeschildren, numnodes_children )
inside = polygons.pointsareinside(tree, points) print(inside) # [True, False]
indices, distances = polygons.distancesnearestvertices(tree, points) print(indices) # [0, 0] print(distances) # [0.7071067811865476, 0.7071067811865476]
distances = polygons.distancesnearestedges(tree, points) print(distances) # [0.5, 0.5]
indices, distances = polygons.distancesnearestvertices( tree, [(0.6, 0.6), (0.5, -0.5)] ) print(indices) # [2, 0] print(distances) # [0.5656854249492381, 0.7071067811865476] ```
Running the benchmark:
$ cargo test --release -- --ignored --nocapture
Python interface inspired by https://github.com/dev-cafe/rustafarian.
Building and testing the Python interface:
$ cargo build --release --features pyo3
$ maturin develop --release --cargo-extra-args="--features pyo3"