// -*- coding: utf-8 -*- // // Copyright 2021 Michael Büsch // // Licensed under the Apache License version 2.0 // or the MIT license, at your option. // SPDX-License-Identifier: Apache-2.0 OR MIT // use crate::base::PhyType; use crate::vector::Vector; use crate::world::WorldContext; use std::cmp::max; pub trait Brake { fn apply_brake(&self, context: &WorldContext, mut speed: Vector) -> Vector { let brake_decel = self.get_brake_deceleration(speed); let speed_dec = brake_decel * context.period_sec(); let new_speed = max(speed.length() - speed_dec, 0.into()); speed.set_length(new_speed); speed } fn get_brake_deceleration(&self, speed: Vector) -> PhyType; } // vim: ts=4 sw=4 expandtab