Skip to content

Commit 94dedb0

Browse files
committed
link first tendency to last tendency in repeated waveform
1 parent b189bc4 commit 94dedb0

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

tests/tendencies/test_repeat.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ def repeat_waveform():
2626
}
2727

2828

29+
def test_repeat_loop():
30+
"""Test if repeat tendency correctly links first and last tendencies."""
31+
looped_waveform = {
32+
"user_duration": 8,
33+
"user_waveform": [
34+
{"type": "linear", "from": 1, "to": 2, "duration": 2},
35+
{"type": "linear", "from": 2, "to": -1, "duration": 1},
36+
{"type": "linear", "duration": 1},
37+
],
38+
}
39+
repeat_tendency = RepeatTendency(**looped_waveform)
40+
times = np.linspace(0, 8, 17)
41+
_, values = repeat_tendency.get_value(times)
42+
check_values_at_times([0, 4, 8], times, values, 1)
43+
check_values_at_times([2, 6], times, values, 2)
44+
check_values_at_times([3, 7], times, values, -1)
45+
check_values_at_times([3.5, 7.5], times, values, 0)
46+
47+
2948
def test_zero_start(repeat_waveform):
3049
"""Test if zero start does not raise an error."""
3150
repeat_waveform["user_waveform"][0]["start"] = 0

waveform_editor/tendencies/repeat.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,12 @@ def __init__(self, **kwargs):
3232
"The starting point of the first repeated tendency is not set to 0."
3333
)
3434

35-
# TODO: The start of the first tendency does not link to the end of the last
36-
# tendency. This might be nice to implement so you could do for example:
37-
# waveform:
38-
# - type: repeat
39-
# duration: 10
40-
# waveform:
41-
# - {type: linear, from: 1, to: 2, duration: 1}
42-
# - {type: linear, from: 2, to: 0, duration: 1}
43-
# - {type: smooth, duration: 3}
44-
#
45-
# where, the smooth tendency would smoothly interpolate from 0 to 2
35+
# Link the last tendency to the first tendency in the repeated waveform
36+
# We must lock the start to 0, otherwise it will take the start value of the
37+
# previous tendency.
38+
self.waveform.tendencies[0].user_start = 0
39+
self.waveform.tendencies[0].set_previous_tendency(self.waveform.tendencies[-1])
40+
self.waveform.tendencies[-1].set_next_tendency(self.waveform.tendencies[0])
4641

4742
def get_value(
4843
self, time: Optional[np.ndarray] = None

0 commit comments

Comments
 (0)