Add approx_eq functions

master
Roman Kretschmer 6 years ago
parent ef876c1606
commit dde2449ffe
Signed by: gnxlxnxx
GPG Key ID: E4EAB482427FA3A0

@ -7,7 +7,7 @@
//! //!
//! Every struct defined here is 2 dimensional and uses f64 //! 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; use thiserror::Error;
pub type Angle = euclid::Angle<f64>; pub type Angle = euclid::Angle<f64>;
@ -31,6 +31,23 @@ pub struct Vector {
pub magnitude: f64, 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) /// Circle vector (Circle + Angle)
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct CircleVector { pub struct CircleVector {
@ -44,6 +61,20 @@ impl CircleVector {
pub fn get_length(&self) -> f64 { pub fn get_length(&self) -> f64 {
self.angle.radians * self.radius 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 /// 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( let vector_middle_center_end_center = Vector2D::new(
route_ccc.end.center.x - route_ccc.middle.center.x, route_ccc.end.center.x - route_ccc.middle.center.x,
route_ccc.end.center.y - route_ccc.middle.center.y, route_ccc.end.center.y - route_ccc.middle.center.y,

Loading…
Cancel
Save