diff --git a/src/point.rs b/src/point.rs index 5a5a5e9..ba60266 100644 --- a/src/point.rs +++ b/src/point.rs @@ -12,6 +12,42 @@ pub struct Point { pub z: f64, } +#[macro_export] +///Generates a point in the xyz plane based on the following pattern: +///``` +///use dxf::point; +///use dxf::Point; +/////Generate a point at (1,2,3) +///let p1 = point!(1.0,2.0,3.0); +/////Generate a point at (1,2,0) +///let p2 = point!(1.0,2.0); +/////Generate a point at (1,0,0) +///let p3 = point!(1.0); +///``` +macro_rules! point { + ($x:expr, $y:expr, $z:expr) => { + Point { + x: $x as f64, + y: $y as f64, + z: $z as f64, + } + }; + ($x:expr, $y:expr) => { + Point { + x: $x as f64, + y: $y as f64, + z: 0.0, + } + }; + ($x:expr) => { + Point { + x: $x as f64, + y: 0.0, + z: 0.0, + } + }; +} + impl Point { /// Creates a new `Point` with the specified values. pub fn new(x: f64, y: f64, z: f64) -> Point { @@ -56,4 +92,11 @@ mod tests { dbg!(&t); assert_eq!(t, p.tuple()) } + #[test] + fn test_point_macro() { + let p = point!(1, 2, 3.5); + assert_eq!(p.x, 1.0); + assert_eq!(p.y, 2.0); + assert_eq!(p.z, 3.5); + } }