123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- use clap::{ArgAction, Parser};
- use crate::tiles::TileType;
- use crate::tiling::{MissingTilePolicy, VacancyPolicy};
- /// Program to generate a larger image made up of different image tiles of the
- /// same size
- #[derive(Parser)]
- #[command(author, version, about)]
- #[deny(missing_docs)]
- pub struct Arguments {
- /// Number of rows
- pub rows: u8,
- /// Number of columns
- pub cols: u8,
- /// Optional connector name that tiles must exhibit towards the border of
- /// the image; if this option is omitted, bordering tiles may have any
- /// connection towards the border.
- #[arg(short, long, value_name = "CONNECTOR_NAME")]
- pub border: Option<String>,
- /// Optional path to a tile configuration file; overrides any configuration
- /// file in the tile directory.
- #[arg(short, long, group = "config_arg_group", value_name = "PATH")]
- pub config: Option<String>,
- /// Optional path to a tile directory; if omitted, assume the current
- /// working directory.
- ///
- /// The directory may contain a tile configuration file named “config.yaml”.
- #[arg(short = 'd', long, value_name = "PATH")]
- pub tile_directory: Option<String>,
- #[rustfmt::skip]
- /// Optional policy name that specifies how to behave in case there is no
- /// tile with a required connectors list.
- ///
- /// MISSING_TILE_POLICY may have one of the following values:
- /// - avoid: Try to avoid leaving empty positions in the tile grid. This may
- /// take a considerable amount of time and memory to finish due to
- /// backtracking. The run may terminate unsuccessfully in case
- /// there is no solution.
- /// - exit: (default) Exit immediately if there is no fitting tile; this
- /// may be useful for debugging tile configurations.
- #[arg(short, long, default_value_t = MissingTilePolicy::Exit,
- verbatim_doc_comment)]
- pub missing_tile_policy: MissingTilePolicy,
- /// Do not use any user defined tile configuration; Instead, assume all
- /// tiles have the connectors
- /// { north: “c”, south: “c”, east: “c”, west: “c” }
- /// and a weight of 1.
- #[arg(short, long, group = "config_arg_group", action = ArgAction::SetTrue)]
- pub no_config: bool,
- /// Path to the output file
- #[arg(short, long, value_name = "PATH", default_value = "output/tiled")]
- pub output: String,
- #[rustfmt::skip]
- /// Optional type of tiles; if omitted, the type is guessed by inspecting
- /// the tile configuration (see option “--config”).
- ///
- /// TILE_TYPE may have one of the following values:
- /// - raster: raster graphics tiles, e.g. PNG, JPEG or GIF
- /// - svg: SVG (Scalable Vector Graphics) tiles
- /// - text: text based tiles, e.g. for ASCII art
- #[arg(short, long, verbatim_doc_comment)]
- pub tile_type: Option<TileType>,
- #[rustfmt::skip]
- /// Optional policy name that specifies how to handle vacant areas without
- /// adjacent open connections.
- ///
- /// VACANCY_POLICY may have one of the following values:
- /// - avoid: Try to avoid leaving vacant areas in the tile grid.
- /// This may take a considerable amount of time and memory to
- /// finish due to backtracking. The run may terminate
- /// unsuccessfully in case there is no solution.
- /// - ignore: Ignore and vacant areas in the tile grid untouched.
- #[arg(short, long, default_value_t = VacancyPolicy::Ignore, verbatim_doc_comment)]
- pub vacancy_policy: VacancyPolicy,
- }
- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn test_initialization() {
- let arguments = Arguments {
- rows: 1,
- cols: 2,
- config: Some("config.yaml".to_string()),
- border: Some("brd".to_string()),
- missing_tile_policy: MissingTilePolicy::Avoid,
- no_config: false,
- output: "file".to_string(),
- tile_directory: Some("/dir".to_string()),
- tile_type: Some(TileType::Text),
- vacancy_policy: VacancyPolicy::Ignore,
- };
- assert_eq!(1, arguments.rows);
- assert_eq!(2, arguments.cols);
- assert_eq!(Some("config.yaml".to_string()), arguments.config);
- assert_eq!(Some("brd".to_string()), arguments.border);
- assert_eq!(MissingTilePolicy::Avoid, arguments.missing_tile_policy);
- assert_eq!(arguments.no_config, false);
- assert_eq!(arguments.output, "file".to_string());
- assert_eq!(arguments.tile_directory, Some("/dir".to_string()));
- assert_eq!(arguments.tile_type, Some(TileType::Text));
- assert_eq!(arguments.vacancy_policy, VacancyPolicy::Ignore);
- }
- }
|