image.vision\spatiotemporal\temporal_ctx.mbt
100% · 14 / 14 points · 80 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 时间上下文 spatiotemporal/temporal_ctx - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 时态控制器:管理时变图像的播放状态。 - 7
// Temporal context: manages playback state of time-varying images. - 8
- 9
///| - 10
/// 时态控制器:当前时间、帧率、循环、暂停、播放速度。 - 11
/// 时间上下文 Temporal context: current time, fps, is_loop, paused, playback speed. - 12
#derive(Eq, @debug.Debug) - 13
pub(all) struct TContext { - 14
current_time : Float - 15
fps : Float - 16
is_loop : Bool - 17
paused : Bool - 18
speed : Float - 19
} - 20
- 21
///| - 22
pub extend TContext with @debug.Debug::{to_repr} - 23
- 24
///| - 25
pub extend TContext with Eq::{not_equal, equal} - 26
- 27
///| - 28
/// 创建时态控制器,默认播放速度 1.0,非暂停,非循环。 - 29
/// 创建时间上下文 Create a temporal context - 30
pub fn TContext::make(fps : Float) -> TContext raise @types.LoadError { - 31●
if fps <= 0.0F { - 32●
raise @types.LoadError::DecodeFailed("TContext::make: fps 必须大于0") - 33
} - 34
{ current_time: 0.0F, fps, is_loop: false, paused: false, speed: 1.0F, } - 35
} - 36
- 37
///| - 38
/// 推进时间:按 fps 和 speed 推进 current_time,支持循环。 - 39
/// 推进一帧时间(考虑速度和循环) Advance time by one frame step, considering speed and is_loop. - 40
pub fn TContext::step(self : TContext, total_duration : Float) -> TContext { - 41●
if self.paused { - 42●
return self - 43
} - 44
let dt = 1.0F / self.fps * self.speed - 45
let mut new_time = self.current_time + dt - 46
if self.is_loop && total_duration > 0.0F { - 47●
while new_time >= total_duration { - 48●
new_time = new_time - total_duration - 49
} - 50
} - 51
{ ..self, current_time: new_time, } - 52
} - 53
- 54
///| - 55
/// 跳转到指定时间。 - 56
/// 跳转到特定时间 Seek to a specific time. - 57
pub fn TContext::seek(self : TContext, time : Float) -> TContext { - 58●
{ ..self, current_time: if time < 0.0F { 0.0F } else { time }, } - 59
} - 60
- 61
///| - 62
/// 暂停/恢复。 - 63
/// 暂停或恢复 Pause or resume. - 64
pub fn TContext::set_paused(self : TContext, paused : Bool) -> TContext { - 65●
{ ..self, paused, } - 66
} - 67
- 68
///| - 69
/// 设置播放速度。 - 70
/// 设置播放速度 Set playback speed. - 71
pub fn TContext::set_speed(self : TContext, speed : Float) -> TContext { - 72●
{ ..self, speed: if speed < 0.0F { 0.0F } else { speed }, } - 73
} - 74
- 75
///| - 76
/// 设置循环。 - 77
/// 设置循环模式 Set is_loop mode. - 78
pub fn TContext::set_loop(self : TContext, is_loop : Bool) -> TContext { - 79●
{ ..self, is_loop, } - 80
}