Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/load_distribution/load_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,27 @@ def singularities_to_polygon(los: list[Singularity], xy: bool = False) -> Polygo
prev_x = None
n = None
# Create a list of the x-ordinates required
# Always starts on 0.0
x_acc.append(0.0)
for idx, sing in enumerate(sorted_sings):
if len(sorted_sings) == 1:
sing = sorted_sings[0]
n = sing.precision
eps = 10 ** (-2 * n)
if prev_x != sing.x0 and prev_x is not None:
x_acc.append(prev_x + eps)
if prev_x is not None and not math.isclose(prev_x, sing.x0):
x_acc.append(sing.x0)
eps = 10 ** (-2 * n - 1)
x_acc.append(sing.x0)
x_acc.append(sing.x0 + eps)
x_acc.append(sing.x1 - eps)
prev_x = sing.x1
x_acc.append(sing.x1)
else:
# Always starts on 0.0
x_acc.append(0.0)
for idx, sing in enumerate(sorted_sings):
n = sing.precision
eps = 10 ** (-2 * n)
if prev_x != sing.x0 and prev_x is not None:
x_acc.append(prev_x + eps)
if prev_x is not None and not math.isclose(prev_x, sing.x0):
x_acc.append(sing.x0)
x_acc.append(sing.x0 + eps)
x_acc.append(sing.x1 - 10 * eps)
prev_x = sing.x1

# There are two scenarios: sing functions that describe trapezoids/triangles
# and sing functions that describe step functions (rectangles). To ensure
Expand All @@ -203,6 +212,7 @@ def singularities_to_polygon(los: list[Singularity], xy: bool = False) -> Polygo
# duplicate x-ordinates. The goal is to have the minimum amount to describe the
# required shape, even if that means the exact x value is omitted (because we are
# keeping the value immediately to the left and immediately to the right instead).
print(f"{x_acc=}")
x_acc = sorted(list(set(x_acc)))
x_ord_count = Counter([round(x, 6) for x in x_acc])
to_filter = []
Expand Down
6 changes: 6 additions & 0 deletions tests/test_load_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ def test_singularities_to_polygon():
).wkt
== "POLYGON ((0 0, 0 10, 2 10, 2 4, 4 4, 4 8, 8 8, 8 10, 10 10, 10 0, 0 0))"
)
assert (
ld.singularities_to_polygon(
[ld.Singularity(x0=1.0, x1=3.0, m=0.0, y0=10.0, precision=6, eps=1e-12)]
).wkt
== "POLYGON ((1 0, 1 10, 3 10, 3 0, 1 0))"
)


def test_overlap_region_to_singularity():
Expand Down
Loading