diff --git a/src/qelmt/arc.rs b/src/qelmt/arc.rs index db42e46..d3daec3 100644 --- a/src/qelmt/arc.rs +++ b/src/qelmt/arc.rs @@ -4,6 +4,18 @@ use dxf::entities::LwPolyline; use hex_color::HexColor; use simple_xml_builder::XMLElement; +fn normalize_angle(angle: f64) -> f64 { + let mut norm = angle % 360.0; + if norm < 0.0 { + norm += 360.0; + } + norm +} + +fn qet_start_angle(angle: f64) -> f64 { + normalize_angle(270.0 - angle) +} + #[derive(Debug)] pub struct Arc { //need to brush up on my Rust scoping rules, isn't there a way to make this pub to just the module? @@ -74,7 +86,7 @@ impl Arc { y: -arc.center.y - arc.radius, height: arc.radius * 2.0, width: arc.radius * 2.0, - start: if start_angle < 0.0 { -start_angle } else { start_angle }, + start: qet_start_angle(normalize_angle(start_angle)), angle: if angle_span < 0.0 { -angle_span } else { angle_span }, //in the original code antialias is always set to false...I'm guessing for performance @@ -275,18 +287,8 @@ impl Arc { (start_y_qet - center_y_qet).atan2(start.0 - center_x).to_degrees(); let mut end_angle = (end_y_qet - center_y_qet).atan2(end.0 - center_x).to_degrees(); - let normalize = |mut angle: f64| { - while angle < 0.0 { - angle += 360.0; - } - while angle >= 360.0 { - angle -= 360.0; - } - angle - }; - - start_angle = normalize(start_angle); - end_angle = normalize(end_angle); + start_angle = normalize_angle(start_angle); + end_angle = normalize_angle(end_angle); let ccw_sweep = (end_angle - start_angle).rem_euclid(360.0); let cw_sweep = (start_angle - end_angle).rem_euclid(360.0); @@ -305,6 +307,8 @@ impl Arc { return Err("Arc sweep too small".into()); } + let start_angle = qet_start_angle(start_angle); + Ok(Arc { x: center_x - radius, y: center_y_qet - radius,