|
|
|
@ -1,5 +1,6 @@
|
|
|
|
use super::{two_dec, Circularity, ScaleEntity};
|
|
|
|
use super::{two_dec, Circularity, ScaleEntity};
|
|
|
|
use dxf::entities::{self, Circle, LwPolyline, Polyline};
|
|
|
|
use dxf::entities::{self, Circle, LwPolyline, Polyline};
|
|
|
|
|
|
|
|
use hex_color::HexColor;
|
|
|
|
use simple_xml_builder::XMLElement;
|
|
|
|
use simple_xml_builder::XMLElement;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
@ -7,6 +8,7 @@ pub struct Ellipse {
|
|
|
|
height: f64,
|
|
|
|
height: f64,
|
|
|
|
width: f64,
|
|
|
|
width: f64,
|
|
|
|
style: String,
|
|
|
|
style: String,
|
|
|
|
|
|
|
|
color: HexColor,
|
|
|
|
|
|
|
|
|
|
|
|
//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?
|
|
|
|
pub x: f64,
|
|
|
|
pub x: f64,
|
|
|
|
@ -22,6 +24,7 @@ impl From<&Circle> for Ellipse {
|
|
|
|
y: -circ.center.y - circ.radius,
|
|
|
|
y: -circ.center.y - circ.radius,
|
|
|
|
height: circ.radius * 2.0,
|
|
|
|
height: circ.radius * 2.0,
|
|
|
|
width: circ.radius * 2.0,
|
|
|
|
width: circ.radius * 2.0,
|
|
|
|
|
|
|
|
color: HexColor::BLACK,
|
|
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
//reasons...I'm trying to think if there is a time we might want to turn it on?
|
|
|
|
//reasons...I'm trying to think if there is a time we might want to turn it on?
|
|
|
|
@ -43,6 +46,7 @@ impl From<&entities::Ellipse> for Ellipse {
|
|
|
|
y: -ellipse.center.y - ellipse.major_axis.x * ellipse.minor_axis_ratio,
|
|
|
|
y: -ellipse.center.y - ellipse.major_axis.x * ellipse.minor_axis_ratio,
|
|
|
|
width: ellipse.major_axis.x * 2.0,
|
|
|
|
width: ellipse.major_axis.x * 2.0,
|
|
|
|
height: ellipse.major_axis.x * 2.0 * ellipse.minor_axis_ratio,
|
|
|
|
height: ellipse.major_axis.x * 2.0 * ellipse.minor_axis_ratio,
|
|
|
|
|
|
|
|
color: HexColor::BLACK,
|
|
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
//reasons...I'm trying to think if there is a time we might want to turn it on?
|
|
|
|
//reasons...I'm trying to think if there is a time we might want to turn it on?
|
|
|
|
@ -87,6 +91,7 @@ impl TryFrom<&Polyline> for Ellipse {
|
|
|
|
y: -max_y,
|
|
|
|
y: -max_y,
|
|
|
|
height: max_y - y,
|
|
|
|
height: max_y - y,
|
|
|
|
width: max_x - x,
|
|
|
|
width: max_x - x,
|
|
|
|
|
|
|
|
color: HexColor::BLACK,
|
|
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
//reasons...I'm trying to think if there is a time we might want to turn it on?
|
|
|
|
//reasons...I'm trying to think if there is a time we might want to turn it on?
|
|
|
|
@ -100,6 +105,12 @@ impl TryFrom<&LwPolyline> for Ellipse {
|
|
|
|
type Error = &'static str; //add better error later
|
|
|
|
type Error = &'static str; //add better error later
|
|
|
|
|
|
|
|
|
|
|
|
fn try_from(poly: &LwPolyline) -> Result<Self, Self::Error> {
|
|
|
|
fn try_from(poly: &LwPolyline) -> Result<Self, Self::Error> {
|
|
|
|
|
|
|
|
Self::try_from_lwpolyline_with_color(poly, HexColor::BLACK)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Ellipse {
|
|
|
|
|
|
|
|
pub fn try_from_lwpolyline_with_color(poly: &LwPolyline, color: HexColor) -> Result<Self, &'static str> {
|
|
|
|
let is_bugle_circle = poly.is_circular_with_bulge();
|
|
|
|
let is_bugle_circle = poly.is_circular_with_bulge();
|
|
|
|
|
|
|
|
|
|
|
|
if !is_bugle_circle&&!poly.is_circular() {
|
|
|
|
if !is_bugle_circle&&!poly.is_circular() {
|
|
|
|
@ -126,6 +137,8 @@ impl TryFrom<&LwPolyline> for Ellipse {
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.fold(f64::MIN, |max_y, vtx| max_y.max(vtx.y));
|
|
|
|
.fold(f64::MIN, |max_y, vtx| max_y.max(vtx.y));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let style = format!("line-style:normal;line-weight:thin;filling:none;color:rgb({},{},{})", color.r, color.g, color.b);
|
|
|
|
|
|
|
|
|
|
|
|
Ok(Ellipse {
|
|
|
|
Ok(Ellipse {
|
|
|
|
x,
|
|
|
|
x,
|
|
|
|
y: if is_bugle_circle {-max_y-(max_x - x)/2.0} else {-max_y},
|
|
|
|
y: if is_bugle_circle {-max_y-(max_x - x)/2.0} else {-max_y},
|
|
|
|
@ -135,11 +148,12 @@ impl TryFrom<&LwPolyline> for Ellipse {
|
|
|
|
max_y - y
|
|
|
|
max_y - y
|
|
|
|
},
|
|
|
|
},
|
|
|
|
width: max_x - x,
|
|
|
|
width: max_x - x,
|
|
|
|
|
|
|
|
color,
|
|
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
//reasons...I'm trying to think if there is a time we might want to turn it on?
|
|
|
|
//reasons...I'm trying to think if there is a time we might want to turn it on?
|
|
|
|
antialias: false,
|
|
|
|
antialias: false,
|
|
|
|
style: "line-style:normal;line-weight:thin;filling:none;color:black".into(),
|
|
|
|
style,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -153,6 +167,7 @@ impl From<&Ellipse> for XMLElement {
|
|
|
|
ell_xml.add_attribute("height", two_dec(ell.height));
|
|
|
|
ell_xml.add_attribute("height", two_dec(ell.height));
|
|
|
|
ell_xml.add_attribute("antialias", ell.antialias);
|
|
|
|
ell_xml.add_attribute("antialias", ell.antialias);
|
|
|
|
ell_xml.add_attribute("style", &ell.style);
|
|
|
|
ell_xml.add_attribute("style", &ell.style);
|
|
|
|
|
|
|
|
ell_xml.add_attribute("color", ell.color.display_rgb().to_string());
|
|
|
|
ell_xml
|
|
|
|
ell_xml
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -168,6 +183,14 @@ impl Ellipse {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
update_fn(&mut self.style);
|
|
|
|
update_fn(&mut self.style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_color(&mut self, color: HexColor) {
|
|
|
|
|
|
|
|
self.color = color;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_color(&self) -> HexColor {
|
|
|
|
|
|
|
|
self.color
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl ScaleEntity for Ellipse {
|
|
|
|
impl ScaleEntity for Ellipse {
|
|
|
|
|