Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix ci, export LineSegment, release 0.1.0 #4

Merged
merged 7 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ build_script:
- ps: |
python -m build -s
cd dist
python -m pip install --verbose pybind11_rdp-0.0.2.tar.gz
python -m pip install --verbose pybind11_rdp-0.1.0.tar.gz
cd ..
test_script:
- ps: python -m pytest
2 changes: 2 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
- uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: auto universal2
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
CIBW_SKIP: pp*

- name: Verify clean directory
run: git diff --exit-code
Expand Down
2 changes: 1 addition & 1 deletion conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: pybind11_rdp
version: 0.0.2
version: 0.1.0

source:
path: ..
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
# built documents.
#
# The short X.Y version.
version = '0.0.2'
version = '0.1.0'
# The full version, including alpha/beta/rc tags.
release = '0.0.2'
release = '0.1.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def build_extension(self, ext):
# logic and declaration, and simpler if you include description/version in a file.
setup(
name="pybind11_rdp",
version="0.0.2",
version="0.1.0",
author="tzx",
author_email="[email protected]",
url="https://github.com/cubao/pybind11-rdp",
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ PYBIND11_MODULE(pybind11_rdp, m)
rdp_mask
)pbdoc";

py::class_<LineSegment>(m, "LineSegment") //
.def(py::init<const Eigen::Vector3d, const Eigen::Vector3d>(), "A"_a,
"B"_a)
.def("distance", &LineSegment::distance, "P"_a)
.def("distance2", &LineSegment::distance2, "P"_a)
//
;

auto rdp_doc = R"pbdoc(
Simplifies a given array of points using the Ramer-Douglas-Peucker algorithm.

Expand Down
10 changes: 10 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import time

import numpy as np
from pybind11_rdp import LineSegment
from pybind11_rdp import rdp as rdp_pybind
from pybind11_rdp import rdp_mask as rdp_mask
from rdp import rdp as rdp_python

seg = LineSegment([0, 0, 0], [10, 0, 0])
assert 4.0 == seg.distance([5.0, 4.0, 0.0])
assert 5.0 == seg.distance([-4.0, 3.0, 0.0])
assert 5.0 == seg.distance([14.0, 3.0, 0.0])
seg = LineSegment([0, 0, 0], [0, 0, 0])
assert 5.0 == seg.distance([3.0, 4.0, 0.0])
assert 5.0 == seg.distance([-4.0, 3.0, 0.0])
assert 13.0 == seg.distance([5.0, 12.0, 0.0])

for fn in [rdp_python, rdp_pybind]:
print("#" * 80)
print(fn)
Expand Down
19 changes: 16 additions & 3 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import pybind11_rdp as m
from pybind11_rdp import LineSegment, rdp


def test_main():
assert m.rdp([[1, 1], [2, 2], [3, 3], [4, 4]]).shape == (2, 2)
def test_segment():
seg = LineSegment([0, 0, 0], [10, 0, 0])
assert 4.0 == seg.distance([5.0, 4.0, 0.0])
assert 5.0 == seg.distance([-4.0, 3.0, 0.0])
assert 5.0 == seg.distance([14.0, 3.0, 0.0])
seg = LineSegment([0, 0, 0], [0, 0, 0])
assert 5.0 == seg.distance([3.0, 4.0, 0.0])
assert 5.0 == seg.distance([-4.0, 3.0, 0.0])
assert 13.0 == seg.distance([5.0, 12.0, 0.0])


def test_rdp():
assert rdp([[1, 1], [2, 2], [3, 3], [4, 4]], epsilon=1e-9).shape == (2, 2)
assert rdp([[0, 0], [5, 1 + 1e-3], [10, 0]], epsilon=1).shape == (3, 2)
assert rdp([[0, 0], [5, 1 - 1e-3], [10, 0]], epsilon=1).shape == (2, 2)