Skip to content

Commit f76b0ae

Browse files
committed
Bump pyo3 version
switch to pseudonormal containment check is now n_rays=0 rather than None, due to PyO3/pyo3#3735
1 parent 6138656 commit f76b0ae

8 files changed

Lines changed: 49 additions & 63 deletions

File tree

Cargo.lock

Lines changed: 30 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ version = "0.19.0"
44
edition = "2018"
55

66
[dependencies]
7-
pyo3 = { version = "0.18", features = ["extension-module", "abi3-py38"] }
7+
pyo3 = { version = "0.20", features = ["extension-module", "abi3-py38"] }
88
parry3d-f64 = { version = "0.13", features = ["dim3", "f64", "enhanced-determinism"] }
99
rayon = "1.7"
1010
rand = "0.8"
1111
rand_pcg = "0.3"
12-
numpy = "0.18"
12+
numpy = "0.20"
1313
log = "0.4.20"
1414

1515
# ndarray is a dependency of numpy.

python/ncollpyde/_ncollpyde.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TriMeshWrapper:
1717
self, points: Points, indices: Indices, n_rays: int, ray_seed: int
1818
): ...
1919
def contains(
20-
self, points: Points, n_rays: Optional[int], consensus: int, parallel: bool
20+
self, points: Points, n_rays: int, consensus: int, parallel: bool
2121
) -> npt.NDArray[np.bool_]: ...
2222
def distance(
2323
self, points: Points, signed: bool, parallel: bool

python/ncollpyde/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def contains(
217217
:param coords:
218218
:param n_rays: Optional[int]
219219
If None, use the maximum rays defined on construction.
220-
If < 0, use signed distance strategy
220+
If < 1, use signed distance strategy
221221
(more robust, but slower for many meshes).
222222
Otherwise, use this many meshes, up to the maximum defined on construction.
223223
:param consensus: Optional[int]
@@ -235,7 +235,7 @@ def contains(
235235
coords = self._as_points(coords)
236236
if n_rays is None:
237237
n_rays = self.n_rays
238-
elif n_rays < 0:
238+
elif n_rays < 1:
239239
n_rays = None
240240
elif n_rays > self.n_rays:
241241
logger.warning(
@@ -245,6 +245,7 @@ def contains(
245245

246246
if n_rays is None:
247247
consensus = 1
248+
n_rays = 0
248249
else:
249250
if consensus is None:
250251
consensus = n_rays // 2 + 1

src/interface.rs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::fmt::Debug;
21
use std::iter::repeat_with;
32

43
use ndarray::{Array2, ArrayView1};
@@ -17,13 +16,13 @@ use crate::utils::{
1716
points_cross_mesh, random_dir, sdf_inner, Precision, FLAGS,
1817
};
1918

20-
fn vec_to_point<T: 'static + Debug + PartialEq + Copy>(v: Vec<T>) -> Point<T> {
21-
Point::new(v[0], v[1], v[2])
22-
}
19+
// fn vec_to_point<T: 'static + Debug + PartialEq + Copy>(v: Vec<T>) -> Point<T> {
20+
// Point::new(v[0], v[1], v[2])
21+
// }
2322

24-
fn point_to_vec<T: 'static + Debug + PartialEq + Copy>(p: &Point<T>) -> Vec<T> {
25-
vec![p.x, p.y, p.z]
26-
}
23+
// fn point_to_vec<T: 'static + Debug + PartialEq + Copy>(p: &Point<T>) -> Vec<T> {
24+
// vec![p.x, p.y, p.z]
25+
// }
2726

2827
#[pyclass]
2928
pub struct TriMeshWrapper {
@@ -96,20 +95,21 @@ impl TriMeshWrapper {
9695
collected.into_pyarray(py)
9796
}
9897

98+
// #[pyo3(signature = (points, n_rays=None, consensus=None, parallel=None))]
9999
pub fn contains<'py>(
100100
&self,
101101
py: Python<'py>,
102102
points: PyReadonlyArray2<Precision>,
103-
n_rays: Option<usize>,
103+
n_rays: usize,
104104
consensus: usize,
105105
parallel: bool,
106106
) -> &'py PyArray1<bool> {
107107
let p_arr = points.as_array();
108108
let zipped = Zip::from(p_arr.rows());
109109

110-
let collected = if let Some(n) = n_rays {
110+
let collected = if n_rays >= 1 {
111111
// use ray casting
112-
let rays = &self.ray_directions[..n];
112+
let rays = &self.ray_directions[..n_rays];
113113
let clos = |r: ArrayView1<f64>| {
114114
mesh_contains_point(&self.mesh, &Point::new(r[0], r[1], r[2]), rays, consensus)
115115
};
@@ -242,7 +242,7 @@ impl TriMeshWrapper {
242242
.as_array()
243243
.rows()
244244
.into_iter()
245-
.zip(tgt_points.as_array().rows().into_iter())
245+
.zip(tgt_points.as_array().rows())
246246
.zip(0_u64..)
247247
.for_each(|((src, tgt), i)| {
248248
if let Some((pt, is_bf)) = points_cross_mesh(
@@ -265,25 +265,6 @@ impl TriMeshWrapper {
265265
)
266266
}
267267

268-
#[deprecated]
269-
pub fn intersections_many_threaded(
270-
&self,
271-
src_points: Vec<Vec<Precision>>,
272-
tgt_points: Vec<Vec<Precision>>,
273-
) -> (Vec<u64>, Vec<Vec<Precision>>, Vec<bool>) {
274-
let (idxs, (intersections, is_backface)) = src_points
275-
.into_par_iter()
276-
.zip(tgt_points.into_par_iter())
277-
.enumerate()
278-
.filter_map(|(i, (src, tgt))| {
279-
points_cross_mesh(&self.mesh, &vec_to_point(src), &vec_to_point(tgt))
280-
.map(|o| (i as u64, (point_to_vec(&o.0), o.1)))
281-
})
282-
.unzip();
283-
284-
(idxs, intersections, is_backface)
285-
}
286-
287268
pub fn intersections_many_threaded2<'py>(
288269
&self,
289270
py: Python<'py>,

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn mesh_contains_point(
8383
return false;
8484
}
8585
}
86-
return false;
86+
false
8787
}
8888

8989
pub fn mesh_contains_point_oriented(mesh: &TriMesh, point: &Point<f64>) -> bool {

tests/test_bench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def test_trimesh_contains(trimesh_volume, sample_points, expected, benchmark):
221221

222222

223223
@pytest.mark.benchmark(group=CONTAINS_SERIAL)
224-
@pytest.mark.parametrize("n_rays", [0, 1, 2, 4, 8, 16])
224+
@pytest.mark.parametrize("n_rays", [1, 2, 4, 8, 16])
225225
def test_ncollpyde_contains(mesh, n_rays, sample_points, expected, benchmark):
226226
ncollpyde_volume = Volume.from_meshio(mesh, n_rays=n_rays)
227227
ncollpyde_volume.threads = False

tests/test_ncollpyde.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ def test_contains_results(volume: Volume):
5757
assert np.allclose(ray, psnorms)
5858

5959

60-
def test_0_rays(mesh):
61-
vol = Volume.from_meshio(mesh, n_rays=0)
62-
points = [p for p, _ in points_expected]
63-
assert np.array_equal(vol.contains(points), [False] * len(points))
64-
65-
6660
def test_no_validation(mesh):
6761
triangles = mesh.cells_dict["triangle"]
6862
Volume(mesh.points, triangles, True)

0 commit comments

Comments
 (0)