{"id":17036778,"url":"https://github.com/bast/polygons","last_synced_at":"2025-04-12T12:51:33.010Z","repository":{"id":38335178,"uuid":"88614389","full_name":"bast/polygons","owner":"bast","description":"Fast points-in-polygon test and distances to polygons.","archived":false,"fork":false,"pushed_at":"2024-01-31T07:16:51.000Z","size":998,"stargazers_count":12,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-03-23T13:23:11.497Z","etag":null,"topics":["distance","geometry","polygon","pyo3","rust","spacial"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bast.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-18T10:51:07.000Z","updated_at":"2024-03-07T11:41:14.000Z","dependencies_parsed_at":"2024-10-14T08:52:04.244Z","dependency_job_id":"6e45dbba-ba12-4e02-9d5d-fa43cb4808f8","html_url":"https://github.com/bast/polygons","commit_stats":{"total_commits":152,"total_committers":2,"mean_commits":76.0,"dds":0.006578947368421018,"last_synced_commit":"fde8c6b9a09a27f4c5b9d16e1f0a518dc73ea01f"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bast%2Fpolygons","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bast%2Fpolygons/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bast%2Fpolygons/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bast%2Fpolygons/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bast","download_url":"https://codeload.github.com/bast/polygons/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571399,"owners_count":21126517,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distance","geometry","polygon","pyo3","rust","spacial"],"created_at":"2024-10-14T08:51:56.662Z","updated_at":"2025-04-12T12:51:33.005Z","avatar_url":"https://github.com/bast.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![test status](https://github.com/bast/polygons/workflows/Test/badge.svg)](https://github.com/bast/polygons/actions)\n[![license badge](https://img.shields.io/badge/license-%20GPL-blue.svg)](LICENSE)\n[![link to Crates](https://img.shields.io/crates/v/polygons.svg)](https://crates.io/crates/polygons)\n[![link to PyPI](https://badge.fury.io/py/polygons.svg)](https://badge.fury.io/py/polygons)\n[![link to Zenodo/DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3825616.svg)](https://doi.org/10.5281/zenodo.3825616)\n\n\n# Polygons: Fast points-in-polygon test and distances to polygons\n\nComputes distances to polygon edges and vertices and can check whether\npoints are inside/outside.\n\nThis library is optimized to perform well with hundreds or thousands of\npolygons and thousands or millions of points.\n\nExample timings (190 polygons, 1 M reference points, run on 12th Gen Intel i7-12700T at 4.6 GHz):\n- distances to nearest edges: 320 ms\n- distances to nearest vertices: 290 ms\n- check whether points are inside or outside: 45 ms\n\n\n## Installation using pip\n\n```\n$ pip install polygons\n```\n\n## Supported versions\n\n- Python: 3.10 - 3.13\n- Operating systems: Linux, macOS, and Windows\n\n\n## Capabilities\n\n- Check whether points are inside or outside polygons\n- Nearest distances to edges\n- Nearest distances to vertices\n\n\n## Recommended citation\n\nIf you use this tool in a program or publication, please acknowledge its\nauthor(s):\n\n```bibtex\n@misc{polygons,\n  author    = {Bast, Radovan},\n  title     = {Polygons: Fast points-in-polygon test and distances to polygons},\n  month     = {03},\n  year      = {2025},\n  publisher = {Zenodo},\n  version   = {v0.3.5},\n  doi       = {10.5281/zenodo.3825616},\n  url       = {https://doi.org/10.5281/zenodo.3825616}\n}\n```\n\n\n## Python example\n\n```python\nimport polygons\n\n# polygon_points is a list of lists\n# the library has been developed to perform\n# with very many polygons - this is just to have a simple example\n# in this example the polygons have the same number of points but there\n# is no restriction like this, this is only an example\npolygon_points = [\n    [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)],\n    [(0.0, 2.0), (1.0, 2.0), (1.0, 3.0), (0.0, 3.0)],\n]\n\n# the more points you compute in one go, the better\n# here using two points to make a simple example but if you have many points\n# then compute a thousand or a million in one go\n# so that the library can parallelize over the points\npoints = [(0.5, 0.5), (0.5, -0.5)]\n\n# parameters for the tree construction:\n#  - each tree node has 4 children nodes\n#  - each leaf collects 4 edges\n# you can try different parameters and check the timing\n# they (should) have no effect on the results apart from timing\nnum_edges_children = 4\nnum_nodes_children = 4\ntree = polygons.build_search_tree(\n    polygon_points, num_edges_children, num_nodes_children\n)\n\ninside = polygons.points_are_inside(tree, points)\nprint(inside)  # [True, False]\n\n# indices are the indices of the nearest polygon vertices (counted\n# consecutively)\nindices, distances = polygons.distances_nearest_vertices(tree, points)\nprint(indices)  # [0, 0]\nprint(distances)  # [0.7071067811865476, 0.7071067811865476]\n\ndistances = polygons.distances_nearest_edges(tree, points)\nprint(distances)  # [0.5, 0.5]\n\nindices, distances = polygons.distances_nearest_vertices(\n    tree, [(0.6, 0.6), (0.5, -0.5)]\n)\nprint(indices)  # [2, 0]\nprint(distances)  # [0.5656854249492381, 0.7071067811865476]\n```\n\n## References which were used during coding\n\n- \u003chttp://geomalgorithms.com/a03-_inclusion.html\u003e\n- \u003chttps://en.wikipedia.org/wiki/Point_in_polygon\u003e\n- \u003chttps://en.wikipedia.org/wiki/Binary_space_partitioning\u003e\n\n\n## Development notes\n\nRunning the benchmark:\n```\n$ cargo test --release -- --ignored --nocapture\n```\n\nPython interface inspired by https://github.com/dev-cafe/rustafarian.\n\nBuilding and testing the Python interface:\n```\n$ maturin develop\n```\n\n\n## Image\n\nSocial media preview generated using https://github.com/qrohlf/trianglify.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbast%2Fpolygons","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbast%2Fpolygons","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbast%2Fpolygons/lists"}