Skip to main content

terrain_forge/
algorithm.rs

1//! Algorithm trait for procedural generation
2
3use crate::{Cell, Grid};
4
5/// Trait for procedural generation algorithms
6pub trait Algorithm<C: Cell = crate::Tile> {
7    /// Generate content into the grid using the given seed
8    fn generate(&self, grid: &mut Grid<C>, seed: u64);
9
10    /// Algorithm name for identification
11    fn name(&self) -> &'static str;
12}
13
14impl<C: Cell> Algorithm<C> for Box<dyn Algorithm<C>> {
15    fn generate(&self, grid: &mut Grid<C>, seed: u64) {
16        (**self).generate(grid, seed)
17    }
18
19    fn name(&self) -> &'static str {
20        (**self).name()
21    }
22}