Skip to content

Commit 4fe77e8

Browse files
committed
add number_of_points property to the PolyFile class
1 parent 681ca99 commit 4fe77e8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

hydrolib/core/dflowfm/polyfile/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ def get_z_sources_sinks(self) -> Tuple[List[float], List[float]]:
161161
>>> polyline = PolyFile("tests/data/input/source-sink/leftsor.pliz")
162162
>>> z_source, z_sink = polyline.get_z_sources_sinks()
163163
>>> print(z_source, z_sink)
164-
[-3] [-4.2]
164+
[-3.0] [-4.2]
165165
166166
in case the polyline has more than 3 columns:
167167
>>> polyline = PolyFile("tests/data/input/source-sink/leftsor-5-columns.pliz") #Doctest: +SKIP
168168
>>> z_source, z_sink = polyline.get_z_sources_sinks()
169169
>>> print(z_source, z_sink)
170-
[-3, -2.9] [-4.2, -5.35]
170+
[-3.0, -2.9] [-4.2, -5.35]
171171
172172
in case the polyline does not have z-values:
173173
>>> root_dir = "tests/data/input/dflowfm_individual_files/polylines"
@@ -189,3 +189,8 @@ def get_z_sources_sinks(self) -> Tuple[List[float], List[float]]:
189189
z_sink: list[float | None] = z_source_sink[0]
190190
z_source: list[float | None] = z_source_sink[1]
191191
return z_source, z_sink
192+
193+
@property
194+
def number_of_points(self) -> int:
195+
"""Total number of points in the PolyFile."""
196+
return len(self.x)

tests/dflowfm/polyfile/test_polyline_models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_with_label(polylines_dir: Path):
2828
assert polyline.save_location == path.absolute()
2929
assert polyline.x == [0, 0]
3030
assert polyline.y == [0, 2]
31+
assert polyline.number_of_points == 2
3132

3233

3334
def test_without_z(polylines_dir: Path):
@@ -48,6 +49,7 @@ def test_without_z(polylines_dir: Path):
4849
assert points[1] == Point(x=-80, y=550, z=None, data=[])
4950
assert polyline.x == [-80, -80]
5051
assert polyline.y == [-50, 550]
52+
assert polyline.number_of_points == 2
5153

5254

5355
def test_with_z_and_pli_extension_2by2(polylines_dir: Path):

0 commit comments

Comments
 (0)