impl ComparisonView {
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new(recording_a: Recording, recording_b: Recording) -> Self {
let name_a = recording_a.metadata().program.clone();
let name_b = recording_b.metadata().program.clone();
Self {
player_a: TimelinePlayer::new(recording_a),
player_b: TimelinePlayer::new(recording_b),
sync_mode: SyncMode::ByFrame,
name_a,
name_b,
}
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn current_frame_a(&self) -> usize {
self.player_a.current_frame()
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn current_frame_b(&self) -> usize {
self.player_b.current_frame()
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn total_frames_a(&self) -> usize {
self.player_a.total_frames()
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn total_frames_b(&self) -> usize {
self.player_b.total_frames()
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn total_frames_min(&self) -> usize {
self.total_frames_a().min(self.total_frames_b())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn total_frames_max(&self) -> usize {
self.total_frames_a().max(self.total_frames_b())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn recording_a_exhausted(&self) -> bool {
let total = self.total_frames_a();
if total == 0 {
return true;
}
self.current_frame_a() >= total - 1
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn recording_b_exhausted(&self) -> bool {
let total = self.total_frames_b();
if total == 0 {
return true;
}
self.current_frame_b() >= total - 1
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn sync_mode(&self) -> SyncMode {
self.sync_mode
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn set_sync_mode(&mut self, mode: SyncMode) {
self.sync_mode = mode;
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn next_frame(&mut self) -> Result<()> {
let a_result = self.player_a.next_frame();
let b_result = self.player_b.next_frame();
if a_result.is_none() && b_result.is_none() {
anyhow::bail!("Both recordings exhausted");
}
Ok(())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn prev_frame(&mut self) -> Result<()> {
let a_result = self.player_a.prev_frame();
let b_result = self.player_b.prev_frame();
if a_result.is_none() && b_result.is_none() {
anyhow::bail!("Both recordings at start");
}
Ok(())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn jump_to(&mut self, frame: usize) -> Result<()> {
let a_result = self.player_a.jump_to(frame);
let b_result = self.player_b.jump_to(frame);
if a_result.is_err() && b_result.is_err() {
anyhow::bail!("Frame {} out of bounds for both recordings", frame);
}
Ok(())
}
}