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.9878715319791809

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.6936232760199346

Compilation

To specify package metadata fastrdp is using the contemporary pyproject.toml. However, to control compilation of the C++ code a legacy setup.py is used.

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 the package build using pyproject.toml was not easy, but these two blog posts helped tremendeously:

In setup.py there is a bootstrap dependency on numpy.

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.0.3.tar.gz (7.9 kB view hashes)

Uploaded Source

Built Distributions

fastrdp-0.0.3-cp311-cp311-win_amd64.whl (13.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

fastrdp-0.0.3-cp311-cp311-musllinux_1_1_x86_64.whl (643.4 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

fastrdp-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (71.7 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

fastrdp-0.0.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (71.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

fastrdp-0.0.3-cp311-cp311-macosx_11_0_arm64.whl (10.1 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

fastrdp-0.0.3-cp311-cp311-macosx_10_14_x86_64.whl (10.3 kB view hashes)

Uploaded CPython 3.11 macOS 10.14+ x86-64

fastrdp-0.0.3-cp310-cp310-win_amd64.whl (13.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

fastrdp-0.0.3-cp310-cp310-musllinux_1_1_x86_64.whl (642.4 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

fastrdp-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (71.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

fastrdp-0.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (70.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

fastrdp-0.0.3-cp310-cp310-macosx_11_0_arm64.whl (10.1 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

fastrdp-0.0.3-cp310-cp310-macosx_10_14_x86_64.whl (10.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.14+ x86-64

fastrdp-0.0.3-cp39-cp39-win_amd64.whl (13.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

fastrdp-0.0.3-cp39-cp39-musllinux_1_1_x86_64.whl (642.1 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

fastrdp-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (71.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

fastrdp-0.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (70.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

fastrdp-0.0.3-cp39-cp39-macosx_11_0_arm64.whl (10.1 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

fastrdp-0.0.3-cp39-cp39-macosx_10_14_x86_64.whl (10.3 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