Skip to content

Commit

Permalink
BUG interpolate properly in offset_by (#75)
Browse files Browse the repository at this point in the history
* BUG interpolate properly in offset_by

* Test offset by/to
  • Loading branch information
ksunden authored and untzag committed Nov 19, 2019
1 parent d0847d4 commit 2afb158
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion attune/curve/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def offset_by(self, dependent, amount):
"""
# offset
self.dependents[dependent].positions += amount
self.dependents[dependent].interpolate()
self.interpolate()

def offset_to(self, dependent, destination, setpoint, setpoint_units="same"):
"""Offset a dependent such that it evaluates to `destination` at `setpoint`.
Expand Down
26 changes: 26 additions & 0 deletions tests/Curve/offset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import attune
import numpy as np


def test_offset_by():
d0 = attune.Dependent(np.linspace(-5, 5, 20), "d1")
s0 = attune.Setpoints(np.linspace(1300, 1400, 20), "s", "wn")
c0 = attune.Curve(s0, [d0], "c1")
c1 = c0.copy()

c1.offset_by("d1", 1.0)

np.testing.assert_allclose(c1["d1"][:], c0["d1"][:] + 1.0)
np.testing.assert_allclose(c1.setpoints[:], c0.setpoints[:])


def test_offset_to():
d0 = attune.Dependent(np.linspace(-5, 5, 20), "d1")
s0 = attune.Setpoints(np.linspace(1300, 1400, 20), "s", "wn")
c0 = attune.Curve(s0, [d0], "c1")
c1 = c0.copy()

c1.offset_to("d1", 1.0, 1300)

np.testing.assert_allclose(c1["d1"][:], np.linspace(1, 11, 20))
np.testing.assert_allclose(c1.setpoints[:], c0.setpoints[:])

0 comments on commit 2afb158

Please sign in to comment.