Metadata-Version: 2.4
Name: extremitypathfinder
Version: 4.0.0
Summary: python package for fast shortest path computation on 2D polygon or grid maps
Keywords: path-planning,path-finding,shortest-path,visibility,graph,polygon,grid,map,robotics,navigation,offline
Author: Jannik Kissinger
Author-email: Jannik Kissinger <github@michelfe.it>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Python :: Free Threading :: 3 - Stable
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Education
Classifier: Topic :: Games/Entertainment
Requires-Dist: numpy>=2.3.3,<3
Requires-Dist: networkx>=3,<4 ; extra == 'networkx'
Requires-Dist: numba>=0.63,<1 ; extra == 'numba'
Requires-Dist: shapely>=2.0.6,<3 ; extra == 'shapely'
Requires-Python: >=3.12, <4
Project-URL: Homepage, https://extremitypathfinder.readthedocs.io/en/latest/
Project-URL: Documentation, https://extremitypathfinder.readthedocs.io/en/latest/
Project-URL: Repository, https://github.com/jannikmi/extremitypathfinder
Provides-Extra: networkx
Provides-Extra: numba
Provides-Extra: shapely
Description-Content-Type: text/x-rst

===================
extremitypathfinder
===================

..
    Note: can't include the badges file from the docs here, as it won't render on PyPI -> sync manually


.. image:: https://github.com/jannikmi/extremitypathfinder/actions/workflows/build.yml/badge.svg?branch=master
    :alt: CI status
    :target: https://github.com/jannikmi/extremitypathfinder/actions?query=branch%3Amaster

.. image:: https://readthedocs.org/projects/extremitypathfinder/badge/?version=latest
    :alt: documentation status
    :target: https://extremitypathfinder.readthedocs.io/en/latest/?badge=latest

.. image:: https://img.shields.io/pypi/v/extremitypathfinder.svg
    :alt: latest version on PyPI
    :target: https://pypi.python.org/pypi/extremitypathfinder

.. image:: https://img.shields.io/pypi/pyversions/extremitypathfinder.svg
    :alt: supported Python versions
    :target: https://pypi.python.org/pypi/extremitypathfinder

.. image:: https://static.pepy.tech/badge/extremitypathfinder
    :alt: total PyPI downloads
    :target: https://pepy.tech/projects/extremitypathfinder

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
    :alt: pre-commit
    :target: https://github.com/pre-commit/pre-commit

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
    :alt: code style: ruff
    :target: https://github.com/astral-sh/ruff


Python package for fast geometric shortest path computation in 2D multi-polygon or grid environments
based on visibility graphs.

Exact Euclidean shortest paths with ``pip install``, on the polygons you already have:
touching and overlapping polygons and grids are used as they are, with well-defined and tested behaviour
at contacts and other edge cases (`what sets it apart <https://extremitypathfinder.readthedocs.io/en/latest/9_alternatives.html>`__).

.. image:: https://raw.githubusercontent.com/jannikmi/extremitypathfinder/master/docs/_static/demo.svg
    :alt: shortest path through a polygon environment


Features
--------

- **Exact shortest paths**: the Euclidean shortest path between any two points of the free space,
  not an approximation on a grid or mesh.
- **Fast repeated queries**: the visibility graph of an environment is computed once,
  each query then only connects its start and goal to it.
  Only the protruding corners ("extremities") become graph nodes, which keeps the graph small.
- **Polygon environments**: a boundary polygon with holes, or holes only (unbounded environments).
  Polygons may touch and overlap each other. Touching obstacles form a wall that paths cannot pass.
  The polygons are used directly: no triangulation or navigation mesh is needed.
- **Grids**: convert a grid with blocked cells into a polygon environment.
- **Shapely and GeoJSON input** (optional): pass Shapely geometries, GeoJSON or GeoPandas geometries directly.
  Agents with a size keep a clearance to the obstacles when these are inflated with Shapely (documented recipe).
- **Well-defined edge cases**: touching obstacles, points on edges and collinear vertices follow one set of rules.
  The floating point decisions are audited against exact arithmetic, the results are identical with and without Numba.
- **Few dependencies**: only NumPy. Optional `Numba <https://numba.pydata.org/>`__ acceleration,
  export of the visibility graph to NetworkX.
- **Extras**: input validation, plotting (Matplotlib), saving prepared environments to a file,
  and a command line interface.


Installation
------------

.. code-block:: console

    pip install extremitypathfinder

.. benchmark-derived: the speed-up by Numba. Update this text with every full benchmark run
   (docs/contributing/performance.md, "After a full run").

