Use Impl for the RouteCSC struct

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

@ -43,8 +43,10 @@ pub struct RouteCCC {
pub end: CircleVector, pub end: CircleVector,
} }
/// Route with a start Circle, a tangent straight and a end Circle
impl RouteCSC {
/// right straight right route /// right straight right route
pub fn rsr(end: Vector) -> Result<RouteCSC, ()> { pub fn rsr(end: Vector) -> Result<Self, ()> {
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),
@ -111,7 +113,7 @@ pub fn rsr(end: Vector) -> Result<RouteCSC, ()> {
} }
/// left straight left route /// left straight left route
pub fn lsl(end: Vector) -> Result<RouteCSC, ()> { pub fn lsl(end: Vector) -> Result<Self, ()> {
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),
@ -182,7 +184,7 @@ pub fn lsl(end: Vector) -> Result<RouteCSC, ()> {
} }
/// right straight left route /// right straight left route
pub fn rsl(end: Vector) -> Result<RouteCSC, ()> { pub fn rsl(end: Vector) -> Result<Self, ()> {
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),
@ -229,7 +231,8 @@ pub fn rsl(end: Vector) -> Result<RouteCSC, ()> {
// get the tangent angle // get the tangent angle
route_csc.tangent.angle = Angle::radians( route_csc.tangent.angle = Angle::radians(
((route_csc.end.center.y - tangent_middle.y) / (route_csc.end.center.x - tangent_middle.x)) ((route_csc.end.center.y - tangent_middle.y)
/ (route_csc.end.center.x - tangent_middle.x))
.atan() .atan()
- (2.0 * end.magnitude / route_csc.tangent.magnitude).atan(), - (2.0 * end.magnitude / route_csc.tangent.magnitude).atan(),
); );
@ -251,13 +254,14 @@ pub fn rsl(end: Vector) -> Result<RouteCSC, ()> {
.transform_vector(Vector2D::new(route_csc.start.radius, 0.0)); .transform_vector(Vector2D::new(route_csc.start.radius, 0.0));
// get the angle of the end circle // get the angle of the end circle
route_csc.end.angle = ((Angle::frac_pi_2() - end.angle) - route_csc.tangent.angle).positive(); route_csc.end.angle =
((Angle::frac_pi_2() - end.angle) - route_csc.tangent.angle).positive();
Ok(route_csc) Ok(route_csc)
} }
/// left straight right route /// left straight right route
pub fn lsr(end: Vector) -> Result<RouteCSC, ()> { pub fn lsr(end: Vector) -> Result<Self, ()> {
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),
@ -305,7 +309,8 @@ pub fn lsr(end: Vector) -> Result<RouteCSC, ()> {
// get the tangent angle // get the tangent angle
route_csc.tangent.angle = Angle::radians( route_csc.tangent.angle = Angle::radians(
((route_csc.end.center.y - tangent_middle.y) / (route_csc.end.center.x - tangent_middle.x)) ((route_csc.end.center.y - tangent_middle.y)
/ (route_csc.end.center.x - tangent_middle.x))
.atan() .atan()
+ (2.0 * end.magnitude / route_csc.tangent.magnitude).atan(), + (2.0 * end.magnitude / route_csc.tangent.magnitude).atan(),
); );
@ -320,6 +325,23 @@ pub fn lsr(end: Vector) -> Result<RouteCSC, ()> {
// get the angle of the start circle // get the angle of the start circle
route_csc.start.angle = (route_csc.tangent.angle - Angle::frac_pi_2()).positive(); route_csc.start.angle = (route_csc.tangent.angle - Angle::frac_pi_2()).positive();
// get the tangent origin by moving the vector from the start circle center
// 90° to it's own direction and the magnitude of the circle radius
route_csc.tangent.origin = route_csc.start.center
+ Rotation::new(route_csc.start.angle)
.transform_vector(Vector2D::new(route_csc.start.radius, 0.0));
// get the angle of the end circle
route_csc.end.angle =
((Angle::frac_pi_2() - end.angle) - route_csc.tangent.angle).positive();
Ok(route_csc)
}
}
// get the angle of the start circle
route_csc.start.angle = (route_csc.tangent.angle - Angle::frac_pi_2()).positive();
// get the tangent origin by moving the vector from the start circle center // get the tangent origin by moving the vector from the start circle center
// 90° to it's own direction and the magnitude of the circle radius // 90° to it's own direction and the magnitude of the circle radius
route_csc.tangent.origin = route_csc.start.center route_csc.tangent.origin = route_csc.start.center

Loading…
Cancel
Save