Skip to content

Commit

Permalink
GmMultiPolyIntersector for python - Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mkennard-aquaveo committed Jan 5, 2024
1 parent 38d3f81 commit b0ec0dc
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions xmsgrid/python/geometry/GmMultiPolyIntersector_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
namespace py = pybind11;

//----- Python Interface -------------------------------------------------------
//PYBIND11_DECLARE_HOLDER_TYPE(T, BSHP<T>);

struct wrapper {
// Use a wrapper struct to avoid compile errors due to virtual ~GmMultiPolyIntersector() being declared protected
struct Wrapper {
BSHP<xms::GmMultiPolyIntersector> p = nullptr;
};

void initGmMultiPolyIntersector(py::module &m) {
// GmMultiPolyIntersector class
// py::class_<xms::GmMultiPolyIntersector, BSHP<xms::GmMultiPolyIntersector>> gmMpi(m, "GmMultiPolyIntersector");
py::class_<wrapper> gmMpi(m, "GmMultiPolyIntersector");
py::class_<Wrapper> gmMpi(m, "GmMultiPolyIntersector");

// ---------------------------------------------------------------------------
// function: init
Expand All @@ -39,16 +38,15 @@ void initGmMultiPolyIntersector(py::module &m) {
BSHP<xms::VecPt3d> vec_pts = xms::VecPt3dFromPyIter(poly_points);
BSHP<xms::VecInt2d> vec_polys = xms::VecInt2dFromPyIter(polys);
BSHP<xms::GmMultiPolyIntersectionSorterTerse> sorter(new xms::GmMultiPolyIntersectionSorterTerse);
// BSHP<xms::GmMultiPolyIntersector> rval(xms::GmMultiPolyIntersector::New(*vec_pts, *vec_polys, sorter, starting_id));
wrapper rval;
rval.p = xms::GmMultiPolyIntersector::New(*vec_pts, *vec_polys, sorter, starting_id);
rval.p->SetQuery(query == "covered_by" ? xms::GMMPIQ_COVEREDBY : xms::GMMPIQ_INTERSECTS);
return rval;
Wrapper wrapper;
wrapper.p = xms::GmMultiPolyIntersector::New(*vec_pts, *vec_polys, sorter, starting_id);
wrapper.p->SetQuery(query == "covered_by" ? xms::GMMPIQ_COVEREDBY : xms::GMMPIQ_INTERSECTS);
return wrapper;
}), py::arg("poly_points"), py::arg("polys"), py::arg("starting_id") = 1, py::arg("query") = "covered_by");
// ---------------------------------------------------------------------------
// function: TraverseLineSegment
// ---------------------------------------------------------------------------
gmMpi.def("TraverseLineSegment", [](wrapper &self, py::iterable pt1, py::iterable pt2)
gmMpi.def("TraverseLineSegment", [](Wrapper &self, py::iterable pt1, py::iterable pt2)
-> py::tuple {
xms::Pt3d p1 = xms::Pt3dFromPyIter(pt1);
xms::Pt3d p2 = xms::Pt3dFromPyIter(pt2);
Expand All @@ -61,7 +59,7 @@ void initGmMultiPolyIntersector(py::module &m) {
// ---------------------------------------------------------------------------
// function: PolygonFromPoint
// ---------------------------------------------------------------------------
gmMpi.def("PolygonFromPoint", [](wrapper &self, py::iterable point) -> int {
gmMpi.def("PolygonFromPoint", [](Wrapper &self, py::iterable point) -> int {
xms::Pt3d p = xms::Pt3dFromPyIter(point);
return self.p->PolygonFromPoint(p);
}, py::arg("point"));
Expand Down

0 comments on commit b0ec0dc

Please sign in to comment.