mirror of
https://github.com/13hannes11/focus_annotator.git
synced 2024-09-03 23:21:01 +02:00
refactor split off application state file
This commit is contained in:
45
src/state/mod.rs
Normal file
45
src/state/mod.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::constants::NONE_STRING_OPTION;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AnnotationZStack {
|
||||
pub images: Vec<AnnotationImage>,
|
||||
pub best_index: Option<usize>,
|
||||
}
|
||||
|
||||
impl AnnotationZStack {
|
||||
pub fn new() -> Self {
|
||||
AnnotationZStack {
|
||||
images: Vec::<AnnotationImage>::new(),
|
||||
best_index: None,
|
||||
}
|
||||
}
|
||||
pub fn push(&mut self, image: AnnotationImage) -> &mut Self {
|
||||
self.images.push(image);
|
||||
self
|
||||
}
|
||||
pub fn first(self) -> Option<AnnotationImage> {
|
||||
self.images.first().map(|x| x.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AnnotationImage {
|
||||
pub image_path: String,
|
||||
pub neighbours: [Option<String>; 8],
|
||||
}
|
||||
|
||||
impl AnnotationImage {
|
||||
pub fn from_vec(image_path: String, neighbours: Vec<Option<String>>) -> Self {
|
||||
let mut _neighbours = [NONE_STRING_OPTION; 8];
|
||||
for (index, element) in (0..8).zip(neighbours.iter()) {
|
||||
_neighbours[index] = element.clone();
|
||||
}
|
||||
|
||||
AnnotationImage {
|
||||
image_path,
|
||||
neighbours: _neighbours,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user