Skip to content

Commit

Permalink
GmMultiPolyIntersector for python - Revert all changes to GmMultiPoly…
Browse files Browse the repository at this point in the history
…Intersector.h to avoid having to update dependent libraries. Remove query as a python property.
  • Loading branch information
mkennard-aquaveo committed Jan 5, 2024
1 parent cc80505 commit 91cc77d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ def _run_test(self, pt1, pt2, poly_points, polys, poly_ids, t_vals, pts, startin
"""Runs the test."""
mpi = grid.geometry.MultiPolyIntersector(poly_points, polys, starting_id, query)

# Check some basic stuff
assert mpi.query == query
print(mpi.__str__())
print(mpi.__repr__())

# Traverse the line segment
out_poly_ids, out_t_vals, out_pts = mpi.traverse_line_segment(pt1, pt2)

Expand Down Expand Up @@ -132,8 +127,7 @@ def test_polygon_from_point(self):
assert mpi.polygon_from_point((15, 15, 0)) == -1
assert mpi.polygon_from_point((15, 10, 0)) == 2
assert mpi.polygon_from_point((15, 5, 0)) == 2
assert mpi.query == 'covered_by'
mpi.query = 'intersects'
mpi = grid.geometry.MultiPolyIntersector(pts, polys, query='intersects')
assert mpi.polygon_from_point((5, 5, 0)) == -1
assert mpi.polygon_from_point((5, 10, 0)) == 1
assert mpi.polygon_from_point((5, 15, 0)) == 1
Expand Down
11 changes: 1 addition & 10 deletions _package/xms/grid/geometry/multi_poly_intersector.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __ne__(self, other) -> bool:
result = self.__eq__(other)
return not result

# Why define these?
# def __repr__(self) -> str:
# """Returns a string representation of the MultiPolyIntersector."""
# return "<xms.grid.geometry.MultiPolyIntersector>"
Expand All @@ -75,16 +76,6 @@ def __ne__(self, other) -> bool:
# """Returns a string representation of the MultiPolyIntersector."""
# return "<xms.grid.geometry.MultiPolyIntersector>"

@property
def query(self) -> str:
"""The query to use ('covered_by', 'intersects')."""
return self._instance.GetQuery()

@query.setter
def query(self, query: str):
"""Set the query to use ('covered_by', 'intersects')."""
self._instance.SetQuery(query)

def traverse_line_segment(self, pt1, pt2) -> tuple[tuple[int], tuple[float], tuple[tuple[float, float, float]]]:
"""Intersect segment with polys and return intersected polys, t-values, and points.
Expand Down
13 changes: 6 additions & 7 deletions xmsgrid/geometry/GmMultiPolyIntersector.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// \file
/// \ingroup geometry
/// \copyright (C) Copyright Aquaveo 2018. Distributed under FreeBSD License
/// (See accompanying file LICENSE or https://aquaveo.com/bsd/license.txt)
/// (See accompanying file LICENSE or https://aqaveo.com/bsd/license.txt)
//------------------------------------------------------------------------------

//----- Included files ---------------------------------------------------------
Expand All @@ -13,7 +13,7 @@

// 5. Shared code headers
#include <xmscore/misc/base_macros.h> // for XM_DISALLOW_COPY_AND_ASSIGN
#include <xmscore/misc/boost_defines.h> // for BSHP
#include <xmscore/misc/boost_defines.h>
#include <xmscore/points/ptsfwd.h> // for Pt3d

//----- Namespace --------------------------------------------------------------
Expand All @@ -33,15 +33,13 @@ enum GmMultiPolyIntersectorQueryEnum { GMMPIQ_COVEREDBY, GMMPIQ_INTERSECTS };
class GmMultiPolyIntersector
{
public:
static BSHP<GmMultiPolyIntersector> New(
static boost::shared_ptr<GmMultiPolyIntersector> New(
const std::vector<Pt3d>& a_points,
const std::vector<std::vector<int> >& a_polys,
BSHP<GmMultiPolyIntersectionSorter> a_sorter,
boost::shared_ptr<GmMultiPolyIntersectionSorter> a_sorter,
int a_startingId = 1);
virtual ~GmMultiPolyIntersector();
/// \cond

virtual GmMultiPolyIntersectorQueryEnum GetQuery() const = 0;
virtual void SetQuery(GmMultiPolyIntersectorQueryEnum a_query) = 0;
virtual void TraverseLineSegment(double a_x1,
double a_y1,
Expand Down Expand Up @@ -72,10 +70,11 @@ class GmMultiPolyIntersector
/// \endcond
protected:
GmMultiPolyIntersector();
virtual ~GmMultiPolyIntersector();

private:
XM_DISALLOW_COPY_AND_ASSIGN(GmMultiPolyIntersector)

}; // class GmMultiPolyIntersector

} // namespace xms
} // namespace xms
13 changes: 0 additions & 13 deletions xmsgrid/python/geometry/GmMultiPolyIntersector_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,4 @@ void initGmMultiPolyIntersector(py::module &m) {
xms::Pt3d p = xms::Pt3dFromPyIter(point);
return self.PolygonFromPoint(p);
}, py::arg("point"));
// ---------------------------------------------------------------------------
// function: GetQuery
// ---------------------------------------------------------------------------
gmMpi.def("GetQuery", [](xms::GmMultiPolyIntersector &self) -> std::string {
return self.GetQuery() == xms::GMMPIQ_COVEREDBY ? "covered_by" : "intersects";
});
// ---------------------------------------------------------------------------
// function: SetQuery
// ---------------------------------------------------------------------------
gmMpi.def("SetQuery", [](xms::GmMultiPolyIntersector &self, std::string query) {
xms::GmMultiPolyIntersectorQueryEnum q = (query == "covered_by" ? xms::GMMPIQ_COVEREDBY : xms::GMMPIQ_INTERSECTS);
self.SetQuery(q);
}, py::arg("query"));
}

0 comments on commit 91cc77d

Please sign in to comment.