use std::vec;
use vexide::math::Angle;
use crate::utils::units::Length;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Point {
pub x: f64,
pub y: f64,
}
#[derive(Debug, Clone)]
pub struct Path {
pub waypoints: Vec<Point>,
}
#[derive(Clone, Copy)]
pub struct Line {
pub point1: Point,
pub point2: Point,
}
#[derive(Clone, Copy)]
pub struct Circle {
pub x: f64,
pub y: f64,
pub r: f64,
}
impl Point {
pub fn new(x: Length, y: Length) -> Self {
Point {
x: x.as_inches(),
y: y.as_inches(),
}
}
pub fn rnew(x: f64, y: f64) -> Self { Point { x: x, y: y } }
pub fn origin() -> Self { Point { x: 0.0, y: 0.0 } }
}
impl Path {
pub fn from_vec(waypoints: Vec<Point>) -> Self {
Self {
waypoints: waypoints,
}
}
pub fn origin() -> Self {
let vec = vec![Point::origin()];
Self { waypoints: vec }
}
pub fn from_pt(pt: Point) -> Self {
let vec = vec![pt];
Self { waypoints: vec }
}
pub fn add(&mut self, waypoint: Point) { self.waypoints.push(waypoint); }
pub fn append_vec(&mut self, mut waypoints: Vec<Point>) {
self.waypoints.append(&mut waypoints);
}
pub fn remove(&mut self, t: usize) { self.waypoints.remove(t); }
pub fn get_lines(&self) -> Vec<Line> {
let mut lines: Vec<Line> = Vec::new();
for i in 0..self.waypoints.len() - 1 {
lines.push(Line {
point1: Point::new(
Length::from_inches(self.waypoints[i].x),
Length::from_inches(self.waypoints[i].y),
),
point2: Point::new(
Length::from_inches(self.waypoints[i + 1].x),
Length::from_inches(self.waypoints[i + 1].y),
),
});
}
lines
}
}
impl Line {
pub fn new(x1: Length, y1: Length, x2: Length, y2: Length) -> Line {
Line {
point1: Point {
x: (x1.as_inches()),
y: (y1.as_inches()),
},
point2: Point {
x: (x2.as_inches()),
y: (y2.as_inches()),
},
}
}
pub fn from_pts(point1: Point, point2: Point) -> Line {
Line {
point1: point1,
point2: point2,
}
}
}
impl Circle {
pub fn new(x: Length, y: Length, r: Length) -> Circle {
Circle {
x: x.as_inches(),
y: y.as_inches(),
r: r.as_inches(),
}
}
pub fn rnew(x: f64, y: f64, r: f64) -> Circle { Circle { x: x, y: y, r: r } }
}
#[derive(Debug, Clone, Copy)]
pub struct Pose {
pub x: Length,
pub y: Length,
pub t: Angle,
}
impl Pose {
pub fn new(x: Length, y: Length, t: Angle) -> Self { Self { x, y, t } }
pub fn origin() -> Self {
Self {
x: Length::zero(),
y: Length::zero(),
t: Angle::ZERO,
}
}
}