mirror of
https://github.com/gnxlxnxx/dubins_path
synced 2026-07-27 15:13:02 +02:00
Use thiserror
This commit is contained in:
@@ -16,3 +16,4 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
euclid = "0.20.11"
|
euclid = "0.20.11"
|
||||||
|
thiserror = "1.0"
|
||||||
|
|||||||
+21
-9
@@ -8,13 +8,23 @@
|
|||||||
//! 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::{Point2D, Rotation2D, UnknownUnit};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
pub type Angle = euclid::Angle<f64>;
|
pub type Angle = euclid::Angle<f64>;
|
||||||
pub type Point = Point2D<f64, UnknownUnit>;
|
pub type Point = Point2D<f64, UnknownUnit>;
|
||||||
type Vector2D = euclid::Vector2D<f64, UnknownUnit>;
|
type Vector2D = euclid::Vector2D<f64, UnknownUnit>;
|
||||||
type Rotation = Rotation2D<f64, UnknownUnit, UnknownUnit>;
|
type Rotation = Rotation2D<f64, UnknownUnit, UnknownUnit>;
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum Error {
|
||||||
|
#[error("inside tangent cannot be constructed (circles too close together)")]
|
||||||
|
CirclesTooClose,
|
||||||
|
#[error("ccc path cannot be constructed (circles too far apart)")]
|
||||||
|
CirclesTooFarApart,
|
||||||
|
}
|
||||||
|
|
||||||
/// Vector with origin, angle and magnitude
|
/// Vector with origin, angle and magnitude
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Vector {
|
pub struct Vector {
|
||||||
pub origin: Point,
|
pub origin: Point,
|
||||||
pub angle: Angle,
|
pub angle: Angle,
|
||||||
@@ -22,21 +32,23 @@ pub struct Vector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Circle vector (Circle + Angle)
|
/// Circle vector (Circle + Angle)
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct CircleVector {
|
pub struct CircleVector {
|
||||||
pub center: Point,
|
pub center: Point,
|
||||||
pub radius: f64,
|
pub radius: f64,
|
||||||
pub angle: Angle,
|
pub angle: Angle,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Route with a start Circle, a tangent straight and a end Circle (eg. rsl, rsr, lsr, lsl)
|
/// Route with a start Circle, a tangent straight and a end Circle
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct RouteCSC {
|
pub struct RouteCSC {
|
||||||
pub start: CircleVector,
|
pub start: CircleVector,
|
||||||
pub tangent: Vector,
|
pub tangent: Vector,
|
||||||
pub end: CircleVector,
|
pub end: CircleVector,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Route with 3 Circles (eg. rlr, lrl) (not yet implemented)
|
/// Route with 3 Circles
|
||||||
#[allow(unused)]
|
#[derive(Debug)]
|
||||||
pub struct RouteCCC {
|
pub struct RouteCCC {
|
||||||
pub start: CircleVector,
|
pub start: CircleVector,
|
||||||
pub middle: CircleVector,
|
pub middle: CircleVector,
|
||||||
@@ -46,7 +58,7 @@ pub struct 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
|
||||||
pub fn rsr(end: Vector) -> Result<Self, ()> {
|
pub fn rsr(end: Vector) -> Result<Self, Error> {
|
||||||
let mut route_csc = RouteCSC {
|
let mut route_csc = RouteCSC {
|
||||||
start: CircleVector {
|
start: CircleVector {
|
||||||
center: Point::new(end.magnitude, 0.0),
|
center: Point::new(end.magnitude, 0.0),
|
||||||
@@ -113,7 +125,7 @@ impl RouteCSC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// left straight left route
|
/// left straight left route
|
||||||
pub fn lsl(end: Vector) -> Result<Self, ()> {
|
pub fn lsl(end: Vector) -> Result<Self, Error> {
|
||||||
let mut route_csc = RouteCSC {
|
let mut route_csc = RouteCSC {
|
||||||
start: CircleVector {
|
start: CircleVector {
|
||||||
center: Point::new(-end.magnitude, 0.0),
|
center: Point::new(-end.magnitude, 0.0),
|
||||||
@@ -184,7 +196,7 @@ impl RouteCSC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// right straight left route
|
/// right straight left route
|
||||||
pub fn rsl(end: Vector) -> Result<Self, ()> {
|
pub fn rsl(end: Vector) -> Result<Self, Error> {
|
||||||
let mut route_csc = RouteCSC {
|
let mut route_csc = RouteCSC {
|
||||||
start: CircleVector {
|
start: CircleVector {
|
||||||
center: Point::new(end.magnitude, 0.0),
|
center: Point::new(end.magnitude, 0.0),
|
||||||
@@ -217,7 +229,7 @@ impl RouteCSC {
|
|||||||
.sqrt()
|
.sqrt()
|
||||||
< 2.0 * end.magnitude
|
< 2.0 * end.magnitude
|
||||||
{
|
{
|
||||||
return Err(());
|
return Err(Error::CirclesTooClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the tangent length via some simple trigonometry
|
// get the tangent length via some simple trigonometry
|
||||||
@@ -261,7 +273,7 @@ impl RouteCSC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// left straight right route
|
/// left straight right route
|
||||||
pub fn lsr(end: Vector) -> Result<Self, ()> {
|
pub fn lsr(end: Vector) -> Result<Self, Error> {
|
||||||
let mut route_csc = RouteCSC {
|
let mut route_csc = RouteCSC {
|
||||||
start: CircleVector {
|
start: CircleVector {
|
||||||
center: Point::new(-end.magnitude, 0.0),
|
center: Point::new(-end.magnitude, 0.0),
|
||||||
@@ -295,7 +307,7 @@ impl RouteCSC {
|
|||||||
.sqrt()
|
.sqrt()
|
||||||
< 2.0 * end.magnitude
|
< 2.0 * end.magnitude
|
||||||
{
|
{
|
||||||
return Err(());
|
return Err(Error::CirclesTooClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the tangent length via some simple trigonometry
|
// get the tangent length via some simple trigonometry
|
||||||
|
|||||||
Reference in New Issue
Block a user