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