add rule fail rate property

This commit is contained in:
Crispy 2024-05-04 16:56:06 +02:00
parent ef14cef49b
commit 4d61184edd
2 changed files with 16 additions and 6 deletions

View file

@ -36,7 +36,8 @@ pub struct Rule {
pub flip_x: bool, pub flip_x: bool,
pub flip_y: bool, pub flip_y: bool,
pub rotate: bool, pub rotate: bool,
// probability: u8 #[serde(default)]
pub failrate: u8,
} }
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@ -131,6 +132,7 @@ impl Rule {
flip_x: false, flip_x: false,
flip_y: false, flip_y: false,
rotate: false, rotate: false,
failrate: 0,
} }
} }
@ -383,6 +385,11 @@ impl Dish {
return; return;
} }
let fail: u8 = random();
if rule.failrate > fail {
return;
}
let width = variant.width; let width = variant.width;
let height = variant.height; let height = variant.height;
let mut old_state = Vec::new(); let mut old_state = Vec::new();

View file

@ -10,7 +10,7 @@ use eframe::{
epaint::Hsva, epaint::Hsva,
NativeOptions, NativeOptions,
}; };
use egui::{collapsing_header::CollapsingState, PointerButton}; use egui::{collapsing_header::CollapsingState, DragValue, PointerButton};
use native_dialog::FileDialog; use native_dialog::FileDialog;
use rand::prelude::*; use rand::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -272,10 +272,13 @@ fn rule_editor(
rule.generate_variants(); rule.generate_variants();
} }
}); });
if ui.checkbox(&mut rule.rotate, "rotate").changed() { ui.horizontal(|ui| {
rule.generate_variants(); if ui.checkbox(&mut rule.rotate, "rotate").changed() {
} rule.generate_variants();
}
ui.label("fail rate");
ui.add(DragValue::new(&mut rule.failrate));
});
let cells_y = rule.height(); let cells_y = rule.height();
let cells_x = rule.width(); let cells_x = rule.width();
let patt_width = CSIZE * cells_x as f32; let patt_width = CSIZE * cells_x as f32;