diff --git a/python/src/ipc.cpp b/python/src/ipc.cpp index c028d76fc..368d1affd 100644 --- a/python/src/ipc.cpp +++ b/python/src/ipc.cpp @@ -93,8 +93,10 @@ void define_ipc(py::module_& m) }, R"ipc_Qu8mg5v7( Constructs a list of unique edges represented in a given mesh F + Parameters: F: #F by 3 list of mesh faces (must be triangles) + Returns: #E by 2 list of edges in no particular order )ipc_Qu8mg5v7", diff --git a/python/src/utils/intersection.cpp b/python/src/utils/intersection.cpp index 6a07b3ebe..24ca30549 100644 --- a/python/src/utils/intersection.cpp +++ b/python/src/utils/intersection.cpp @@ -2,6 +2,8 @@ #include +#include + namespace py = pybind11; using namespace ipc; @@ -11,4 +13,25 @@ void define_intersection(py::module_& m) "is_edge_intersecting_triangle", &is_edge_intersecting_triangle, "", py::arg("e0"), py::arg("e1"), py::arg("t0"), py::arg("t1"), py::arg("t2")); + + m.def( + "segment_segment_intersect", + [](const Eigen::Vector2d& A, const Eigen::Vector2d& B, + const Eigen::Vector2d& C, const Eigen::Vector2d& D) -> bool { + igl::predicates::exactinit(); + return igl::predicates::segment_segment_intersect(A, B, C, D); + }, + R"ipc_Qu8mg5v7( + Given two segments in 2d test whether they intersect each other using predicates orient2d + + Parameters: + A: 1st endpoint of segment 1 + B: 2st endpoint of segment 1 + C: 1st endpoint of segment 2 + D: 2st endpoint of segment 2 + + Returns: + true if they intersect + )ipc_Qu8mg5v7", + py::arg("A"), py::arg("B"), py::arg("C"), py::arg("D")); } diff --git a/python/tests/test_intersections.py b/python/tests/test_intersections.py new file mode 100644 index 000000000..0e2662b55 --- /dev/null +++ b/python/tests/test_intersections.py @@ -0,0 +1,7 @@ +import numpy as np +import ipctk + + +def test_segment_segment_intersect(): + assert ipctk.segment_segment_intersect( + np.array([-1, 0]), np.array([1, 0]), np.array([0, -1]), np.array([0, 1]))