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