1use image::RgbImage;
2
3use crate::{
4 line_sorter::{sort_column, sort_row},
5 Options,
6};
7
8pub fn sort(buf: &mut RgbImage) {
10 sort_with_options(buf, &Options::default());
11}
12
13pub fn sort_with_options(buf: &mut RgbImage, options: &Options) {
15 if options.direction.has_column() {
16 for col in 0..buf.width() {
17 sort_column(buf, col, options);
18 }
19 }
20
21 if options.direction.has_row() {
22 for row in 0..buf.height() {
23 sort_row(buf, row, options);
24 }
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31 use crate::{Direction, Mode};
32 use helper::*;
33
34 #[test]
35 fn test_sort() {
36 assert_sort!("p1", "brightness_default");
37 }
38
39 #[test]
40 fn test_sort_with_options_black() {
41 let options = Options {
42 mode: Mode::black(),
43 ..Default::default()
44 };
45
46 assert_sort_with_options!("p1", "black_default", &options);
47 }
48
49 #[test]
50 fn test_sort_with_options_white() {
51 let options = Options {
52 mode: Mode::white(),
53 ..Default::default()
54 };
55
56 assert_sort_with_options!("p1", "white_default", &options);
57 }
58
59 #[test]
60 fn test_sort_with_options_column() {
61 let options = Options {
62 direction: Direction::Column,
63 ..Default::default()
64 };
65
66 assert_sort_with_options!("p1", "column", &options);
67 }
68
69 #[test]
70 fn test_sort_with_options_row() {
71 let options = Options {
72 direction: Direction::Row,
73 ..Default::default()
74 };
75
76 assert_sort_with_options!("p1", "row", &options);
77 }
78}