rust/lib-hedgewars-engine/src/render/atlas.rs
author alfadur
Mon, 25 Mar 2019 23:12:24 +0300
changeset 14720 b110cbe52e51
parent 14717 16024046d458
child 14722 c97faf0aef78
permissions -rw-r--r--
save more of the atlas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14717
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
     1
use integral_geometry::{Rect, Size};
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
     2
use std::cmp::{max, min, Ordering};
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
     3
14720
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
     4
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
14717
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
     5
struct Fit {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
     6
    short_size: u32,
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
     7
    long_size: u32,
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
     8
}
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
     9
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    10
impl Fit {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    11
    fn new() -> Self {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    12
        Self {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    13
            short_size: u32::max_value(),
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    14
            long_size: u32::max_value(),
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    15
        }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    16
    }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    17
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    18
    fn measure(container: Size, size: Size) -> Option<Self> {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    19
        if container.contains(size) {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    20
            let x_leftover = container.width - size.width;
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    21
            let y_leftover = container.height - size.height;
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    22
            Some(Self {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    23
                short_size: min(x_leftover, y_leftover) as u32,
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    24
                long_size: max(x_leftover, y_leftover) as u32,
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    25
            })
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    26
        } else {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    27
            None
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    28
        }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    29
    }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    30
}
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    31
14720
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    32
pub struct Atlas {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    33
    size: Size,
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    34
    free_rects: Vec<Rect>,
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    35
    used_rects: Vec<Rect>,
14717
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    36
}
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    37
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    38
impl Atlas {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    39
    pub fn new(size: Size) -> Self {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    40
        Self {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    41
            size,
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    42
            free_rects: vec![Rect::at_origin(size)],
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    43
            used_rects: vec![],
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    44
        }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    45
    }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    46
14720
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    47
    pub fn size(&self) -> Size {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    48
        self.size
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    49
    }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    50
14717
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    51
    fn find_position(&self, size: Size) -> Option<(Rect, Fit)> {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    52
        let mut best_rect = Rect::EMPTY;
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    53
        let mut best_fit = Fit::new();
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    54
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    55
        for rect in &self.free_rects {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    56
            if let Some(fit) = Fit::measure(rect.size(), size) {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    57
                if fit < best_fit {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    58
                    best_fit = fit;
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    59
                    best_rect = Rect::from_size(rect.top_left(), size);
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    60
                }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    61
            }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    62
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    63
            if let Some(fit) = Fit::measure(rect.size(), size.transpose()) {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    64
                if fit < best_fit {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    65
                    best_fit = fit;
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    66
                    best_rect = Rect::from_size(rect.top_left(), size.transpose());
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    67
                }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    68
            }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    69
        }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    70
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    71
        if best_rect == Rect::EMPTY {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    72
            None
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    73
        } else {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    74
            Some((best_rect, best_fit))
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    75
        }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    76
    }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    77
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    78
    fn prune(&mut self) {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    79
        self.free_rects = self
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    80
            .free_rects
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    81
            .iter()
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    82
            .filter(|inner| {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    83
                self.free_rects
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    84
                    .iter()
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    85
                    .all(|outer| outer == *inner || !outer.contains_rect(inner))
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    86
            })
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    87
            .cloned()
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    88
            .collect();
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    89
    }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    90
14720
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    91
    pub fn insert(&mut self, size: Size) -> Option<Rect> {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
    92
        let (rect, _) = self.find_position(size)?;
14717
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    93
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    94
        let mut rects_to_process = self.free_rects.len();
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    95
        let mut i = 0;
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    96
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    97
        while i < rects_to_process {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    98
            let rects = split_rect(self.free_rects[i], rect);
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
    99
            if !rects.is_empty() {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   100
                self.free_rects.remove(i);
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   101
                self.free_rects.extend(rects);
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   102
                rects_to_process -= 1
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   103
            } else {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   104
                i += 1;
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   105
            }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   106
        }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   107
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   108
        self.used_rects.push(rect);
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   109
        self.prune();
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   110
        Some(rect)
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   111
    }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   112
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   113
    pub fn insert_set<Iter>(&mut self, sizes: Iter) -> Vec<Rect>
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   114
    where
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   115
        Iter: Iterator<Item = Size>,
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   116
    {
14720
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   117
        let mut sizes: Vec<_> = sizes.collect();
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   118
        let mut result = vec![];
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   119
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   120
        while let Some((index, (rect, _))) = sizes
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   121
            .iter()
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   122
            .enumerate()
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   123
            .filter_map(|(i, s)| self.find_position(*s).map(|res| (i, res)))
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   124
            .min_by_key(|(_, (_, fit))| fit.clone())
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   125
        {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   126
            result.push(rect);
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   127
            sizes.swap_remove(index);
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   128
        }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   129
        if sizes.is_empty() {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   130
            self.used_rects.extend_from_slice(&result);
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   131
            result
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   132
        } else {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   133
            vec![]
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   134
        }
14717
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   135
    }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   136
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   137
    pub fn reset(&mut self) {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   138
        self.free_rects.clear();
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   139
        self.used_rects.clear();
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   140
        self.free_rects.push(Rect::at_origin(self.size));
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   141
    }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   142
}
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   143
14720
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   144
pub struct AtlasCollection {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   145
    texture_size: Size,
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   146
    atlases: Vec<Atlas>,
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   147
}
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   148
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   149
impl AtlasCollection {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   150
    pub fn new(texture_size: Size) -> Self {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   151
        Self {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   152
            texture_size,
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   153
            atlases: vec![],
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   154
        }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   155
    }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   156
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   157
    fn repack(&mut self, size: Size) -> bool {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   158
        for atlas in &mut self.atlases {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   159
            let mut temp_atlas = Atlas::new(atlas.size());
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   160
            let sizes = atlas
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   161
                .used_rects
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   162
                .iter()
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   163
                .map(|r| r.size())
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   164
                .chain(std::iter::once(size));
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   165
            if !temp_atlas.insert_set(sizes).is_empty() {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   166
                std::mem::swap(atlas, &mut temp_atlas);
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   167
                return true;
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   168
            }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   169
        }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   170
        false
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   171
    }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   172
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   173
    pub fn insert_sprite(&mut self, size: Size) -> bool {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   174
        if !self.texture_size.contains(size) {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   175
            false
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   176
        } else {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   177
            if let Some(rect) = self
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   178
                .atlases
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   179
                .iter_mut()
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   180
                .find_map(|a| a.insert(size))
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   181
            {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   182
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   183
            } else if !self.repack(size) {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   184
                let mut atlas = Atlas::new(self.texture_size);
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   185
                atlas.insert(size);
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   186
                self.atlases.push(atlas);
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   187
            }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   188
            true
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   189
        }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   190
    }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   191
}
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   192
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   193
fn split_rect(free_rect: Rect, rect: Rect) -> Vec<Rect> {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   194
    let mut result = vec![];
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   195
    if free_rect.intersects(&rect) {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   196
        if rect.left() > free_rect.left() {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   197
            let trim = free_rect.right() - rect.left() + 1;
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   198
            result.push(free_rect.with_margins(0, -trim, 0, 0))
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   199
        }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   200
        if rect.right() < free_rect.right() {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   201
            let trim = rect.right() - free_rect.left() + 1;
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   202
            result.push(free_rect.with_margins(-trim, 0, 0, 0))
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   203
        }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   204
        if rect.top() > free_rect.top() {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   205
            let trim = free_rect.bottom() - rect.top() + 1;
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   206
            result.push(free_rect.with_margins(0, 0, 0, -trim));
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   207
        }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   208
        if rect.bottom() < free_rect.bottom() {
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   209
            let trim = rect.bottom() - free_rect.top() + 1;
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   210
            result.push(free_rect.with_margins(0, 0, -trim, 0));
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   211
        }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   212
    }
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   213
    result
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   214
}
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   215
14717
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   216
#[cfg(test)]
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   217
mod tests {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   218
    use super::Atlas;
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   219
    use integral_geometry::{Rect, Size};
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   220
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   221
    #[test]
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   222
    fn insert() {
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   223
        let atlas_size = Size::square(16);
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   224
        let mut atlas = Atlas::new(atlas_size);
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   225
14720
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   226
        assert_eq!(None, atlas.insert(Size::square(20)));
14717
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   227
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   228
        let rect_size = Size::new(11, 3);
14720
b110cbe52e51 save more of the atlas
alfadur
parents: 14717
diff changeset
   229
        let rect = atlas.insert(rect_size).unwrap();
14717
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   230
        assert_eq!(rect, Rect::at_origin(rect_size));
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   231
        assert_eq!(2, atlas.free_rects.len());
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   232
    }
16024046d458 rescue the atlas
alfadur
parents:
diff changeset
   233
}