///|
/// A deterministic scene recipe that turns a seed into reusable design layers.
pub(all) struct SceneRecipe {
  seed : UInt
  width : Double
  height : Double
  columns : Int
  rows : Int
  palette : Palette
} derive(Eq, Debug, ToJson)

///|
pub fn SceneRecipe::new(
  seed : UInt,
  width : Double,
  height : Double,
  columns : Int,
  rows : Int,
  palette : Palette,
) -> SceneRecipe {
  { seed, width, height, columns, rows, palette }
}

///|
pub fn SceneRecipe::build(self : SceneRecipe) -> Composition {
  let composition = Composition::new(
    self.width,
    self.height,
    background=self.palette.at(0).unwrap_or(Color::rgb8(255, 255, 255)),
  )
  let layer = PatternLayer::new("procedural-field")
  let sampler = ValueNoise::new(0.035, self.seed)
  let cell_width = self.width / self.columns.to_double()
  let cell_height = self.height / self.rows.to_double()
  let colors = if self.palette.colors.length() > 1 {
    self.palette.colors
  } else {
    [Color::rgb8(0, 0, 0), Color::rgb8(255, 255, 255)]
  }
  for row in 0.. String {
  SceneRecipe::new(seed, width, height, columns, rows, sunset_palette())
  .build()
  .render()
  .to_svg_string()
}

///|
pub fn scene_metrics(recipe : SceneRecipe) -> LayoutMetrics {
  let composition = recipe.build()
  let paths = []
  for layer in composition.layers {
    for motif in layer.motifs {
      paths.push(motif.transformed_path())
    }
  }
  measure_paths(paths, Rect::new(0.0, 0.0, recipe.width, recipe.height))
}