1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
# pypathlib
[](https://circleci.com/gh/nschloe/pypathlib/tree/master)
[](https://codecov.io/gh/nschloe/pypathlib)
[](https://github.com/psf/black)
[](https://pypi.org/project/pypathlib)
[](https://tracker.debian.org/pkg/python-pypathlib)
[](https://github.com/nschloe/pypathlib)
[](https://pypistats.org/packages/pypathlib)
Lightweight package for working with 2D paths/polygons.
```python
import pypathlib
# Create path
path = pypathlib.ClosedPath([[0, 0], [0, 1], [1, 1], [1, 0]])
# Get the squared distance of some points to the path
path.squared_distance([[0.5, 0.5], [0.1, 2.4]])
# Get the _signed_ squared distance of some points to the path
# (negative if inside the path)
path.signed_squared_distance([[0.5, 0.5], [0.1, 2.4]])
# Check if the path contains the points
# (with a tolerance; set negative if you want to exclude the boundary)
path.contains_points([[0.5, 0.5], [0.1, 2.4]], tol=1.0e-12)
```
pypathlib is fully vectorized, so it's pretty fast. (Not quite as fast as
[`mathplotlib.path.contains_points`](https://matplotlib.org/api/path_api.html#matplotlib.path.Path.contains_points)
though.)
### Relevant publications
* [S.W. Sloan, _A point-in-polygon program_. Adv. Eng. Software, Vol 7, No. 1, pp.
45-47, 1985, 10.1016/0141-1195(85)90094-4](https://doi.org/10.1016/0141-1195(85)90094-4).
### Installation
pypathlib is [available from the Python Package
Index](https://pypi.org/project/pypathlib/), so simply type
```
pip install -U pypathlib --user
```
to install or upgrade.
### Testing
To run the pypathlib unit tests, check out this repository and type
```
pytest
```
### Distribution
To create a new release
1. bump the `__version__` number,
2. publish to PyPi and GitHub:
```
make publish
```
### License
pypathlib is published under the [MIT license](https://en.wikipedia.org/wiki/MIT_License).
|