mirror of
https://github.com/gnxlxnxx/dubins_path
synced 2026-07-27 07:03:03 +02:00
Add approx_eq functions
This commit is contained in:
+32
-3
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user