rust/landgen/src/outline_template.rs
author unc0rr
Sat, 03 Nov 2018 18:29:58 +0100
changeset 14142 69db1d2e4cec
parent 14121 4d22be35cfa2
child 14147 32383b888309
permissions -rw-r--r--
land_dump app for testing templated landgen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14090
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     1
use integral_geometry::{Point, Rect, Size};
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     2
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     3
pub struct OutlineTemplate {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     4
    pub islands: Vec<Vec<Rect>>,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     5
    pub fill_points: Vec<Point>,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     6
    pub size: Size,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     7
    pub can_flip: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     8
    pub can_invert: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     9
    pub can_mirror: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    10
    pub is_negative: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    11
}
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    12
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    13
impl OutlineTemplate {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    14
    pub fn new(size: Size) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    15
        OutlineTemplate {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    16
            size,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    17
            islands: Vec::new(),
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    18
            fill_points: Vec::new(),
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    19
            can_flip: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    20
            can_invert: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    21
            can_mirror: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    22
            is_negative: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    23
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    24
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    25
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    26
    pub fn flippable(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    27
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    28
            can_flip: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    29
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    30
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    31
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    32
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    33
    pub fn mirrorable(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    34
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    35
            can_mirror: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    36
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    37
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    38
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    39
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    40
    pub fn invertable(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    41
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    42
            can_invert: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    43
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    44
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    45
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    46
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    47
    pub fn negative(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    48
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    49
            is_negative: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    50
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    51
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    52
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    53
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    54
    pub fn with_fill_points(self, fill_points: Vec<Point>) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    55
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    56
            fill_points,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    57
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    58
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    59
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    60
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    61
    pub fn with_islands(self, islands: Vec<Vec<Rect>>) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    62
        Self { islands, ..self }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    63
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    64
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    65
    pub fn add_fill_points(mut self, points: &[Point]) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    66
        self.fill_points.extend_from_slice(points);
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    67
        self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    68
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    69
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    70
    pub fn add_island(mut self, island: &[Rect]) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    71
        self.islands.push(island.into());
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    72
        self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    73
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    74
}