diff --git a/src/lib.rs b/src/lib.rs index 90adea3..b74d6bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,13 +30,24 @@ //! //! -use euclid::{approxeq::ApproxEq, Point2D, Rotation2D, UnknownUnit}; -use num_traits; +use std::{ + cmp::PartialOrd, + convert, + ops::{Add, Mul, Rem, Sub}, +}; + +use convert::From; +pub use euclid::Angle; +use euclid::{approxeq::ApproxEq, Point2D, Rotation2D, Trig, UnknownUnit, Vector2D}; +use num_traits::{ + self, + float::{Float, FloatConst}, + Zero, +}; use thiserror::Error; -pub type Angle = euclid::Angle; pub type Point = Point2D; -pub type Vector = euclid::Vector2D; +pub type Vector = Vector2D; type Rotation = Rotation2D; #[derive(Debug, Error)] @@ -54,7 +65,7 @@ pub struct StraightPath { pub vector: Vector, } -impl> StraightPath { +impl> StraightPath { /// approximate equality to other Vector pub fn approx_eq(&self, other: Self) -> bool { ApproxEq::approx_eq(&self.vector, &other.vector) @@ -66,13 +77,13 @@ impl> StraightPath { #[derive(Debug, Copy, Clone)] pub struct CirclePath where - T: std::ops::Mul - + euclid::approxeq::ApproxEq - + std::ops::Rem - + std::ops::Sub - + std::ops::Add - + num_traits::Zero - + num_traits::FloatConst + T: Mul + + ApproxEq + + Rem + + Sub + + Add + + Zero + + FloatConst + PartialOrd + Copy, { @@ -83,13 +94,13 @@ where impl CirclePath where - T: std::ops::Mul - + euclid::approxeq::ApproxEq - + std::ops::Rem - + std::ops::Sub - + std::ops::Add - + num_traits::Zero - + num_traits::FloatConst + T: Mul + + ApproxEq + + Rem + + Sub + + Add + + Zero + + FloatConst + PartialOrd + Copy, { @@ -117,14 +128,14 @@ where #[derive(Debug, Copy, Clone)] pub struct RouteCSC where - T: std::ops::Mul - + std::ops::Mul - + euclid::approxeq::ApproxEq - + std::ops::Rem - + std::ops::Sub - + std::ops::Add - + num_traits::Zero - + num_traits::FloatConst + T: Mul + + Mul + + ApproxEq + + Rem + + Sub + + Add + + Zero + + FloatConst + PartialOrd + Copy, { @@ -137,14 +148,14 @@ where #[derive(Debug, Copy, Clone)] pub struct RouteCCC where - T: std::ops::Mul - + std::ops::Mul - + euclid::approxeq::ApproxEq - + std::ops::Rem - + std::ops::Sub - + std::ops::Add - + num_traits::Zero - + num_traits::FloatConst + T: Mul + + Mul + + ApproxEq + + Rem + + Sub + + Add + + Zero + + FloatConst + PartialOrd + Copy, { @@ -156,14 +167,14 @@ where #[derive(Debug, Copy, Clone)] pub enum Path where - T: std::ops::Mul - + std::ops::Mul - + euclid::approxeq::ApproxEq - + std::ops::Rem - + std::ops::Sub - + std::ops::Add - + num_traits::Zero - + num_traits::FloatConst + T: Mul + + Mul + + ApproxEq + + Rem + + Sub + + Add + + Zero + + FloatConst + PartialOrd + Copy, { @@ -174,15 +185,15 @@ where /// Route with a start Circle, a tangent straight and a end Circle impl RouteCSC where - T: std::ops::Add - + std::ops::Mul - + std::ops::Mul - + num_traits::float::FloatConst - + num_traits::float::Float - + std::cmp::PartialOrd - + std::convert::From - + euclid::approxeq::ApproxEq - + euclid::Trig, + T: Add + + Mul + + Mul + + FloatConst + + Float + + PartialOrd + + From + + ApproxEq + + Trig, { /// right straight right route pub fn rsr(radius: T, end_point: Point, end_angle: Angle) -> Result { @@ -233,7 +244,7 @@ where Ok(Self { start: CirclePath { center: start_center, - radius: radius, + radius, angle: start_angle, }, tangent: StraightPath { @@ -242,7 +253,7 @@ where }, end: CirclePath { center: end_center, - radius: radius, + radius, angle: end_angle, }, }) @@ -296,7 +307,7 @@ where Ok(Self { start: CirclePath { center: start_center, - radius: radius, + radius, angle: start_angle, }, tangent: StraightPath { @@ -305,7 +316,7 @@ where }, end: CirclePath { center: end_center, - radius: radius, + radius, angle: end_angle, }, }) @@ -368,7 +379,7 @@ where Ok(Self { start: CirclePath { center: start_center, - radius: radius, + radius, angle: start_angle, }, tangent: StraightPath { @@ -377,7 +388,7 @@ where }, end: CirclePath { center: end_center, - radius: radius, + radius, angle: end_angle, }, }) @@ -440,7 +451,7 @@ where Ok(Self { start: CirclePath { center: start_center, - radius: radius, + radius, angle: start_angle, }, tangent: StraightPath { @@ -449,7 +460,7 @@ where }, end: CirclePath { center: end_center, - radius: radius, + radius, angle: end_angle, }, }) @@ -495,15 +506,15 @@ where /// Route with 3 Circles impl RouteCCC where - T: std::ops::Add - + std::ops::Mul - + std::ops::Mul - + num_traits::float::FloatConst - + num_traits::float::Float - + std::cmp::PartialOrd - + std::convert::From - + euclid::approxeq::ApproxEq - + euclid::Trig, + T: Add + + Mul + + Mul + + FloatConst + + Float + + PartialOrd + + From + + ApproxEq + + Trig, { /// right left right route (not working yet) pub fn rlr(radius: T, end_point: Point, end_angle: Angle) -> Result { @@ -537,8 +548,8 @@ where + (vector_start_center_end_center.length() / (radius * 4.0)).acos(); vector_start_center_middle_center = Vector::new( - (radius * 2.0) * euclid::Trig::cos(vector_start_center_middle_center_angle), - (radius * 2.0) * euclid::Trig::sin(vector_start_center_middle_center_angle), + (radius * 2.0) * Trig::cos(vector_start_center_middle_center_angle), + (radius * 2.0) * Trig::sin(vector_start_center_middle_center_angle), ); Point::new( @@ -571,17 +582,17 @@ where Ok(Self { start: CirclePath { center: start_center, - radius: radius, + radius, angle: start_angle, }, middle: CirclePath { center: middle_center, - radius: radius, + radius, angle: middle_angle, }, end: CirclePath { center: end_center, - radius: radius, + radius, angle: end_angle, }, }) @@ -618,8 +629,8 @@ where - (vector_start_center_end_center.length() / (radius * 4.0)).acos(); vector_start_center_middle_center = Vector::new( - (radius * 2.0) * euclid::Trig::cos(vector_start_center_middle_center_angle), - (radius * 2.0) * euclid::Trig::sin(vector_start_center_middle_center_angle), + (radius * 2.0) * Trig::cos(vector_start_center_middle_center_angle), + (radius * 2.0) * Trig::sin(vector_start_center_middle_center_angle), ); Point::new( @@ -648,17 +659,17 @@ where Ok(Self { start: CirclePath { center: start_center, - radius: radius, + radius, angle: start_angle, }, middle: CirclePath { center: middle_center, - radius: radius, + radius, angle: middle_angle, }, end: CirclePath { center: end_center, - radius: radius, + radius, angle: end_angle, }, }) @@ -699,15 +710,15 @@ where /// get the shortest path pub fn get_shortest(radius: T, end_point: Point, end_angle: Angle) -> Path where - T: std::ops::Add - + std::ops::Mul - + std::ops::Mul - + num_traits::float::FloatConst - + num_traits::float::Float - + std::cmp::PartialOrd - + std::convert::From - + euclid::approxeq::ApproxEq - + euclid::Trig, + T: Add + + Mul + + Mul + + FloatConst + + Float + + PartialOrd + + From + + ApproxEq + + Trig, { let route_csc = RouteCSC::get_shortest(radius, end_point, end_angle).unwrap(); let route_ccc = RouteCCC::get_shortest(radius, end_point, end_angle);