Skip to main content

Implementation of the Ramer-Douglas-Peucker algorithm

Project description

fastrdp

PyPI Latest Release

The fastrdp package contains an implementation of the Ramer–Douglas–Peucker algorithm for reducing the number of points in a curve.

Example

There is a single function in the fastrdp package. Here is an example from the Wikipedia page linked to above with a description of the algorithm. The original line is black and the approximating line is red.

import matplotlib.pyplot as plt
import numpy as np
import fastrdp

x = np.linspace(0, 5, 10_000)
y = np.exp(-x) * np.cos(2 * np.pi * x)
x_new, y_new = fastrdp.rdp(x, y, 0.06)

fig, ax = plt.subplots()
ax.plot(x, y, color='black', linewidth=2.0)
ax.plot(x_new, y_new, linestyle='dashed', color='red')
plt.show()

Performance

Here we compare the performance of fastrdp with that of a pure Python implementation. The example above is executed with fastrdp in less than a millisecond on my machine

from timeit import timeit
timeit(lambda: fastrdp.rdp(x, y, 0.1), number=10_000)
0.9715354799991474

The pure Python implementation in the rdp package takes more than a second to finish the same computation

import rdp
z = np.column_stack((x, y))
timeit(lambda: rdp.rdp(z, epsilon=0.1), number=1)
1.636681150062941

To illustrate how fastrdp scales consider the following graph that shows execution time for an increasing number of random input points. The figure is produced with the scripts in the performance folder.

Compilation

To specify package metadata fastrdp is using the contemporary pyproject.toml. Execute the following commands to build and install fastrdp

pip install .

If you want an editable installation, then add a -e to the last command. To also install the optional dependencies used for development add a little extra:

pip install -e '.[dev]'

The single quotes are needed in zsh, but is perhaps superfluous in other shells.

Acknowledgements

Setting up package metadata to build and compile fastrdp is inspired by the pybind11 example package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastrdp-0.1.0.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distributions

fastrdp-0.1.0-cp311-cp311-win_amd64.whl (64.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

fastrdp-0.1.0-cp311-cp311-musllinux_1_1_x86_64.whl (613.5 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

fastrdp-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (97.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

fastrdp-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (95.1 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

fastrdp-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (61.8 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

fastrdp-0.1.0-cp311-cp311-macosx_10_14_x86_64.whl (64.8 kB view hashes)

Uploaded CPython 3.11 macOS 10.14+ x86-64

fastrdp-0.1.0-cp310-cp310-win_amd64.whl (63.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

fastrdp-0.1.0-cp310-cp310-musllinux_1_1_x86_64.whl (612.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

fastrdp-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (95.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

fastrdp-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (93.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

fastrdp-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (60.6 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

fastrdp-0.1.0-cp310-cp310-macosx_10_14_x86_64.whl (63.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.14+ x86-64

fastrdp-0.1.0-cp39-cp39-win_amd64.whl (63.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

fastrdp-0.1.0-cp39-cp39-musllinux_1_1_x86_64.whl (612.4 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

fastrdp-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (96.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

fastrdp-0.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (93.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

fastrdp-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (60.7 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

fastrdp-0.1.0-cp39-cp39-macosx_10_14_x86_64.whl (63.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page