commit 1732c2909604aef826749c0399019bb1e5629cfa
parent 0dca15cace538fe59deece607b2147ea82b53975
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date: Sun, 14 Oct 2018 14:31:58 -0400
Correct coordinate calculation for really wide or long pictures.
Diffstat:
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/main.rs b/src/main.rs
@@ -3,9 +3,10 @@ extern crate svg;
use std::cmp;
use std::io;
use std::vec::Vec;
-use svg::Document;
+
use svg::node::element::Polygon;
use svg::node::element::Rectangle;
+use svg::Document;
fn print_points(points: &Vec<(f64, f64)>) -> String {
let mut result = String::new();
@@ -30,13 +31,18 @@ fn main() -> io::Result<()> {
let unit: f64 = (cmp::min(width, height) as f64) / 10.;
let center: (f64, f64) = ((width as f64) / 2., (height as f64) / 2.);
+ let top_touch: f64 = center.0 + 2. / 3. * center.1 - 2. * unit;
+ let right_touch: f64 = center.1 + 2. * unit - 2. / 3. * center.0;
let flare_points: Vec<(f64, f64)> = vec![
(center.0 - 3. * unit, center.1),
(center.0 - 6. / 5. * unit, center.1 - 6. / 5. * unit),
- (center.0 + 2. / 3. * center.1 - 2. * unit, 0.),
+ (
+ top_touch.min(width as f64),
+ (top_touch - width as f64).max(0.),
+ ),
(width as f64, 0.),
- (width as f64, center.1 + 2. * unit - 2. / 3. * center.0),
+ (width as f64 + right_touch.min(0.), right_touch.max(0.)),
(center.0 + 6. / 5. * unit, center.1 + 6. / 5. * unit),
(center.0, center.1 + 3. * unit),
(center.0 - 6. / 5. * unit, center.1 + 6. / 5. * unit),