rust/landgen/src/outline.rs
author unC0Rr
Fri, 02 Nov 2018 14:29:24 +0100
changeset 14078 bf40b5f938b0
parent 14077 5ade484f3351
child 14081 5d42204ac35e
permissions -rw-r--r--
- Add methods to work with Rect as box - Refactor, tests, fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     1
use itertools::Itertools;
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     2
14078
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
     3
use integral_geometry::{Line, Point, Rect, Size};
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     4
use land2d::Land2D;
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     5
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     6
use outline_template::OutlineTemplate;
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     7
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     8
pub struct OutlinePoints {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     9
    pub islands: Vec<Vec<Point>>,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    10
    pub fill_points: Vec<Point>,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    11
    pub size: Size,
14078
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    12
    pub play_box: Rect,
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    13
}
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    14
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    15
impl OutlinePoints {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    16
    pub fn from_outline_template<I: Iterator<Item = u32>>(
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    17
        outline_template: &OutlineTemplate,
14078
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    18
        play_box: Rect,
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    19
        size: Size,
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    20
        random_numbers: &mut I,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    21
    ) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    22
        Self {
14078
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    23
            play_box,
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    24
            size,
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    25
            islands: outline_template
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    26
                .islands
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    27
                .iter()
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    28
                .map(|i| {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    29
                    i.iter()
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    30
                        .zip(random_numbers.tuples())
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    31
                        .map(|(rect, (rnd_a, rnd_b))| {
14078
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    32
                            rect.top_left()
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    33
                                + Point::new(
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    34
                                    (rnd_a % rect.width) as i32,
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    35
                                    (rnd_b % rect.height) as i32,
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    36
                                )
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
    37
                                + play_box.top_left()
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    38
                        }).collect()
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    39
                }).collect(),
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    40
            fill_points: outline_template.fill_points.clone(),
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    41
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    42
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    43
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    44
    pub fn total_len(&self) -> usize {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    45
        self.islands.iter().map(|i| i.len()).sum::<usize>() + self.fill_points.len()
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 iter_mut(&mut self) -> impl Iterator<Item = &mut Point> {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    49
        self.islands
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    50
            .iter_mut()
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    51
            .flat_map(|i| i.iter_mut())
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    52
            .chain(self.fill_points.iter_mut())
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
    fn divide_edge<I: Iterator<Item = u32>>(
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    56
        &self,
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
    57
        segment: Line,
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    58
        random_numbers: &mut I,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    59
    ) -> Option<Point> {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    60
        None
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    61
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    62
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    63
    fn divide_edges<I: Iterator<Item = u32>>(&mut self, random_numbers: &mut I) {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    64
        for is in 0..self.islands.len() {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    65
            let mut i = 0;
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
    66
            let mut segment;
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    67
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    68
            loop {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    69
                {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    70
                    let island = &self.islands[is];
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
    71
                    let mut end_point;
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    72
                    if i < island.len() {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    73
                        end_point = if i + 1 < island.len() {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    74
                            island[i + 1]
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    75
                        } else {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    76
                            island[0]
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    77
                        };
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    78
                    } else {
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
    79
                        break;
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    80
                    }
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
    81
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
    82
                    segment = Line::new(island[i], end_point);
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    83
                }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    84
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
    85
                if let Some(new_point) = self.divide_edge(segment, random_numbers) {
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    86
                    self.islands[is].insert(i + 1, new_point);
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    87
                    i += 2;
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    88
                } else {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    89
                    i += 1;
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    90
                }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    91
            }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    92
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    93
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    94
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    95
    pub fn bezierize(&mut self) {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    96
        unimplemented!()
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    97
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    98
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    99
    pub fn distort<I: Iterator<Item = u32>>(&mut self, random_numbers: &mut I) {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   100
        loop {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   101
            let old_len = self.total_len();
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   102
            self.divide_edges(random_numbers);
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   103
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   104
            if self.total_len() != old_len {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   105
                break;
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   106
            }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   107
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   108
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   109
        self.bezierize();
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   110
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   111
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   112
    pub fn draw<T: Copy + PartialEq>(&self, land: &mut Land2D<T>, value: T) {
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   113
        for segment in self.segments_iter() {
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   114
            land.draw_line(segment, value);
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   115
        }
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   116
    }
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   117
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   118
    fn segments_iter(&self) -> OutlineSegmentsIterator {
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   119
        OutlineSegmentsIterator {
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   120
            outline: self,
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   121
            island: 0,
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   122
            index: 0,
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   123
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   124
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
   125
}
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   126
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   127
struct OutlineSegmentsIterator<'a> {
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   128
    outline: &'a OutlinePoints,
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   129
    island: usize,
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   130
    index: usize,
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   131
}
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   132
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   133
impl<'a> Iterator for OutlineSegmentsIterator<'a> {
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   134
    type Item = Line;
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   135
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   136
    fn next(&mut self) -> Option<Self::Item> {
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   137
        if self.island < self.outline.islands.len() {
14078
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   138
            if self.index + 1 < self.outline.islands[self.island].len() {
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   139
                let result = Some(Line::new(
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   140
                    self.outline.islands[self.island][self.index],
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   141
                    self.outline.islands[self.island][self.index + 1],
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   142
                ));
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   143
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   144
                self.index += 1;
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   145
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   146
                result
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   147
            } else if self.index + 1 == self.outline.islands[self.island].len() {
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   148
                let result = Some(Line::new(
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   149
                    self.outline.islands[self.island][self.index],
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   150
                    self.outline.islands[self.island][0],
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   151
                ));
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   152
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   153
                self.island += 1;
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   154
                self.index = 0;
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   155
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   156
                result
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   157
            } else {
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   158
                self.island += 1;
14078
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   159
                self.index = 0;
14076
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   160
                self.next()
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   161
            }
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   162
        } else {
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   163
            None
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   164
        }
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   165
    }
e5904ead4864 Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents: 14069
diff changeset
   166
}
14078
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   167
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   168
#[test()]
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   169
fn points_test() {
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   170
    let mut points = OutlinePoints {
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   171
        islands: vec![
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   172
            vec![Point::new(0, 0), Point::new(20, 0), Point::new(30, 30)],
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   173
            vec![Point::new(10, 15), Point::new(15, 20), Point::new(20, 15)],
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   174
        ],
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   175
        fill_points: vec![Point::new(1, 1)],
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   176
        play_box: Rect::from_box(0, 100, 0, 100).with_margin(10),
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   177
        size: Size::square(100),
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   178
    };
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   179
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   180
    let segments: Vec<Line> = points.segments_iter().collect();
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   181
    assert_eq!(
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   182
        segments.first(),
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   183
        Some(&Line::new(Point::new(0, 0), Point::new(20, 0)))
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   184
    );
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   185
    assert_eq!(
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   186
        segments.last(),
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   187
        Some(&Line::new(Point::new(20, 15), Point::new(10, 15)))
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   188
    );
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   189
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   190
    points.iter_mut().for_each(|p| p.x = 2);
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   191
    assert_eq!(points.fill_points[0].x, 2);
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   192
    assert_eq!(points.islands[0][0].x, 2);
bf40b5f938b0 - Add methods to work with Rect as box
unC0Rr
parents: 14077
diff changeset
   193
}