Skip to content

Commit 218dfc7

Browse files
committed
Polygon
1 parent 0c0e651 commit 218dfc7

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

mikeio/spatial/_FM_geometry.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from ._FM_utils import (
2323
_get_node_centered_data,
2424
_plot_map,
25-
BoundaryPolylines,
25+
BoundaryPolygons,
2626
Polygon,
2727
_set_xy_label_by_projection, # TODO remove
2828
_to_polygons, # TODO remove
@@ -843,9 +843,9 @@ def get_element_area(self) -> np.ndarray:
843843
return np.abs(area)
844844

845845
@cached_property
846-
def boundary_polylines(self) -> BoundaryPolylines:
846+
def boundary_polylines(self) -> BoundaryPolygons:
847847
"""Lists of closed polylines defining domain outline."""
848-
return self._get_boundary_polylines()
848+
return self._get_boundary_polygons()
849849

850850
def contains(self, points: np.ndarray) -> np.ndarray:
851851
"""Test if a list of points are contained by mesh.
@@ -861,19 +861,18 @@ def contains(self, points: np.ndarray) -> np.ndarray:
861861
True for points inside, False otherwise
862862
863863
"""
864-
865864
points = np.atleast_2d(points)
866865

867866
return self.boundary_polylines.contains(points)
868867

869868
def __contains__(self, pt: np.ndarray) -> bool:
870869
return self.contains(pt)[0]
871870

872-
def _get_boundary_polylines_uncategorized(self) -> list[list[np.int64]]:
873-
"""Construct closed polylines for all boundary faces."""
871+
def _get_boundary_polygons_uncategorized(self) -> list[list[np.int64]]:
872+
"""Construct closed polygons for all boundary faces."""
874873
boundary_faces = self._get_boundary_faces()
875874
face_remains = boundary_faces.copy()
876-
polylines = []
875+
polygons = []
877876
while face_remains.shape[0] > 1:
878877
n0 = face_remains[:, 0]
879878
n1 = face_remains[:, 1]
@@ -892,28 +891,26 @@ def _get_boundary_polylines_uncategorized(self) -> list[list[np.int64]]:
892891
break
893892

894893
face_remains = np.delete(face_remains, index_to_delete, axis=0)
895-
polylines.append(polyline)
896-
return polylines
894+
polygons.append(polyline)
895+
return polygons
897896

898-
def _get_boundary_polylines(self) -> BoundaryPolylines:
897+
def _get_boundary_polygons(self) -> BoundaryPolygons:
899898
"""Get boundary polylines and categorize as inner or outer by assessing the signed area."""
900-
polylines = self._get_boundary_polylines_uncategorized()
899+
polygons = self._get_boundary_polygons_uncategorized()
901900

902901
interiors = []
903902
exteriors = []
904903

905-
for polyline in polylines:
906-
# xy = self.node_coordinates[polyline, :2]
907-
908-
poly_line = np.asarray(polyline)
909-
xy = self.node_coordinates[poly_line, 0:2]
904+
for polygon in polygons:
905+
polygon_np = np.asarray(polygon)
906+
xy = self.node_coordinates[polygon_np, 0:2]
910907
poly = Polygon(xy)
911908
if poly.area > 0:
912909
exteriors.append(poly)
913910
else:
914911
interiors.append(poly)
915912

916-
return BoundaryPolylines(exteriors=exteriors, interiors=interiors)
913+
return BoundaryPolygons(exteriors=exteriors, interiors=interiors)
917914

918915
def _get_boundary_faces(self) -> np.ndarray:
919916
"""Construct list of faces."""

mikeio/spatial/_FM_geometry_layered.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ._FM_geometry import GeometryFM2D, _GeometryFM, _GeometryFMPlotter
1313
from ._geometry import GeometryPoint3D
1414

15-
from ._FM_utils import _plot_vertical_profile, BoundaryPolylines
15+
from ._FM_utils import _plot_vertical_profile, BoundaryPolygons
1616

1717
from ._utils import _relative_cumulative_distance
1818

@@ -653,7 +653,7 @@ def __init__(
653653
self.plot = _GeometryFMPlotter(self)
654654

655655
@property
656-
def boundary_polylines(self) -> BoundaryPolylines:
656+
def boundary_polylines(self) -> BoundaryPolygons:
657657
return self.geometry2d.boundary_polylines
658658

659659
def contains(self, points: np.ndarray) -> np.ndarray:

mikeio/spatial/_FM_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def area(self) -> float:
3131

3232

3333
@dataclass
34-
class BoundaryPolylines:
34+
class BoundaryPolygons:
3535
exteriors: list[Polygon]
3636
interiors: list[Polygon]
3737

0 commit comments

Comments
 (0)