rust/landgen/src/wavefront_collapse/generator.rs
author unC0Rr
Wed, 28 Aug 2024 17:16:23 +0200
branchtransitional_engine
changeset 16052 0fd23fc57947
parent 15956 c273908218f3
child 16053 3402b2185698
permissions -rw-r--r--
Make pascal engine link to hwengine-future and use WFC generator
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
     1
use super::tile_image::{Edge, TileImage};
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
     2
use super::wavefront_collapse::{CollapseRule, Tile, WavefrontCollapse};
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
     3
use crate::{LandGenerationParameters, LandGenerator};
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
     4
use integral_geometry::Size;
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
     5
use png::Decoder;
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
     6
use std::collections::HashSet;
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
     7
use std::fs::File;
15950
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
     8
use std::io::{BufReader, Result};
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
     9
use std::path::Path;
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    10
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    11
#[derive(Clone)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    12
pub struct EdgeDescription {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    13
    pub name: String,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    14
    pub reversed: Option<bool>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    15
    pub symmetrical: Option<bool>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    16
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    17
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    18
#[derive(Clone)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    19
pub struct EdgesDescription {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    20
    pub top: EdgeDescription,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    21
    pub right: EdgeDescription,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    22
    pub bottom: EdgeDescription,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    23
    pub left: EdgeDescription,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    24
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    25
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    26
#[derive(Clone)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    27
pub struct TileDescription {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    28
    pub name: String,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    29
    pub edges: EdgesDescription,
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    30
    pub is_negative: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    31
    pub can_flip: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    32
    pub can_mirror: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    33
    pub can_rotate90: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    34
    pub can_rotate180: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    35
    pub can_rotate270: Option<bool>,
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    36
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    37
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    38
#[derive(Clone)]
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
    39
pub struct NonStrictEdgesDescription {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
    40
    pub top: Option<EdgeDescription>,
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
    41
    pub right: Option<EdgeDescription>,
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
    42
    pub bottom: Option<EdgeDescription>,
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
    43
    pub left: Option<EdgeDescription>,
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
    44
}
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
    45
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
    46
#[derive(Clone)]
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    47
pub struct TemplateDescription {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    48
    pub size: Size,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    49
    pub tiles: Vec<TileDescription>,
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
    50
    pub edges: NonStrictEdgesDescription,
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    51
    pub wrap: bool,
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    52
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    53
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    54
pub struct WavefrontCollapseLandGenerator {
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    55
    pub template: TemplateDescription,
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    56
}
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    57
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    58
impl WavefrontCollapseLandGenerator {
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    59
    pub fn new(template: TemplateDescription) -> Self {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
    60
        Self { template }
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    61
    }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    62
15950
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
    63
    fn load_image_tiles<T: Copy + PartialEq + Default>(
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    64
        parameters: &LandGenerationParameters<T>,
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    65
        tile_description: &TileDescription,
15950
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
    66
    ) -> Result<Vec<TileImage<T, String>>> {
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    67
        let mut result = Vec::new();
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    68
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    69
        let file = File::open(
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    70
            Path::new("../share/hedgewars/Data/Tiles")
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    71
                .join(&tile_description.name)
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    72
                .as_path(),
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    73
        )?;
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    74
        let decoder = Decoder::new(BufReader::new(file));
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    75
        let mut reader = decoder.read_info().unwrap();
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    76
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    77
        let info = reader.info();
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    78
        let mut tiles_image = vec2d::Vec2D::new(
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    79
            &Size::new(info.width as usize, info.height as usize),
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    80
            parameters.zero,
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    81
        );
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    82
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    83
        let mut buf = vec![0; reader.output_buffer_size()];
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    84
        let info = reader.next_frame(&mut buf).unwrap();
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    85
        let bytes = &buf[..info.buffer_size()];
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    86
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    87
        let mut tiles_image_pixels = tiles_image.as_mut_slice().iter_mut();
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    88
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    89
        let (zero, basic) = if tile_description.is_negative.unwrap_or_default() {
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    90
            (parameters.basic(), parameters.zero())
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    91
        } else {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    92
            (parameters.zero(), parameters.basic())
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    93
        };
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    94
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    95
        match info.color_type.samples() {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    96
            1 => {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    97
                for line in bytes.chunks_exact(info.line_size) {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    98
                    for value in line.iter() {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    99
                        *tiles_image_pixels
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   100
                            .next()
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   101
                            .expect("vec2d size matching image dimensions") =
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   102
                            if *value == 0 { zero } else { basic };
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   103
                    }
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   104
                }
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   105
            }
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   106
            a => {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   107
                for line in bytes.chunks_exact(info.line_size) {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   108
                    for value in line.chunks_exact(a) {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   109
                        print!("{:?},", value);
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   110
                        *tiles_image_pixels
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   111
                            .next()
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   112
                            .expect("vec2d size matching image dimensions") =
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   113
                            if value[0] == 0u8 { zero } else { basic };
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   114
                    }
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   115
                }
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   116
            }
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   117
        }
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   118
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   119
        let [top_edge, right_edge, bottom_edge, left_edge]: [Edge<String>; 4] = [
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   120
            (&tile_description.edges.top).into(),
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   121
            (&tile_description.edges.right).into(),
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   122
            (&tile_description.edges.bottom).into(),
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   123
            (&tile_description.edges.left).into(),
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   124
        ];
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   125
15956
c273908218f3 Format the code, apply clippy fixes
unC0Rr
parents: 15955
diff changeset
   126
        let tile =
c273908218f3 Format the code, apply clippy fixes
unC0Rr
parents: 15955
diff changeset
   127
            TileImage::<T, String>::new(tiles_image, top_edge, right_edge, bottom_edge, left_edge);
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   128
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   129
        result.push(tile.clone());
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   130
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   131
        if tile_description.can_flip.unwrap_or_default() {
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   132
            result.push(tile.flipped());
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   133
        }
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   134
        if tile_description.can_mirror.unwrap_or_default() {
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   135
            result.push(tile.mirrored());
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   136
        }
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   137
        if tile_description.can_flip.unwrap_or_default()
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   138
            && tile_description.can_mirror.unwrap_or_default()
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   139
        {
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   140
            result.push(tile.mirrored().flipped());
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   141
        }
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   142
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   143
        if tile_description.can_rotate90.unwrap_or_default() {
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   144
            result.push(tile.rotated90());
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   145
        }
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   146
        if tile_description.can_rotate180.unwrap_or_default() {
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   147
            result.push(tile.rotated180());
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   148
        }
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   149
        if tile_description.can_rotate270.unwrap_or_default() {
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   150
            result.push(tile.rotated270());
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   151
        }
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   152
15950
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   153
        Ok(result)
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   154
    }
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   155
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   156
    pub fn load_template<T: Copy + PartialEq + Default>(
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   157
        &self,
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   158
        parameters: &LandGenerationParameters<T>,
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   159
    ) -> Vec<TileImage<T, String>> {
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   160
        let mut result = Vec::new();
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   161
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   162
        for tile_description in self.template.tiles.iter() {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   163
            if let Ok(mut tiles) = Self::load_image_tiles(parameters, tile_description) {
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   164
                result.append(&mut tiles);
16052
0fd23fc57947 Make pascal engine link to hwengine-future and use WFC generator
unC0Rr
parents: 15956
diff changeset
   165
            } else {
0fd23fc57947 Make pascal engine link to hwengine-future and use WFC generator
unC0Rr
parents: 15956
diff changeset
   166
                eprintln!("Failed to load a tile!");
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
   167
            }
15950
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   168
        }
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   169
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   170
        result
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   171
    }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   172
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   173
    pub fn build_rules<T: Copy + PartialEq + Default>(
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   174
        &self,
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   175
        tiles: &[TileImage<T, String>],
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   176
    ) -> Vec<CollapseRule> {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   177
        let [grid_top_edge, grid_right_edge, grid_bottom_edge, grid_left_edge]: [Option<
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   178
            Edge<String>,
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   179
        >; 4] = [
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   180
            self.template.edges.top.as_ref(),
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   181
            self.template.edges.right.as_ref(),
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   182
            self.template.edges.bottom.as_ref(),
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   183
            self.template.edges.left.as_ref(),
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   184
        ]
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   185
        .map(|opt| opt.map(|d| d.into()));
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   186
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   187
        let mut rules = Vec::<CollapseRule>::new();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   188
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   189
        let default_connection = HashSet::from_iter(vec![Tile::Empty].into_iter());
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   190
        for (i, tile) in tiles.iter().enumerate() {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   191
            let mut right = default_connection.clone();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   192
            let mut bottom = default_connection.clone();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   193
            let mut left = default_connection.clone();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   194
            let mut top = default_connection.clone();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   195
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   196
            // compatibility with grid edges
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   197
            if grid_top_edge
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   198
                .as_ref()
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   199
                .map(|e| e.is_compatible(tile.top_edge()))
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   200
                .unwrap_or(true)
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   201
            {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   202
                top.insert(Tile::Outside);
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   203
            }
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   204
            if grid_right_edge
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   205
                .as_ref()
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   206
                .map(|e| e.is_compatible(tile.right_edge()))
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   207
                .unwrap_or(true)
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   208
            {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   209
                right.insert(Tile::Outside);
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   210
            }
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   211
            if grid_bottom_edge
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   212
                .as_ref()
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   213
                .map(|e| e.is_compatible(tile.bottom_edge()))
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   214
                .unwrap_or(true)
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   215
            {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   216
                bottom.insert(Tile::Outside);
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   217
            }
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   218
            if grid_left_edge
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   219
                .as_ref()
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   220
                .map(|e| e.is_compatible(tile.left_edge()))
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   221
                .unwrap_or(true)
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   222
            {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   223
                left.insert(Tile::Outside);
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   224
            }
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   225
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   226
            // compatibility with itself
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   227
            if tile.left_edge().is_compatible(tile.right_edge()) {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   228
                left.insert(Tile::Numbered(i));
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   229
                right.insert(Tile::Numbered(i));
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   230
            }
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   231
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   232
            if tile.top_edge().is_compatible(tile.bottom_edge()) {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   233
                top.insert(Tile::Numbered(i));
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   234
                bottom.insert(Tile::Numbered(i));
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   235
            }
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   236
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   237
            // compatibility with previously defined tiles
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   238
            for p in 0..i {
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   239
                if tiles[p].left_edge().is_compatible(tile.right_edge()) {
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   240
                    rules[p].left.insert(Tile::Numbered(i));
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   241
                    right.insert(Tile::Numbered(p));
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   242
                }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   243
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   244
                if tiles[p].right_edge().is_compatible(tile.left_edge()) {
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   245
                    rules[p].right.insert(Tile::Numbered(i));
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   246
                    left.insert(Tile::Numbered(p));
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   247
                }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   248
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   249
                if tiles[p].top_edge().is_compatible(tile.bottom_edge()) {
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   250
                    rules[p].top.insert(Tile::Numbered(i));
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   251
                    bottom.insert(Tile::Numbered(p));
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   252
                }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   253
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   254
                if tiles[p].bottom_edge().is_compatible(tile.top_edge()) {
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   255
                    rules[p].bottom.insert(Tile::Numbered(i));
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   256
                    top.insert(Tile::Numbered(p));
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   257
                }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   258
            }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   259
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   260
            rules.push(CollapseRule {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   261
                tile: Tile::Numbered(i),
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   262
                top,
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   263
                right,
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   264
                bottom,
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   265
                left,
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   266
            });
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   267
        }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   268
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   269
        rules
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   270
    }
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   271
}
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   272
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   273
impl LandGenerator for WavefrontCollapseLandGenerator {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   274
    fn generate_land<T: Copy + PartialEq + Default, I: Iterator<Item = u32>>(
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   275
        &self,
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   276
        parameters: &LandGenerationParameters<T>,
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   277
        random_numbers: &mut I,
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   278
    ) -> land2d::Land2D<T> {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   279
        let tiles = self.load_template(parameters);
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   280
        let rules = self.build_rules(&tiles);
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   281
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   282
        let mut wfc = WavefrontCollapse::new(self.template.wrap);
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   283
        wfc.set_rules(rules);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   284
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   285
        let wfc_size = if let Some(first_tile) = tiles.first() {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   286
            let tile_size = first_tile.size();
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   287
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   288
            Size::new(
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
   289
                self.template.size.width / tile_size.width,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
   290
                self.template.size.height / tile_size.height,
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   291
            )
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   292
        } else {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   293
            Size::new(1, 1)
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   294
        };
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   295
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   296
        wfc.generate_map(&wfc_size, |_| {}, random_numbers);
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   297
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   298
        // render tiles into resulting land array
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15950
diff changeset
   299
        let mut result = land2d::Land2D::new(&self.template.size, parameters.zero);
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   300
        let offset_y = result.height() - result.play_height();
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   301
        let offset_x = (result.width() - result.play_width()) / 2;
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   302
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   303
        for row in 0..wfc_size.height {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   304
            for column in 0..wfc_size.width {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   305
                if let Some(Tile::Numbered(tile_index)) = wfc.grid().get(row, column) {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   306
                    let tile = &tiles[*tile_index];
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   307
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   308
                    for tile_row in 0..tile.size().height {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   309
                        for tile_column in 0..tile.size().width {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   310
                            result.map(
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   311
                                (row * tile.size().height + tile_row + offset_y) as i32,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
   312
                                (column * tile.size().width + tile_column + offset_x) as i32,
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   313
                                |p| {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   314
                                    *p =
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   315
                                        *tile.get(tile_row, tile_column).unwrap_or(&parameters.zero)
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   316
                                },
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   317
                            );
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   318
                        }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   319
                    }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   320
                }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   321
            }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   322
        }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   323
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   324
        result
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   325
    }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   326
}
15955
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   327
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   328
impl From<&EdgeDescription> for Edge<String> {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   329
    fn from(val: &EdgeDescription) -> Self {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   330
        let edge = Edge::new(val.name.clone(), val.symmetrical.unwrap_or_default());
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   331
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   332
        if val.reversed.unwrap_or_default() {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   333
            edge.reversed()
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   334
        } else {
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   335
            edge
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   336
        }
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   337
    }
b0e8cc72bfef Allow defining compatible edges for grid, add few more templates
unC0Rr
parents: 15954
diff changeset
   338
}