use super::tracks;
use crate::check::{Check, CheckCtx};
use crate::finding::{Finding, Severity};
pub const FIRST_KEY_SLACK_S: f32 = 0.017;
pub const NEGATIVE_TIME_TOLERANCE_S: f32 = 1e-4;
pub struct TimeMonotonic;
impl Check for TimeMonotonic {
fn id(&self) -> &'static str {
"time-monotonic"
}
fn run(&self, ctx: &CheckCtx, out: &mut Vec<Finding>) {
let doc = ctx.doc;
for (clip, bone, track) in tracks(doc) {
let times = &track.times;
if times.is_empty() {
continue;
}
if times[0] < -NEGATIVE_TIME_TOLERANCE_S {
out.push(
Finding::new(
self.id(),
Severity::Error,
format!("negative key time in {} track", track.property.as_str()),
)
.clip(clip)
.bone(bone)
.time(times[0])
.measured(times[0]),
);
}
if let Some(k) = (1..times.len()).find(|&k| times[k] <= times[k - 1]) {
out.push(
Finding::new(
self.id(),
Severity::Error,
format!(
"key times not strictly increasing in {} track (keys {} and {})",
track.property.as_str(),
k - 1,
k
),
)
.clip(clip)
.bone(bone)
.time(times[k]),
);
}
if times[0] > FIRST_KEY_SLACK_S {
out.push(
Finding::new(
self.id(),
Severity::Note,
format!(
"first key of {} track starts at {:.3}s, not 0 — the pose is \
clamp-held until then",
track.property.as_str(),
times[0]
),
)
.clip(clip)
.bone(bone)
.time(times[0])
.measured(times[0])
.expected(0.0f64),
);
}
}
}
}