Skip to content

Commit 1d1a1b9

Browse files
authored
Bind segment_segment_intersect (#74)
* Wrap segment_segment_intersect
1 parent 457b8a1 commit 1d1a1b9

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

python/src/ipc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ void define_ipc(py::module_& m)
9393
},
9494
R"ipc_Qu8mg5v7(
9595
Constructs a list of unique edges represented in a given mesh F
96+
9697
Parameters:
9798
F: #F by 3 list of mesh faces (must be triangles)
99+
98100
Returns:
99101
#E by 2 list of edges in no particular order
100102
)ipc_Qu8mg5v7",

python/src/utils/intersection.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <ipc/utils/intersection.hpp>
44

5+
#include <igl/predicates/segment_segment_intersect.h>
6+
57
namespace py = pybind11;
68
using namespace ipc;
79

@@ -11,4 +13,25 @@ void define_intersection(py::module_& m)
1113
"is_edge_intersecting_triangle", &is_edge_intersecting_triangle, "",
1214
py::arg("e0"), py::arg("e1"), py::arg("t0"), py::arg("t1"),
1315
py::arg("t2"));
16+
17+
m.def(
18+
"segment_segment_intersect",
19+
[](const Eigen::Vector2d& A, const Eigen::Vector2d& B,
20+
const Eigen::Vector2d& C, const Eigen::Vector2d& D) -> bool {
21+
igl::predicates::exactinit();
22+
return igl::predicates::segment_segment_intersect(A, B, C, D);
23+
},
24+
R"ipc_Qu8mg5v7(
25+
Given two segments in 2d test whether they intersect each other using predicates orient2d
26+
27+
Parameters:
28+
A: 1st endpoint of segment 1
29+
B: 2st endpoint of segment 1
30+
C: 1st endpoint of segment 2
31+
D: 2st endpoint of segment 2
32+
33+
Returns:
34+
true if they intersect
35+
)ipc_Qu8mg5v7",
36+
py::arg("A"), py::arg("B"), py::arg("C"), py::arg("D"));
1437
}

python/tests/test_intersections.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import numpy as np
2+
import ipctk
3+
4+
5+
def test_segment_segment_intersect():
6+
assert ipctk.segment_segment_intersect(
7+
np.array([-1, 0]), np.array([1, 0]), np.array([0, -1]), np.array([0, 1]))

0 commit comments

Comments
 (0)