Showing
2 changed files
with
46 additions
and
6 deletions
... | ... | @@ -50,8 +50,7 @@ impl Coordinate { |
50 | 50 | let Coordinate(x, y) = v[0]; |
51 | 51 | |
52 | 52 | if x != bx || y != by { |
53 | - let doinc = (2*err >= dy, 2*err <= dx); | |
54 | - let (x, y, err) = match doinc { | |
53 | + let (x, y, err) = match (2*err >= dy, 2*err <= dx) { | |
55 | 54 | (true, false) => (x + sx, y, err + dy), |
56 | 55 | (false, true) => ( x, y + sy, err + dx), |
57 | 56 | _ => (x + sx, y + sy, err + dx + dy ), |
... | ... | @@ -218,7 +217,7 @@ impl Drawable for Polygon { |
218 | 217 | r.append(&mut i.line(j)[1..].to_vec()); |
219 | 218 | i = *j; |
220 | 219 | } |
221 | - let mut j = i.line(&a); | |
220 | + let mut j = a.line(&i); | |
222 | 221 | let l = j.len(); |
223 | 222 | r.append(&mut j[1..l-1].to_vec()); |
224 | 223 | Coordinates(r) | ... | ... |
... | ... | @@ -254,9 +254,50 @@ fn _line() { |
254 | 254 | |
255 | 255 | println!(); |
256 | 256 | let pg = Polygon( |
257 | - Coordinates(vec!( Coordinate( 0, -20) | |
258 | - , Coordinate( 20, 20) | |
259 | - , Coordinate(-20, 20) ))); | |
257 | + Coordinates(vec!( Coordinate( 0, -10) | |
258 | + , Coordinate( 10, 10) | |
259 | + , Coordinate(-10, 10) ))); | |
260 | + println!("{:>14} : {}", pg, pg.plot()); | |
261 | + | |
262 | + let i = Vector(Fractional( 0,1), Fractional(-30,1), Fractional(0,1)); | |
263 | + let j = Vector(Fractional( 30,1), Fractional( 30,1), Fractional(0,1)); | |
264 | + let k = Vector(Fractional(-30,1), Fractional( 30,1), Fractional(0,1)); | |
265 | + | |
266 | + let rot :TMatrix<Fractional> = rotate_z(20); | |
267 | + let Vector(ix, iy, _) = rot.apply(&i); | |
268 | + let Vector(jx, jy, _) = rot.apply(&j); | |
269 | + let Vector(kx, ky, _) = rot.apply(&k); | |
270 | + | |
271 | + fn to_i32(x :Fractional) -> i32 { | |
272 | + let Fractional(n, d) = x; | |
273 | + (n / d + if (n % d).abs() < (n / 2).abs() { 0 } else { 1 }) as i32 | |
274 | + } | |
275 | + | |
276 | + println!(); | |
277 | + let pg = Polygon( | |
278 | + Coordinates(vec!( Coordinate(to_i32(ix) + 100, to_i32(iy) + 100) | |
279 | + , Coordinate(to_i32(jx) + 100, to_i32(jy) + 100) | |
280 | + , Coordinate(to_i32(kx) + 100, to_i32(ky) + 100) ))); | |
281 | + println!("{:>14} : {}", pg, pg.plot()); | |
282 | + | |
283 | + let i = Vector( 0.0, -30.0, 0.0); | |
284 | + let j = Vector( 30.0, 30.0, 0.0); | |
285 | + let k = Vector(-30.0, 30.0, 0.0); | |
286 | + | |
287 | + let rot :TMatrix<f64> = rotate_z(20); | |
288 | + let Vector(ix, iy, _) = rot.apply(&i); | |
289 | + let Vector(jx, jy, _) = rot.apply(&j); | |
290 | + let Vector(kx, ky, _) = rot.apply(&k); | |
291 | + | |
292 | + fn to_i32_2(x :f64) -> i32 { | |
293 | + x.round() as i32 | |
294 | + } | |
295 | + | |
296 | + println!(); | |
297 | + let pg = Polygon( | |
298 | + Coordinates(vec!( Coordinate(to_i32_2(ix) + 100, to_i32_2(iy) + 100) | |
299 | + , Coordinate(to_i32_2(jx) + 100, to_i32_2(jy) + 100) | |
300 | + , Coordinate(to_i32_2(kx) + 100, to_i32_2(ky) + 100) ))); | |
260 | 301 | println!("{:>14} : {}", pg, pg.plot()); |
261 | 302 | } |
262 | 303 | ... | ... |
Please
register
or
login
to post a comment