Skip to content

Commit 15c7a2a

Browse files
Merge pull request #5 from StructuralPython/fixes/polygon_for_single_singularity
fix: added condition for when there is only a single singluarity func…
2 parents aa29c95 + 405ee26 commit 15c7a2a

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/load_distribution/load_distribution.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,27 @@ def singularities_to_polygon(los: list[Singularity], xy: bool = False) -> Polygo
183183
prev_x = None
184184
n = None
185185
# Create a list of the x-ordinates required
186-
# Always starts on 0.0
187-
x_acc.append(0.0)
188-
for idx, sing in enumerate(sorted_sings):
186+
if len(sorted_sings) == 1:
187+
sing = sorted_sings[0]
189188
n = sing.precision
190-
eps = 10 ** (-2 * n)
191-
if prev_x != sing.x0 and prev_x is not None:
192-
x_acc.append(prev_x + eps)
193-
if prev_x is not None and not math.isclose(prev_x, sing.x0):
194-
x_acc.append(sing.x0)
189+
eps = 10 ** (-2 * n - 1)
190+
x_acc.append(sing.x0)
195191
x_acc.append(sing.x0 + eps)
196192
x_acc.append(sing.x1 - eps)
197-
prev_x = sing.x1
193+
x_acc.append(sing.x1)
194+
else:
195+
# Always starts on 0.0
196+
x_acc.append(0.0)
197+
for idx, sing in enumerate(sorted_sings):
198+
n = sing.precision
199+
eps = 10 ** (-2 * n)
200+
if prev_x != sing.x0 and prev_x is not None:
201+
x_acc.append(prev_x + eps)
202+
if prev_x is not None and not math.isclose(prev_x, sing.x0):
203+
x_acc.append(sing.x0)
204+
x_acc.append(sing.x0 + eps)
205+
x_acc.append(sing.x1 - 10 * eps)
206+
prev_x = sing.x1
198207

199208
# There are two scenarios: sing functions that describe trapezoids/triangles
200209
# and sing functions that describe step functions (rectangles). To ensure
@@ -203,6 +212,7 @@ def singularities_to_polygon(los: list[Singularity], xy: bool = False) -> Polygo
203212
# duplicate x-ordinates. The goal is to have the minimum amount to describe the
204213
# required shape, even if that means the exact x value is omitted (because we are
205214
# keeping the value immediately to the left and immediately to the right instead).
215+
print(f"{x_acc=}")
206216
x_acc = sorted(list(set(x_acc)))
207217
x_ord_count = Counter([round(x, 6) for x in x_acc])
208218
to_filter = []

tests/test_load_distribution.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ def test_singularities_to_polygon():
196196
).wkt
197197
== "POLYGON ((0 0, 0 10, 2 10, 2 4, 4 4, 4 8, 8 8, 8 10, 10 10, 10 0, 0 0))"
198198
)
199+
assert (
200+
ld.singularities_to_polygon(
201+
[ld.Singularity(x0=1.0, x1=3.0, m=0.0, y0=10.0, precision=6, eps=1e-12)]
202+
).wkt
203+
== "POLYGON ((1 0, 1 10, 3 10, 3 0, 1 0))"
204+
)
199205

200206

201207
def test_overlap_region_to_singularity():

0 commit comments

Comments
 (0)