With the optional Numba extra for a significant speedup
(larger installation, initial compilation time):

.. code-block:: console

    pip install "extremitypathfinder[numba]"

Python 3.12 or newer is required (CI tests CPython 3.12–3.15).
Dependencies: NumPy >=2.3.3,<3 (NetworkX 3.x with the optional ``networkx`` extra).
Cf. `supported versions and dependencies
<https://extremitypathfinder.readthedocs.io/en/latest/0_getting_started.html#supported-versions-and-dependencies>`__
for the support policy.


Quick Start
-----------

Polygon environment
~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    from extremitypathfinder import PolygonEnvironment

    # the boundary polygon (clockwise or counter clockwise vertex numbering)
    boundary_coordinates = [(0.0, 0.0), (10.0, 0.0), (9.0, 5.0), (10.0, 10.0), (0.0, 10.0)]
    # the holes (obstacles)
    list_of_holes = [
        [
            (3.0, 7.0),
            (5.0, 9.0),
            (4.5, 7.0),
            (5.0, 4.0),
        ],
    ]
    # computes the visibility graph once
    environment = PolygonEnvironment(boundary_coordinates, list_of_holes)

    # fast consecutive queries
    path, length = environment.find_shortest_path((4.5, 1.0), (4.0, 8.5))
    # path: [(4.5, 1.0), (3.0, 7.0), (4.0, 8.5)], length: 7.987...

``path`` is ``[]`` and ``length`` is ``None`` when there is no path between start and goal.
The input polygons are validated by default (self intersections, overlapping edges, ...) and invalid input raises a ``ValueError``.
The validation costs little compared to the preparation of the environment.
For trusted input it can be skipped (``validate=False``).

Grid environment
~~~~~~~~~~~~~~~~

Coordinates refer to the corners of the grid cells, i.e. cell ``(x, y)`` spans ``[x, x+1] x [y, y+1]``:

.. code-block:: python

    size_x, size_y = 5, 3
    obstacle_iter = [(2, 1), (3, 1)]  # blocked grid cells (x, y)
    environment = PolygonEnvironment.from_grid(size_x, size_y, obstacle_iter)
    path, length = environment.find_shortest_path((0.5, 0.5), (4.5, 2.5))
    # path: [(0.5, 0.5), (2.0, 2.0), (4.5, 2.5)], length: 4.670...

Command line
~~~~~~~~~~~~

Environments stored as JSON (cf. ``example.json``) can be queried from the command line:

.. code-block:: console

    extremitypathfinder ./example.json -s 2.5 3.2 -g 7.9 6.8


Documentation
-------------

The `documentation <https://extremitypathfinder.readthedocs.io/en/latest/>`__ covers:

- `Usage <https://extremitypathfinder.readthedocs.io/en/latest/1_usage.html>`__:
  all features, the input requirements, plotting and caching
- `Upgrading from 2.x or 3.x <https://extremitypathfinder.readthedocs.io/en/latest/2_upgrading.html>`__
- `About <https://extremitypathfinder.readthedocs.io/en/latest/3_about.html>`__:
  how it works and the handling of touching obstacles
- `Engineering Design <https://extremitypathfinder.readthedocs.io/en/latest/8_design.html>`__:
  the architecture and the algorithms
- `Alternatives <https://extremitypathfinder.readthedocs.io/en/latest/9_alternatives.html>`__:
  similar packages and how they differ
- `API reference <https://extremitypathfinder.readthedocs.io/en/latest/4_api.html>`__


Citing
------

If you use ``extremitypathfinder`` in your research, please cite it.
The citation metadata is in
`CITATION.cff <https://github.com/jannikmi/extremitypathfinder/blob/master/CITATION.cff>`__:
GitHub converts it into APA and BibTeX ("Cite this repository" in the sidebar of the repository).
Please cite the version you used.


Contributing and License
------------------------

Contributions are welcome: see the
`contribution guidelines <https://extremitypathfinder.readthedocs.io/en/latest/5_contributing.html>`__
and the `issue tracker <https://github.com/jannikmi/extremitypathfinder/issues>`__.
Questions and requests for help go to the issue tracker as well.

``extremitypathfinder`` is distributed under the terms of the MIT license
(`LICENSE <https://github.com/jannikmi/extremitypathfinder/blob/master/LICENSE>`__).

Also see:
`GitHub <https://github.com/jannikmi/extremitypathfinder>`__,
`PyPI <https://pypi.python.org/pypi/extremitypathfinder/>`__,
`Changelog <https://extremitypathfinder.readthedocs.io/en/latest/6_changelog.html>`__
