Skip to content

Commit

Permalink
Feature/fix ci, export LineSegment, release 0.1.0 (#4)
Browse files Browse the repository at this point in the history
* trigger wheels

* update pip, install numpy

* fix pyproject.toml; export LineSegment

* disable all pp

* change version

* ready to PR

* fix tests

Co-authored-by: TANG ZHIXIONG <[email protected]>
district10 and TANG ZHIXIONG authored Nov 3, 2022
1 parent 1fb6eea commit 79a1640
Showing 8 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -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
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: ..
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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",
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -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.
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)
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)

0 comments on commit 79a1640

Please sign in to comment.