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