Browse Source

Add first transformed Polygon

master
Georg Hopp 6 years ago
parent
commit
45d1af9c59
Signed by: ghopp GPG Key ID: 4C5D226768784538
  1. 5
      fractional/src/easel.rs
  2. 47
      fractional/src/main.rs

5
fractional/src/easel.rs

@ -50,8 +50,7 @@ impl Coordinate {
let Coordinate(x, y) = v[0];
if x != bx || y != by {
let doinc = (2*err >= dy, 2*err <= dx);
let (x, y, err) = match doinc {
let (x, y, err) = match (2*err >= dy, 2*err <= dx) {
(true, false) => (x + sx, y, err + dy),
(false, true) => ( x, y + sy, err + dx),
_ => (x + sx, y + sy, err + dx + dy ),
@ -218,7 +217,7 @@ impl Drawable for Polygon {
r.append(&mut i.line(j)[1..].to_vec());
i = *j;
}
let mut j = i.line(&a);
let mut j = a.line(&i);
let l = j.len();
r.append(&mut j[1..l-1].to_vec());
Coordinates(r)

47
fractional/src/main.rs

@ -254,9 +254,50 @@ fn _line() {
println!();
let pg = Polygon(
Coordinates(vec!( Coordinate( 0, -20)
, Coordinate( 20, 20)
, Coordinate(-20, 20) )));
Coordinates(vec!( Coordinate( 0, -10)
, Coordinate( 10, 10)
, Coordinate(-10, 10) )));
println!("{:>14} : {}", pg, pg.plot());
let i = Vector(Fractional( 0,1), Fractional(-30,1), Fractional(0,1));
let j = Vector(Fractional( 30,1), Fractional( 30,1), Fractional(0,1));
let k = Vector(Fractional(-30,1), Fractional( 30,1), Fractional(0,1));
let rot :TMatrix<Fractional> = rotate_z(20);
let Vector(ix, iy, _) = rot.apply(&i);
let Vector(jx, jy, _) = rot.apply(&j);
let Vector(kx, ky, _) = rot.apply(&k);
fn to_i32(x :Fractional) -> i32 {
let Fractional(n, d) = x;
(n / d + if (n % d).abs() < (n / 2).abs() { 0 } else { 1 }) as i32
}
println!();
let pg = Polygon(
Coordinates(vec!( Coordinate(to_i32(ix) + 100, to_i32(iy) + 100)
, Coordinate(to_i32(jx) + 100, to_i32(jy) + 100)
, Coordinate(to_i32(kx) + 100, to_i32(ky) + 100) )));
println!("{:>14} : {}", pg, pg.plot());
let i = Vector( 0.0, -30.0, 0.0);
let j = Vector( 30.0, 30.0, 0.0);
let k = Vector(-30.0, 30.0, 0.0);
let rot :TMatrix<f64> = rotate_z(20);
let Vector(ix, iy, _) = rot.apply(&i);
let Vector(jx, jy, _) = rot.apply(&j);
let Vector(kx, ky, _) = rot.apply(&k);
fn to_i32_2(x :f64) -> i32 {
x.round() as i32
}
println!();
let pg = Polygon(
Coordinates(vec!( Coordinate(to_i32_2(ix) + 100, to_i32_2(iy) + 100)
, Coordinate(to_i32_2(jx) + 100, to_i32_2(jy) + 100)
, Coordinate(to_i32_2(kx) + 100, to_i32_2(ky) + 100) )));
println!("{:>14} : {}", pg, pg.plot());
}

Loading…
Cancel
Save