rust/landgen/src/outline_template.rs
author unC0Rr
Fri, 02 Nov 2018 09:45:54 +0100
changeset 14074 abb42ba345b6
child 14105 4d22be35cfa2
permissions -rw-r--r--
Rework lib structure, no code changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14074
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
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     4
pub struct OutlineTemplate {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     5
    pub islands: Vec<Vec<Rect>>,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     6
    pub fill_points: Vec<Point>,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     7
    pub size: Size,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     8
    pub can_flip: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     9
    pub can_invert: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    10
    pub can_mirror: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    11
    pub is_negative: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    12
}
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    13
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    14
impl OutlineTemplate {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    15
    pub fn new(size: Size) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    16
        OutlineTemplate {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    17
            size,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    18
            islands: Vec::new(),
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    19
            fill_points: Vec::new(),
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    20
            can_flip: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    21
            can_invert: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    22
            can_mirror: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    23
            is_negative: false,
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
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    27
    pub fn flippable(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    28
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    29
            can_flip: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    30
            ..self
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
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    34
    pub fn mirrorable(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    35
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    36
            can_mirror: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    37
            ..self
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
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    41
    pub fn invertable(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    42
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    43
            can_invert: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    44
            ..self
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
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    48
    pub fn negative(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    49
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    50
            is_negative: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    51
            ..self
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
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    55
    pub fn with_fill_points(self, fill_points: Vec<Point>) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    56
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    57
            fill_points,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    58
            ..self
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
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    62
    pub fn with_islands(self, islands: Vec<Vec<Rect>>) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    63
        Self { islands, ..self }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    64
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    65
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    66
    pub fn add_fill_points(mut self, points: &[Point]) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    67
        self.fill_points.extend_from_slice(points);
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    68
        self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    69
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    70
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    71
    pub fn add_island(mut self, island: &[Rect]) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    72
        self.islands.push(island.into());
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    73
        self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    74
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    75
}