use crate::primitives::ws;
use crate::ws_separated;
use nom::character::complete::u32;
use nom::number::complete::float;
use nom::{IResult, Parser};
#[derive(Debug, PartialEq, Clone, Default, PartialOrd)]
pub struct Point {
pub loop_label: u32,
pub x: f32,
pub y: f32,
pub angle: f32,
}
pub fn point(input: &str) -> IResult<&str, Point> {
let (remaining, (loop_label, x, y, angle)) =
ws_separated!((u32, float, float, float)).parse(input)?;
let point = Point {
loop_label,
x,
y,
angle,
};
Ok((remaining, point))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_point() {
let input = "0 100.0 200.0 45.0";
let (remaining, point) = point(input).unwrap();
assert_eq!(remaining, "");
assert_eq!(
point,
Point {
loop_label: 0,
x: 100.0,
y: 200.0,
angle: 45.0
}
);
}
}