1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use ::{
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: x,
y: y,
z: 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(())
}
}