Skip to content

Commit e6ddef8

Browse files
committed
fix: removed popping from x_acc and implemented filtering instead
1 parent 08579c9 commit e6ddef8

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/load_distribution/load_distribution.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,31 +215,36 @@ def singularities_to_polygon(los: list[Singularity], xy: bool = False) -> Polygo
215215
# required shape, even if that means the exact x value is omitted (because we are
216216
# keeping the value immediately to the left and immediately to the right instead).
217217
x_acc = sorted(list(set(x_acc)))
218-
219218
x_ord_count = Counter([round(x, 6) for x in x_acc])
220219
to_filter = []
221220
for key, count in x_ord_count.items():
222221
if count == 3:
223222
to_filter.append(key)
224223

224+
filtered_indexes = []
225225
if to_filter:
226226
rounded_x_acc = [round(x, 6) for x in x_acc]
227227
for filter_val in to_filter:
228228
index = rounded_x_acc.index(filter_val)
229-
x_acc.pop(index)
229+
filtered_indexes.append(index + 1)
230+
231+
filtered_x = []
232+
for idx, x_val in enumerate(x_acc):
233+
if idx not in filtered_indexes:
234+
filtered_x.append(x_val)
230235

231236
# Now, for every x value, compute the corresponding y value
232-
y_acc = [sum([sing(x) for sing in sorted_sings]) for x in x_acc[:-1]]
237+
y_acc = [sum([sing(x) for sing in sorted_sings]) for x in filtered_x[:-1]]
233238
# Always ends on 0.0
234239
y_acc.append(0.0)
235240
if xy:
236241
return x_acc, y_acc
237242
else:
238243
precision = n if n else 2
239244
xy_acc = zip(
240-
[round(x, precision) for x in x_acc], [round(y, precision) for y in y_acc]
245+
[round(x, precision) for x in filtered_x],
246+
[round(y, precision) for y in y_acc],
241247
)
242-
243248
return Polygon(xy_acc)
244249

245250

tests/test_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from load_distribution import Singularity
22
import numpy as np
33

4+
# An output from papermodels that caused an error in the singularities_to_polygon function due to lots of list popping
5+
46
big_list_o_singularities = [
57
Singularity(
68
x0=6.628,

tests/test_load_distribution.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ def test_singularities_to_polygon():
241241
# because of the popping
242242

243243
assert (
244-
ld.singularities_to_polygon(data.big_list_o_singularities).wkt
245-
) == "FAILING TEST"
244+
(ld.singularities_to_polygon(data.big_list_o_singularities).wkt)
245+
== "POLYGON ((0 0, 0.001 0, 0.001 3396.431373, 0.413 3396.431373, 0.413 -1656.718815, 3.172 -1656.718815, 3.172 -2981.839131, 3.504 -2981.839131, 3.504 -1325.120316, 6.628 -1325.120316, 6.628 -1991.55609, 6.876 -1991.55609, 6.876 -666.435774, 7.57 -666.435774, 7.57 3157.111452, 7.859 3157.111452, 7.859 0, 0 0))"
246+
)
246247

247248

248249
def test_overlap_region_to_singularity():

0 commit comments

Comments
 (0)