rust/landgen/src/lib.rs
author alfadur
Fri, 02 Nov 2018 20:46:17 +0300
changeset 14114 dbaa125a0fe9
parent 14090 abb42ba345b6
child 14121 4d22be35cfa2
permissions -rw-r--r--
fix infinite loop in landgen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14075
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14072
diff changeset
     1
pub mod template_based;
14090
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents: 14075
diff changeset
     2
pub mod outline_template;
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents: 14075
diff changeset
     3
mod outline;
13929
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
     4
13959
1fa905aa4cdb move point struct into integral-geometry and use it to refactor a bit
alfadur
parents: 13929
diff changeset
     5
extern crate integral_geometry;
14047
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
     6
extern crate land2d;
14072
8a0d69c16cad Implement OutlinePoints for land generators, some ground work for template based landgen
unc0rr
parents: 14048
diff changeset
     7
extern crate itertools;
14047
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
     8
14048
cef0c685fda8 make useful stuff public
alfadur
parents: 14047
diff changeset
     9
pub struct LandGenerationParameters<T> {
14047
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    10
    zero: T,
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    11
    basic: T,
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    12
}
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    13
14075
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14072
diff changeset
    14
impl <T: Copy + PartialEq> LandGenerationParameters<T> {
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14072
diff changeset
    15
    pub fn new(zero: T, basic: T) -> Self {
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14072
diff changeset
    16
        Self { zero, basic }
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14072
diff changeset
    17
    }
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14072
diff changeset
    18
}
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14072
diff changeset
    19
14048
cef0c685fda8 make useful stuff public
alfadur
parents: 14047
diff changeset
    20
pub trait LandGenerator {
14047
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    21
    fn generate_land<T: Copy + PartialEq, I: Iterator<Item = u32>>(
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    22
        &self,
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    23
        parameters: LandGenerationParameters<T>,
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    24
        random_numbers: &mut I,
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    25
    ) -> land2d::Land2D<T>;
3b3d97ed2286 Start land generators implementation
unc0rr
parents: 13959
diff changeset
    26
}
13959
1fa905aa4cdb move point struct into integral-geometry and use it to refactor a bit
alfadur
parents: 13929
diff changeset
    27
13929
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    28
#[cfg(test)]
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    29
mod tests {
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    30
    #[test]
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    31
    fn it_works() {
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    32
        assert_eq!(2 + 2, 4);
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    33
    }
9a1f1e8170f2 Start work on landgen rust lib
unc0rr
parents:
diff changeset
    34
}