author | nemo |
Thu, 15 Nov 2018 15:39:59 -0500 | |
changeset 14213 | 09dacb61d526 |
parent 14207 | bb2f301d4fe0 |
child 14702 | 29dbe9ce8b7d |
permissions | -rw-r--r-- |
14144 | 1 |
use std::{ |
2 |
cmp, |
|
3 |
ops::Index |
|
4 |
}; |
|
13917 | 5 |
|
14137
3119d665d3c6
collapse rectangle types back together with consistent usage of size
alfadur
parents:
14135
diff
changeset
|
6 |
use integral_geometry::{ArcPoints, EquidistantPoints, Line, Point, Rect, Size, SizeMask}; |
13938
1fa905aa4cdb
move point struct into integral-geometry and use it to refactor a bit
alfadur
parents:
13936
diff
changeset
|
7 |
|
13917 | 8 |
pub struct Land2D<T> { |
9 |
pixels: vec2d::Vec2D<T>, |
|
14137
3119d665d3c6
collapse rectangle types back together with consistent usage of size
alfadur
parents:
14135
diff
changeset
|
10 |
play_box: Rect, |
14078 | 11 |
mask: SizeMask, |
13917 | 12 |
} |
13 |
||
13931 | 14 |
impl<T: Copy + PartialEq> Land2D<T> { |
14052 | 15 |
pub fn new(play_size: Size, fill_value: T) -> Self { |
16 |
let real_size = play_size.next_power_of_two(); |
|
14078 | 17 |
let top_left = Point::new( |
14101 | 18 |
((real_size.width - play_size.width) / 2) as i32, |
14078 | 19 |
(real_size.height - play_size.height) as i32, |
20 |
); |
|
14137
3119d665d3c6
collapse rectangle types back together with consistent usage of size
alfadur
parents:
14135
diff
changeset
|
21 |
let play_box = Rect::from_size(top_left, play_size); |
13917 | 22 |
Self { |
14078 | 23 |
play_box, |
14052 | 24 |
pixels: vec2d::Vec2D::new(real_size, fill_value), |
14078 | 25 |
mask: real_size.to_mask(), |
13917 | 26 |
} |
27 |
} |
|
28 |
||
14121 | 29 |
pub fn raw_pixels(&self) -> &[T] { |
14160 | 30 |
&self.pixels.as_slice() |
14121 | 31 |
} |
32 |
||
13917 | 33 |
#[inline] |
13924 | 34 |
pub fn width(&self) -> usize { |
35 |
self.pixels.width() |
|
36 |
} |
|
37 |
||
38 |
#[inline] |
|
39 |
pub fn height(&self) -> usize { |
|
40 |
self.pixels.height() |
|
41 |
} |
|
42 |
||
43 |
#[inline] |
|
14052 | 44 |
pub fn size(&self) -> Size { |
45 |
self.pixels.size() |
|
46 |
} |
|
47 |
||
48 |
#[inline] |
|
14050
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
49 |
pub fn play_width(&self) -> usize { |
14135
7f5a591e1c43
separate rectangle types based on right/bottom edge inclusivity
alfadur
parents:
14121
diff
changeset
|
50 |
self.play_box.width() |
14050
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
51 |
} |
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
52 |
|
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
53 |
#[inline] |
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
54 |
pub fn play_height(&self) -> usize { |
14135
7f5a591e1c43
separate rectangle types based on right/bottom edge inclusivity
alfadur
parents:
14121
diff
changeset
|
55 |
self.play_box.height() |
14052 | 56 |
} |
57 |
||
58 |
#[inline] |
|
59 |
pub fn play_size(&self) -> Size { |
|
14135
7f5a591e1c43
separate rectangle types based on right/bottom edge inclusivity
alfadur
parents:
14121
diff
changeset
|
60 |
self.play_box.size() |
14050
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
61 |
} |
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
62 |
|
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
63 |
#[inline] |
14137
3119d665d3c6
collapse rectangle types back together with consistent usage of size
alfadur
parents:
14135
diff
changeset
|
64 |
pub fn play_box(&self) -> Rect { |
14078 | 65 |
self.play_box |
66 |
} |
|
67 |
||
68 |
#[inline] |
|
13931 | 69 |
pub fn is_valid_x(&self, x: i32) -> bool { |
14032 | 70 |
self.mask.contains_x(x as usize) |
13931 | 71 |
} |
72 |
||
73 |
#[inline] |
|
74 |
pub fn is_valid_y(&self, y: i32) -> bool { |
|
14032 | 75 |
self.mask.contains_y(y as usize) |
13931 | 76 |
} |
77 |
||
78 |
#[inline] |
|
13924 | 79 |
pub fn is_valid_coordinate(&self, x: i32, y: i32) -> bool { |
13931 | 80 |
self.is_valid_x(x) && self.is_valid_y(y) |
13917 | 81 |
} |
82 |
||
83 |
#[inline] |
|
14170 | 84 |
pub fn rows(&self) -> impl DoubleEndedIterator<Item = &[T]> { |
14030 | 85 |
self.pixels.rows() |
86 |
} |
|
87 |
||
88 |
#[inline] |
|
13940
1c30793b1cea
put back land2d.map accidentally replaced by testing code
alfadur
parents:
13938
diff
changeset
|
89 |
pub fn map<U: Default, F: FnOnce(&mut T) -> U>(&mut self, y: i32, x: i32, f: F) -> U { |
13917 | 90 |
if self.is_valid_coordinate(x, y) { |
13934
9c112f2ae02d
Raise levels of abstraction to implement draw_thick_line() avoiding code duplication
unc0rr
parents:
13931
diff
changeset
|
91 |
unsafe { |
9c112f2ae02d
Raise levels of abstraction to implement draw_thick_line() avoiding code duplication
unc0rr
parents:
13931
diff
changeset
|
92 |
// hey, I just checked that coordinates are valid! |
13940
1c30793b1cea
put back land2d.map accidentally replaced by testing code
alfadur
parents:
13938
diff
changeset
|
93 |
f(self.pixels.get_unchecked_mut(y as usize, x as usize)) |
13931 | 94 |
} |
13934
9c112f2ae02d
Raise levels of abstraction to implement draw_thick_line() avoiding code duplication
unc0rr
parents:
13931
diff
changeset
|
95 |
} else { |
13940
1c30793b1cea
put back land2d.map accidentally replaced by testing code
alfadur
parents:
13938
diff
changeset
|
96 |
U::default() |
13917 | 97 |
} |
98 |
} |
|
99 |
||
13944
4162ea9ae333
Use integral-geometry iterators to implement Land2D::draw_thick_line, remove no longer unused functions from Land2D
unc0rr
parents:
13943
diff
changeset
|
100 |
#[inline] |
4162ea9ae333
Use integral-geometry iterators to implement Land2D::draw_thick_line, remove no longer unused functions from Land2D
unc0rr
parents:
13943
diff
changeset
|
101 |
pub fn map_point<U: Default, F: FnOnce(&mut T) -> U>(&mut self, point: Point, f: F) -> U { |
4162ea9ae333
Use integral-geometry iterators to implement Land2D::draw_thick_line, remove no longer unused functions from Land2D
unc0rr
parents:
13943
diff
changeset
|
102 |
self.map(point.y, point.x, f) |
13934
9c112f2ae02d
Raise levels of abstraction to implement draw_thick_line() avoiding code duplication
unc0rr
parents:
13931
diff
changeset
|
103 |
} |
9c112f2ae02d
Raise levels of abstraction to implement draw_thick_line() avoiding code duplication
unc0rr
parents:
13931
diff
changeset
|
104 |
|
13938
1fa905aa4cdb
move point struct into integral-geometry and use it to refactor a bit
alfadur
parents:
13936
diff
changeset
|
105 |
pub fn fill_from_iter<I>(&mut self, i: I, value: T) -> usize |
13943
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
106 |
where |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
107 |
I: std::iter::Iterator<Item = Point>, |
13938
1fa905aa4cdb
move point struct into integral-geometry and use it to refactor a bit
alfadur
parents:
13936
diff
changeset
|
108 |
{ |
13943
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
109 |
i.map(|p| { |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
110 |
self.map(p.y, p.x, |v| { |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
111 |
*v = value; |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
112 |
1 |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
113 |
}) |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
114 |
}).count() |
13938
1fa905aa4cdb
move point struct into integral-geometry and use it to refactor a bit
alfadur
parents:
13936
diff
changeset
|
115 |
} |
1fa905aa4cdb
move point struct into integral-geometry and use it to refactor a bit
alfadur
parents:
13936
diff
changeset
|
116 |
|
14076
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
117 |
pub fn draw_line(&mut self, line: Line, value: T) -> usize { |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
118 |
self.fill_from_iter(line.into_iter(), value) |
13917 | 119 |
} |
13924 | 120 |
|
13948 | 121 |
pub fn fill(&mut self, start_point: Point, border_value: T, fill_value: T) { |
14150 | 122 |
assert!(self.is_valid_coordinate(start_point.x - 1, start_point.y)); |
123 |
assert!(self.is_valid_coordinate(start_point.x, start_point.y)); |
|
13924 | 124 |
|
14148 | 125 |
let mask = self.mask; |
126 |
let width = self.width(); |
|
127 |
||
13924 | 128 |
let mut stack: Vec<(usize, usize, usize, isize)> = Vec::new(); |
14148 | 129 |
fn push( |
130 |
mask: SizeMask, |
|
13924 | 131 |
stack: &mut Vec<(usize, usize, usize, isize)>, |
132 |
xl: usize, |
|
133 |
xr: usize, |
|
134 |
y: usize, |
|
135 |
dir: isize, |
|
136 |
) { |
|
137 |
let yd = y as isize + dir; |
|
14148 | 138 |
if mask.contains_y(yd as usize) { |
13924 | 139 |
stack.push((xl, xr, yd as usize, dir)); |
140 |
} |
|
141 |
}; |
|
142 |
||
13948 | 143 |
let start_x_l = (start_point.x - 1) as usize; |
144 |
let start_x_r = start_point.x as usize; |
|
14148 | 145 |
for dir in [-1, 1].iter().cloned() { |
146 |
push(mask, &mut stack, start_x_l, start_x_r, start_point.y as usize, dir); |
|
147 |
} |
|
13924 | 148 |
|
14148 | 149 |
while let Some((mut xl, mut xr, y, dir)) = stack.pop() { |
150 |
let row = &mut self.pixels[y][..]; |
|
14149
8e2e98760003
a bit more simplification without an apparent performance gain
alfadur
parents:
14148
diff
changeset
|
151 |
while xl > 0 && row[xl] != border_value && row[xl] != fill_value |
13951 | 152 |
{ |
153 |
xl -= 1; |
|
154 |
} |
|
13924 | 155 |
|
14149
8e2e98760003
a bit more simplification without an apparent performance gain
alfadur
parents:
14148
diff
changeset
|
156 |
while xr < width - 1 && row[xr] != border_value && row[xr] != fill_value |
13951 | 157 |
{ |
158 |
xr += 1; |
|
159 |
} |
|
13924 | 160 |
|
13951 | 161 |
while xl < xr { |
14148 | 162 |
while xl <= xr && (row[xl] == border_value || row[xl] == fill_value) |
13951 | 163 |
{ |
164 |
xl += 1; |
|
165 |
} |
|
13924 | 166 |
|
14148 | 167 |
let x = xl; |
13924 | 168 |
|
14149
8e2e98760003
a bit more simplification without an apparent performance gain
alfadur
parents:
14148
diff
changeset
|
169 |
while xl <= xr && row[xl] != border_value && row[xl] != fill_value |
13951 | 170 |
{ |
14148 | 171 |
row[xl] = fill_value; |
13951 | 172 |
xl += 1; |
173 |
} |
|
13924 | 174 |
|
13951 | 175 |
if x < xl { |
14148 | 176 |
push(mask, &mut stack, x, xl - 1, y, dir); |
177 |
push(mask, &mut stack, x, xl - 1, y, -dir); |
|
13924 | 178 |
} |
179 |
} |
|
180 |
} |
|
181 |
} |
|
13931 | 182 |
|
183 |
#[inline] |
|
184 |
fn fill_circle_line<F: Fn(&mut T) -> usize>( |
|
185 |
&mut self, |
|
186 |
y: i32, |
|
187 |
x_from: i32, |
|
188 |
x_to: i32, |
|
189 |
f: &F, |
|
190 |
) -> usize { |
|
191 |
let mut result = 0; |
|
192 |
||
193 |
if self.is_valid_y(y) { |
|
194 |
for i in cmp::min(x_from, 0) as usize..cmp::max(x_to as usize, self.width() - 1) { |
|
13934
9c112f2ae02d
Raise levels of abstraction to implement draw_thick_line() avoiding code duplication
unc0rr
parents:
13931
diff
changeset
|
195 |
unsafe { |
9c112f2ae02d
Raise levels of abstraction to implement draw_thick_line() avoiding code duplication
unc0rr
parents:
13931
diff
changeset
|
196 |
// coordinates are valid at this point |
13931 | 197 |
result += f(self.pixels.get_unchecked_mut(y as usize, i)); |
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
result |
|
203 |
} |
|
204 |
||
205 |
#[inline] |
|
206 |
fn fill_circle_lines<F: Fn(&mut T) -> usize>( |
|
207 |
&mut self, |
|
208 |
x: i32, |
|
209 |
y: i32, |
|
210 |
dx: i32, |
|
211 |
dy: i32, |
|
212 |
f: &F, |
|
213 |
) -> usize { |
|
214 |
self.fill_circle_line(y + dy, x - dx, x + dx, f) |
|
215 |
+ self.fill_circle_line(y - dy, x - dx, x + dx, f) |
|
216 |
+ self.fill_circle_line(y + dx, x - dy, x + dy, f) |
|
217 |
+ self.fill_circle_line(y - dx, x - dy, x + dy, f) |
|
218 |
} |
|
219 |
||
220 |
pub fn change_round<F: Fn(&mut T) -> usize>( |
|
221 |
&mut self, |
|
222 |
x: i32, |
|
223 |
y: i32, |
|
224 |
radius: i32, |
|
225 |
f: F, |
|
226 |
) -> usize { |
|
13943
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
227 |
ArcPoints::new(radius) |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
228 |
.map(&mut |p: Point| self.fill_circle_lines(x, y, p.x, p.y, &f)) |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
229 |
.sum() |
13934
9c112f2ae02d
Raise levels of abstraction to implement draw_thick_line() avoiding code duplication
unc0rr
parents:
13931
diff
changeset
|
230 |
} |
13931 | 231 |
|
14031 | 232 |
fn fill_row(&mut self, center: Point, offset: Point, value: T) -> usize { |
233 |
let row_index = center.y + offset.y; |
|
234 |
if self.is_valid_y(row_index) { |
|
235 |
let from_x = cmp::max(0, center.x - offset.x) as usize; |
|
236 |
let to_x = cmp::min(self.width() - 1, (center.x + offset.x) as usize); |
|
237 |
self.pixels[row_index as usize][from_x..=to_x] |
|
14078 | 238 |
.iter_mut() |
239 |
.for_each(|v| *v = value); |
|
14031 | 240 |
to_x - from_x + 1 |
241 |
} else { |
|
242 |
0 |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
pub fn fill_circle(&mut self, center: Point, radius: i32, value: T) -> usize { |
|
14078 | 247 |
let transforms = [[0, 1, 1, 0], [0, 1, -1, 0], [1, 0, 0, 1], [1, 0, 0, -1]]; |
248 |
ArcPoints::new(radius) |
|
249 |
.map(|vector| { |
|
250 |
transforms |
|
251 |
.iter() |
|
252 |
.map(|m| self.fill_row(center, vector.transform(m), value)) |
|
253 |
.sum::<usize>() |
|
254 |
}).sum() |
|
14031 | 255 |
} |
256 |
||
14076
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
257 |
pub fn draw_thick_line(&mut self, line: Line, radius: i32, value: T) -> usize { |
13944
4162ea9ae333
Use integral-geometry iterators to implement Land2D::draw_thick_line, remove no longer unused functions from Land2D
unc0rr
parents:
13943
diff
changeset
|
258 |
let mut result = 0; |
13931 | 259 |
|
13949
a1895019bb94
change draw_thick_line iteration order to benchmark winner
alfadur
parents:
13948
diff
changeset
|
260 |
for vector in ArcPoints::new(radius) { |
a1895019bb94
change draw_thick_line iteration order to benchmark winner
alfadur
parents:
13948
diff
changeset
|
261 |
for delta in EquidistantPoints::new(vector) { |
14076
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
262 |
for point in line.into_iter() { |
13946 | 263 |
self.map_point(point + delta, |p| { |
264 |
if *p != value { |
|
265 |
*p = value; |
|
266 |
result += 1; |
|
267 |
} |
|
268 |
}) |
|
13944
4162ea9ae333
Use integral-geometry iterators to implement Land2D::draw_thick_line, remove no longer unused functions from Land2D
unc0rr
parents:
13943
diff
changeset
|
269 |
} |
13943
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
270 |
} |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
271 |
} |
a325ed57ebfe
Don't generate unnecessary duplication in case of equal coordinates
unc0rr
parents:
13940
diff
changeset
|
272 |
|
13944
4162ea9ae333
Use integral-geometry iterators to implement Land2D::draw_thick_line, remove no longer unused functions from Land2D
unc0rr
parents:
13943
diff
changeset
|
273 |
result |
13934
9c112f2ae02d
Raise levels of abstraction to implement draw_thick_line() avoiding code duplication
unc0rr
parents:
13931
diff
changeset
|
274 |
} |
13917 | 275 |
} |
276 |
||
14144 | 277 |
impl<T> Index<usize> for Land2D<T> { |
278 |
type Output = [T]; |
|
279 |
#[inline] |
|
280 |
fn index(&self, row: usize) -> &[T] { |
|
281 |
&self.pixels[row] |
|
282 |
} |
|
283 |
} |
|
284 |
||
13917 | 285 |
#[cfg(test)] |
286 |
mod tests { |
|
287 |
use super::*; |
|
288 |
||
289 |
#[test] |
|
290 |
fn basics() { |
|
14052 | 291 |
let l: Land2D<u8> = Land2D::new(Size::new(30, 50), 0); |
14050
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
292 |
|
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
293 |
assert_eq!(l.play_width(), 30); |
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
294 |
assert_eq!(l.play_height(), 50); |
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
295 |
assert_eq!(l.width(), 32); |
4b40bdd214df
Use next_power_of_two() just like hedgewars engine does, expose original and real dimensions
unc0rr
parents:
13951
diff
changeset
|
296 |
assert_eq!(l.height(), 64); |
13917 | 297 |
|
298 |
assert!(l.is_valid_coordinate(0, 0)); |
|
299 |
assert!(!l.is_valid_coordinate(-1, -1)); |
|
300 |
||
301 |
assert!(l.is_valid_coordinate(31, 63)); |
|
302 |
assert!(!l.is_valid_coordinate(32, 63)); |
|
303 |
assert!(!l.is_valid_coordinate(31, 64)); |
|
304 |
} |
|
305 |
||
13924 | 306 |
#[test] |
307 |
fn fill() { |
|
14032 | 308 |
let mut l: Land2D<u8> = Land2D::new(Size::square(128), 0); |
13924 | 309 |
|
14076
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
310 |
l.draw_line(Line::new(Point::new(0, 0), Point::new(32, 96)), 1); |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
311 |
l.draw_line(Line::new(Point::new(32, 96), Point::new(64, 32)), 1); |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
312 |
l.draw_line(Line::new(Point::new(64, 32), Point::new(96, 80)), 1); |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
313 |
l.draw_line(Line::new(Point::new(96, 80), Point::new(128, 0)), 1); |
13924 | 314 |
|
14076
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
315 |
l.draw_line(Line::new(Point::new(0, 128), Point::new(64, 96)), 1); |
e5904ead4864
Introduce OutlineSegmentsIterator, some refactoring
unC0Rr
parents:
14052
diff
changeset
|
316 |
l.draw_line(Line::new(Point::new(128, 128), Point::new(64, 96)), 1); |
13924 | 317 |
|
13948 | 318 |
l.fill(Point::new(32, 32), 1, 2); |
319 |
l.fill(Point::new(16, 96), 1, 3); |
|
320 |
l.fill(Point::new(60, 100), 1, 4); |
|
13924 | 321 |
|
322 |
assert_eq!(l.pixels[0][0], 1); |
|
323 |
assert_eq!(l.pixels[96][64], 1); |
|
324 |
||
325 |
assert_eq!(l.pixels[40][32], 2); |
|
326 |
assert_eq!(l.pixels[40][96], 2); |
|
327 |
assert_eq!(l.pixels[5][0], 3); |
|
328 |
assert_eq!(l.pixels[120][0], 3); |
|
329 |
assert_eq!(l.pixels[5][127], 3); |
|
330 |
assert_eq!(l.pixels[120][127], 3); |
|
331 |
assert_eq!(l.pixels[35][64], 3); |
|
332 |
assert_eq!(l.pixels[120][20], 4); |
|
333 |
assert_eq!(l.pixels[120][100], 4); |
|
334 |
assert_eq!(l.pixels[100][64], 4); |
|
335 |
} |
|
13917 | 336 |
} |