|
|
|
@ -24,7 +24,7 @@ pub enum Error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Vector with origin, angle and magnitude
|
|
|
|
/// Vector with origin, angle and magnitude
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct Vector {
|
|
|
|
pub struct Vector {
|
|
|
|
pub origin: Point,
|
|
|
|
pub origin: Point,
|
|
|
|
pub angle: Angle,
|
|
|
|
pub angle: Angle,
|
|
|
|
@ -32,15 +32,22 @@ pub struct Vector {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Circle vector (Circle + Angle)
|
|
|
|
/// Circle vector (Circle + Angle)
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct CircleVector {
|
|
|
|
pub struct CircleVector {
|
|
|
|
pub center: Point,
|
|
|
|
pub center: Point,
|
|
|
|
pub radius: f64,
|
|
|
|
pub radius: f64,
|
|
|
|
pub angle: Angle,
|
|
|
|
pub angle: Angle,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl CircleVector {
|
|
|
|
|
|
|
|
///get the length of the circle vector
|
|
|
|
|
|
|
|
pub fn get_length(&self) -> f64 {
|
|
|
|
|
|
|
|
self.angle.radians * self.radius
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Route with a start Circle, a tangent straight and a end Circle
|
|
|
|
/// Route with a start Circle, a tangent straight and a end Circle
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct RouteCSC {
|
|
|
|
pub struct RouteCSC {
|
|
|
|
pub start: CircleVector,
|
|
|
|
pub start: CircleVector,
|
|
|
|
pub tangent: Vector,
|
|
|
|
pub tangent: Vector,
|
|
|
|
@ -48,13 +55,19 @@ pub struct RouteCSC {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Route with 3 Circles
|
|
|
|
/// Route with 3 Circles
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct RouteCCC {
|
|
|
|
pub struct RouteCCC {
|
|
|
|
pub start: CircleVector,
|
|
|
|
pub start: CircleVector,
|
|
|
|
pub middle: CircleVector,
|
|
|
|
pub middle: CircleVector,
|
|
|
|
pub end: CircleVector,
|
|
|
|
pub end: CircleVector,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
|
|
|
|
pub enum Path {
|
|
|
|
|
|
|
|
CSC(RouteCSC),
|
|
|
|
|
|
|
|
CCC(RouteCCC),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Route with a start Circle, a tangent straight and a end Circle
|
|
|
|
/// Route with a start Circle, a tangent straight and a end Circle
|
|
|
|
impl RouteCSC {
|
|
|
|
impl RouteCSC {
|
|
|
|
/// right straight right route
|
|
|
|
/// right straight right route
|
|
|
|
@ -349,5 +362,37 @@ impl RouteCSC {
|
|
|
|
|
|
|
|
|
|
|
|
Ok(route_csc)
|
|
|
|
Ok(route_csc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// get the length of the path
|
|
|
|
|
|
|
|
pub fn get_length(&self) -> f64 {
|
|
|
|
|
|
|
|
self.start.get_length() + self.tangent.magnitude + self.end.get_length()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// get the shortest circle straight circle route
|
|
|
|
|
|
|
|
pub fn get_shortest(end: Vector) -> Result<Self, Error> {
|
|
|
|
|
|
|
|
let mut route_csc;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let route_rsr = Self::rsr(end).unwrap();
|
|
|
|
|
|
|
|
let route_lsl = Self::rsr(end).unwrap();
|
|
|
|
|
|
|
|
let route_lsr = Self::rsr(end);
|
|
|
|
|
|
|
|
let route_rsl = Self::rsr(end);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
route_csc = route_rsr;
|
|
|
|
|
|
|
|
if route_lsl.get_length() < route_csc.get_length() {
|
|
|
|
|
|
|
|
route_csc = route_lsl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Ok(route_lsr) = route_lsr {
|
|
|
|
|
|
|
|
if route_lsr.get_length() < route_csc.get_length() {
|
|
|
|
|
|
|
|
route_csc = route_lsr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Ok(route_rsl) = route_rsl {
|
|
|
|
|
|
|
|
if route_rsl.get_length() < route_csc.get_length() {
|
|
|
|
|
|
|
|
route_csc = route_rsl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(route_csc)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|