lj_qualibration/src/qualibration/sequence/wait_space.rs

118 lines
2.8 KiB
Rust

use super::{super::Param, Sequence};
use crate::{
draw::{draw_line, draw_line_dotted},
point::{Color, Point},
};
use opencv::Result;
#[derive(Debug, Clone, Copy)]
pub struct WaitSpace {
borders: [Point; 4],
mid: [Point; 2],
nb_millis: u64,
}
impl WaitSpace {
pub fn new(beg: Point, end: Point, nb_millis: u64) -> Self {
let mid = (end.y - beg.y) * 0.5 + beg.y;
Self {
borders: [
Point {
x: beg.x,
y: beg.y,
color: end.color,
},
Point {
x: end.x,
y: beg.y,
color: end.color,
},
Point {
x: end.x,
y: end.y,
color: end.color,
},
Point {
x: beg.x,
y: end.y,
color: end.color,
},
],
mid: [
Point {
x: beg.x,
y: mid,
color: end.color,
},
Point {
x: end.x,
y: mid,
color: end.color,
},
],
nb_millis,
}
}
}
impl Sequence for WaitSpace {
fn draw(&self, mem: &Param) -> Option<Vec<Point>> {
if mem.key == 32 || !mem.capture_mode {
return None;
}
let mut pl = vec![];
let color = Color {
r: mem.r as u8,
g: mem.g as u8,
b: mem.b as u8,
};
for i in 0..self.borders.len() {
let id1 = (i + 1) % self.borders.len();
let p0 = Point {
color,
..self.borders[i]
};
let p1 = Point {
color,
..self.borders[id1]
};
pl.extend(draw_line(
&p0,
&p1,
mem.nb_all as usize,
mem.nb_visible as usize,
));
pl.extend(draw_line_dotted(
&Point {
color,
..self.mid[0]
},
&Point {
color,
..self.mid[1]
},
mem.nb_all as usize,
mem.nb_visible as usize,
true,
));
}
Some(pl)
}
fn compute_sequence(&mut self, _mem: &mut Param) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
fn is_capture(&self) -> bool {
false
}
fn sequence_name(&self) -> String {
"Wait_Space".to_owned()
}
fn wait_milis(&self) -> u64 {
self.nb_millis
}
}