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