rust/landgen/src/template_based.rs
author alfadur
Tue, 30 Oct 2018 19:05:52 +0300
changeset 14032 2869c2ccb1b8
parent 14026 3b3d97ed2286
child 14052 9c817b2eedae
permissions -rw-r--r--
extract size struct for common usage
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14026
diff changeset
     1
use integral_geometry::{Point, Size};
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
     2
use land2d::Land2D;
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
     3
use LandGenerationParameters;
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
     4
use LandGenerator;
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
     5
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
     6
struct OutlineTemplate {
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
     7
    islands: Vec<Vec<Point>>,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
     8
    fill_points: Vec<Point>,
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14026
diff changeset
     9
    size: Size,
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    10
    can_flip: bool,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    11
    can_invert: bool,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    12
    can_mirror: bool,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    13
    is_negative: bool,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    14
}
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    15
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    16
struct TemplatedLandGenerator {
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    17
    outline_template: OutlineTemplate,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    18
}
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    19
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    20
impl OutlineTemplate {}
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    21
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    22
impl TemplatedLandGenerator {
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    23
    fn new(outline_template: OutlineTemplate) -> Self {
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    24
        Self { outline_template }
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    25
    }
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    26
}
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    27
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    28
impl LandGenerator for TemplatedLandGenerator {
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    29
    fn generate_land<T: Copy + PartialEq, I: Iterator<Item = u32>>(
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    30
        &self,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    31
        parameters: LandGenerationParameters<T>,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    32
        random_numbers: &mut I,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    33
    ) -> Land2D<T> {
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    34
        let mut pa = Vec::new();
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    35
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    36
        for island in &self.outline_template.islands {
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    37
            let mut island_points = Vec::new();
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    38
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    39
            for p in island {
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    40
                island_points.push(p);
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    41
            }
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    42
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    43
            pa.push(island_points);
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    44
        }
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    45
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    46
        let mut land = Land2D::new(
14032
2869c2ccb1b8 extract size struct for common usage
alfadur
parents: 14026
diff changeset
    47
            self.outline_template.size,
14026
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    48
            parameters.basic,
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    49
        );
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    50
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    51
        land
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    52
    }
3b3d97ed2286 Start land generators implementation
unc0rr
parents:
diff changeset
    53
}