feat: pixel<->time geometry helpers for the waveform
This commit is contained in:
@@ -607,3 +607,20 @@ def test_load_region_samples_bad_path_returns_empty():
|
||||
out = load_region_samples("/no/such/file.mp4", 0.0, 1.0)
|
||||
assert isinstance(out, np.ndarray)
|
||||
assert out.size == 0
|
||||
|
||||
|
||||
def test_time_pixel_roundtrip():
|
||||
from core.waveform import t_to_x, x_to_t
|
||||
assert x_to_t(0, 400, 10.0, 4.0) == 10.0
|
||||
assert x_to_t(400, 400, 10.0, 4.0) == 14.0
|
||||
assert x_to_t(200, 400, 10.0, 4.0) == 12.0
|
||||
assert t_to_x(12.0, 400, 10.0, 4.0) == 200
|
||||
for x in (0, 37, 200, 399):
|
||||
assert abs(t_to_x(x_to_t(x, 400, 10.0, 4.0), 400, 10.0, 4.0) - x) <= 1
|
||||
|
||||
|
||||
def test_time_pixel_guards():
|
||||
from core.waveform import t_to_x, x_to_t
|
||||
assert x_to_t(50, 0, 10.0, 4.0) == 10.0 # zero width -> view_start
|
||||
assert x_to_t(50, 400, 10.0, 0.0) == 10.0 # zero span -> view_start
|
||||
assert t_to_x(12.0, 400, 10.0, 0.0) == 0 # zero span -> 0
|
||||
|
||||
Reference in New Issue
Block a user