diff --git a/src/lib.rs b/src/lib.rs index 4ff4cd2..f6c95ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ //! //! Every struct defined here is 2 dimensional and uses f64 -use euclid::{Point2D, Rotation2D, UnknownUnit}; +use euclid::{approxeq::ApproxEq, Point2D, Rotation2D, UnknownUnit}; use thiserror::Error; pub type Angle = euclid::Angle; @@ -31,6 +31,23 @@ pub struct Vector { pub magnitude: f64, } +impl Vector { + /// approximate equality to other Vector + pub fn approx_eq(&self, other: Self) -> bool { + if !ApproxEq::approx_eq(&self.origin, &other.origin) { + false + } else if !ApproxEq::approx_eq(&self.magnitude, &other.magnitude) { + false + } else if !ApproxEq::approx_eq(&self.angle, &other.angle) + || !ApproxEq::approx_eq(&self.angle.signed(), &other.angle.signed()) + { + false + } else { + true + } + } +} + /// Circle vector (Circle + Angle) #[derive(Debug, Copy, Clone)] pub struct CircleVector { @@ -44,6 +61,20 @@ impl CircleVector { pub fn get_length(&self) -> f64 { self.angle.radians * self.radius } + /// approximate equality to other CircleVector + pub fn approx_eq(&self, other: Self) -> bool { + if !ApproxEq::approx_eq(&self.center, &other.center) { + false + } else if !ApproxEq::approx_eq(&self.radius, &other.radius) { + false + } else if !(ApproxEq::approx_eq(&self.angle, &other.angle) + || ApproxEq::approx_eq(&self.angle.signed(), &other.angle.signed())) + { + false + } else { + true + } + } } /// Route with a start Circle, a tangent straight and a end Circle @@ -553,8 +584,6 @@ impl RouteCCC { ) }; - // TODO: Get the angles - let vector_middle_center_end_center = Vector2D::new( route_ccc.end.center.x - route_ccc.middle.center.x, route_ccc.end.center.y - route_ccc.middle.center.y,