eau: lissage sans melange des composantes voisines, y en floor
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
01660947f4
révision
7acda01811
2 fichiers modifiés
+62
-4
Aucun fichier ne correspond à votre recherche
+22
-4
@@ -1,5 +1,5 @@
|
||||
//! Prototype 11 : eau (rivieres creusees, niveaux en blocs, plans d'eau, berges).
|
||||
//! 1 bloc = 1 m vertical ; y_bloc = round(altitude - alt_base). Aucune dependance.
|
||||
//! 1 bloc = 1 m vertical ; y_bloc = floor(altitude - alt_base), comme rt-core::alt_to_y. Aucune dependance.
|
||||
use std::cmp::Reverse;
|
||||
use std::collections::BinaryHeap;
|
||||
|
||||
@@ -38,6 +38,7 @@ pub struct Colonne {
|
||||
pub struct Params { pub alt_base: f32, pub rayon_berge: usize, pub pas_max: i16 }
|
||||
impl Default for Params { fn default() -> Self { Self { alt_base: 0.0, rayon_berge: 3, pas_max: 1 } } }
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Stats { pub composantes_rivieres: usize, pub lacs: usize, pub pixels_ecretes: usize, pub largeur_max_m: f32 }
|
||||
|
||||
pub struct CarteEau {
|
||||
@@ -106,7 +107,7 @@ pub fn construire(mnt: &[f32], eau: &[u8], w: usize, h: usize, p: &Params) -> Ca
|
||||
assert_eq!(mnt.len(), w * h);
|
||||
assert_eq!(eau.len(), w * h);
|
||||
let n = w * h;
|
||||
let yb = |a: f32| -> i16 { (a - p.alt_base).round() as i16 };
|
||||
let yb = |a: f32| -> i16 { (a - p.alt_base).floor() as i16 };
|
||||
let dem: Vec<i16> = mnt.iter().map(|&a| yb(a)).collect();
|
||||
let mut niveau = vec![AUCUN; n];
|
||||
let mut fond = vec![AUCUN; n];
|
||||
@@ -135,7 +136,8 @@ pub fn construire(mnt: &[f32], eau: &[u8], w: usize, h: usize, p: &Params) -> Ca
|
||||
stats.composantes_rivieres += 1;
|
||||
// lissage du niveau brut le long de la riviere (moyenne masquee 13x13, 2 passes)
|
||||
let mut lis: Vec<f32> = vec![0.0; n];
|
||||
for &i in &comp { lis[i] = mnt[i]; }
|
||||
let mut dans = vec![false; n]; // la moyenne ne doit pas melanger les composantes voisines
|
||||
for &i in &comp { lis[i] = mnt[i]; dans[i] = true; }
|
||||
for _ in 0..2 {
|
||||
let src = lis.clone();
|
||||
for &i in &comp {
|
||||
@@ -145,7 +147,7 @@ pub fn construire(mnt: &[f32], eau: &[u8], w: usize, h: usize, p: &Params) -> Ca
|
||||
let (nx, ny) = (x + dx, y + dy);
|
||||
if nx >= 0 && ny >= 0 && nx < w as i32 && ny < h as i32 {
|
||||
let j = ny as usize * w + nx as usize;
|
||||
if riv[j] { s += src[j]; c += 1.0; }
|
||||
if dans[j] { s += src[j]; c += 1.0; }
|
||||
}
|
||||
} }
|
||||
lis[i] = s / c;
|
||||
@@ -353,4 +355,20 @@ mod tests {
|
||||
assert!(etiage.eau_haut.map_or(true, |t| t == n - 1));
|
||||
assert_eq!(EtatEau { debit_rel: 0.7, lac_gele: false }.decalage_riviere(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn composantes_voisines_independantes() {
|
||||
// deux ruisseaux a 4 px d'ecart, l'un a 100 m, l'autre a 900 m : pas de melange des niveaux
|
||||
let (w, h) = (30usize, 12usize);
|
||||
let mut mnt = vec![0.0f32; w * h];
|
||||
let mut e = vec![0u8; w * h];
|
||||
for r in 0..h { for c in 0..w {
|
||||
let haut = c >= 15;
|
||||
mnt[r * w + c] = if haut { 900.0 } else { 100.0 };
|
||||
if c == 13 || c == 17 { e[r * w + c] = COURS; }
|
||||
} }
|
||||
let m = construire(&mnt, &e, w, h, &Params { alt_base: 0.0, rayon_berge: 2, pas_max: 1 });
|
||||
assert_eq!(m.niveau[5 * w + 13], 100);
|
||||
assert_eq!(m.niveau[5 * w + 17], 900);
|
||||
}
|
||||
}
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur