use crate::{CodePair, DxfError, DxfResult};
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
pub struct Point {
pub x: f64,
pub y: f64,
pub z: f64,
}
impl Point {
pub fn new(x: f64, y: f64, z: f64) -> Point {
Point { x, y, z }
}
pub fn origin() -> Point {
Point::new(0.0, 0.0, 0.0)
}
pub(crate) fn set(&mut self, pair: &CodePair) -> DxfResult<()> {
match pair.code {
10 => self.x = pair.assert_f64()?,
20 => self.y = pair.assert_f64()?,
30 => self.z = pair.assert_f64()?,
_ => {
return Err(DxfError::UnexpectedCodePair(
pair.clone(),
String::from("expected code [10, 20, 30] for point"),
))
}
}
Ok(())
}
}