Skip to content

Commit 05e4bb6

Browse files
Merge pull request #9 from StructuralPython/fixes/incorrect_filtering_practices
Fixes/incorrect filtering practices
2 parents 8d2646f + 9fa27da commit 05e4bb6

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

src/load_distribution/load_distribution.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,18 @@ 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+
218219
x_ord_count = Counter([round(x, 6) for x in x_acc])
219220
to_filter = []
220221
for key, count in x_ord_count.items():
221222
if count == 3:
222223
to_filter.append(key)
223-
for filter_val in to_filter:
224-
index = x_acc.index(filter_val)
225-
x_acc.pop(index)
224+
225+
if to_filter:
226+
rounded_x_acc = [round(x, 6) for x in x_acc]
227+
for filter_val in to_filter:
228+
index = rounded_x_acc.index(filter_val)
229+
x_acc.pop(index)
226230

227231
# Now, for every x value, compute the corresponding y value
228232
y_acc = [sum([sing(x) for sing in sorted_sings]) for x in x_acc[:-1]]

tests/test_load_distribution.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,25 @@ def test_singularities_to_polygon():
173173
square_bow_tie_sings = ld.get_singularity_functions(square_bow_tie)
174174
square_with_L_hole_sings = ld.get_singularity_functions(square_with_L_hole)
175175

176+
real_world_singularities = [
177+
ld.Singularity(
178+
x0=0.034367933446777243,
179+
x1=0.051573454339195024,
180+
m=29.060439560440315,
181+
y0=0.0,
182+
precision=6,
183+
eps=1e-12,
184+
),
185+
ld.Singularity(
186+
x0=0.051573454339195024,
187+
x1=11.704999999999998,
188+
m=0.0,
189+
y0=0.5,
190+
precision=6,
191+
eps=1e-12,
192+
),
193+
]
194+
176195
assert (
177196
ld.singularities_to_polygon(square_45_sings[0] + square_45_sings[1]).wkt
178197
== "POLYGON ((0 0, 0 0, 5 10, 5 10, 10 0, 10 0, 0 0))"
@@ -202,13 +221,22 @@ def test_singularities_to_polygon():
202221
== "POLYGON ((1 0, 1 10, 3 10, 3 0, 1 0))"
203222
)
204223
assert (
205-
ld.singularities_to_polygon([
206-
ld.Singularity(x0=0, x1=4, m=0.0, y0=5, precision=6, eps=1e-12),
207-
ld.Singularity(x0=0, x1=2.5, m=0.0, y0=40, precision=6, eps=1e-12)
208-
]).wkt
224+
ld.singularities_to_polygon(
225+
[
226+
ld.Singularity(x0=0, x1=4, m=0.0, y0=5, precision=6, eps=1e-12),
227+
ld.Singularity(x0=0, x1=2.5, m=0.0, y0=40, precision=6, eps=1e-12),
228+
]
229+
).wkt
209230
== "POLYGON ((0 0, 0 45, 2.5 45, 2.5 5, 4 5, 4 0, 0 0))"
210231
)
211232

233+
# This test fails due to an error in filtering
234+
assert (
235+
ld.singularities_to_polygon(real_world_singularities).wkt
236+
== "POLYGON ((0 0, 0.034368 0, 0.051573 0.5, 0.051573 0.5, 11.705 0.5, 11.705 0, 0 0))"
237+
)
238+
239+
212240
def test_overlap_region_to_singularity():
213241
assert ld.overlap_region_to_singularity(
214242
ld.Overlap(6.0, 10.0, 0.0, 0.0, 0.0, 10.0), 6

0 commit comments

Comments
 (0)