diff options
Diffstat (limited to 'src/renderer.rs')
-rw-r--r-- | src/renderer.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index 14dfb6f..c523268 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -38,6 +38,20 @@ fn render_circle<P: Pixel>(layer: &mut TileLayer<P>, center: (u64, u64), radius: } } +fn direction_vector(a: (u64, u64), b: (u64, u64)) -> Vector2<f64> { + let dx = if b.0 > a.0 { + (b.0 - a.0) as f64 + } else { + -((a.0 - b.0) as f64) + }; + let dy = if b.1 > a.1 { + (b.1 - a.1) as f64 + } else { + -((a.1 - b.1) as f64) + }; + vector![dx, dy] +} + fn render_line<P: Pixel>( layer: &mut TileLayer<P>, start: (u64, u64), @@ -58,16 +72,15 @@ fn render_line<P: Pixel>( a[0] + b[0] as u64 }; let y = if b[1] < 0 { - a[1] - b[0].abs() as u64 + a[1] - b[1].abs() as u64 } else { a[1] + b[1] as u64 }; vector![x, y] } - let r = vector![end.0 as f64, end.1 as f64] - vector![start.0 as f64, start.1 as f64]; - let r = r.normalize(); - let normal = vector![r[1], -r[0]]; + let r = direction_vector(start, end); + let normal = vector![r[1], -r[0]].normalize(); let start = vector![start.0, start.1]; let end = vector![end.0, end.1]; |