-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint.rs
More file actions
77 lines (72 loc) · 1.72 KB
/
Copy pathpoint.rs
File metadata and controls
77 lines (72 loc) · 1.72 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! POINT entity (§19.4.27).
//!
//! # Stream shape
//!
//! ```text
//! BD x
//! BD y
//! BD z
//! BT thickness
//! BE extrusion
//! BD x-axis-angle -- in radians (UCS-local rotation of the point marker)
//! ```
use crate::bitcursor::BitCursor;
use crate::entities::{Point3D, Vec3D, read_be, read_bt};
use crate::error::Result;
#[derive(Debug, Clone, PartialEq)]
pub struct Point {
pub position: Point3D,
pub thickness: f64,
pub extrusion: Vec3D,
pub x_axis_angle: f64,
}
pub fn decode(c: &mut BitCursor<'_>) -> Result<Point> {
let x = c.read_bd()?;
let y = c.read_bd()?;
let z = c.read_bd()?;
let thickness = read_bt(c)?;
let extrusion = read_be(c)?;
let x_axis_angle = c.read_bd()?;
Ok(Point {
position: Point3D { x, y, z },
thickness,
extrusion,
x_axis_angle,
})
}
#[cfg(test)]
mod tests {
use super::*;
use crate::bitwriter::BitWriter;
#[test]
fn roundtrip_point() {
let mut w = BitWriter::new();
w.write_bd(1.25);
w.write_bd(2.5);
w.write_bd(3.75);
w.write_b(true); // default thickness
w.write_b(true); // default extrusion
w.write_bd(0.0); // no rotation
let bytes = w.into_bytes();
let mut c = BitCursor::new(&bytes);
let p = decode(&mut c).unwrap();
assert_eq!(
p.position,
Point3D {
x: 1.25,
y: 2.5,
z: 3.75
}
);
assert_eq!(p.thickness, 0.0);
assert_eq!(
p.extrusion,
Vec3D {
x: 0.0,
y: 0.0,
z: 1.0
}
);
assert_eq!(p.x_axis_angle, 0.0);
}
}