mod params;
pub mod obstacles_2d_f32;
pub mod obstacles_2d_f64;
pub mod obstacles_3d_f32;
pub mod obstacles_3d_f64;
use nalgebra::storage::Storage;
use nalgebra::{Const, Vector};
use serde::{Deserialize, Serialize};
use crate::cspace::CSpace;
use crate::params::FromParams;
use crate::trajectories::FullTrajectory;
pub type ObstacleId = usize;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum Behavior {
Static,
Appearing,
}
impl Default for Behavior {
fn default() -> Behavior {
Behavior::Static
}
}
pub trait ObstacleSpace<X, CS, const N: usize>:
FromParams + Clone + Obstacle<X, CS, N>
where
CS: CSpace<X, N>,
{
type Obs: AppearingObstacle<X, CS, N>;
fn empty() -> Self;
fn new(obstacles: Vec<Self::Obs>) -> Self {
let mut new_ = Self::empty();
new_.add_obstacles(obstacles.into_iter().enumerate());
new_
}
fn add_obstacle(&mut self, id: ObstacleId, obstacle: Self::Obs) {
self.add_obstacles(vec![(id, obstacle)])
}
fn add_obstacles<I>(&mut self, obstacles: I)
where
I: IntoIterator<Item = (ObstacleId, Self::Obs)>;
fn get_obstacle(&self, id: ObstacleId) -> Option<&Self::Obs> {
self.get_obstacles(&[id; 1]).into_iter().next()
}
fn get_obstacles(&self, obstacles: &[ObstacleId]) -> Vec<&Self::Obs>;
fn get_obstacles_as_obstacle_space(&self, obstacles: &[ObstacleId]) -> Self {
Self::new(self.get_obstacles(obstacles).into_iter().cloned().collect())
}
fn get_sensed_obstacles(&self) -> Vec<(ObstacleId, &Self::Obs)>;
fn get_not_sensed_obstacles(&self) -> Vec<(ObstacleId, &Self::Obs)>;
fn get_all_obstacle_ids(&self) -> Vec<ObstacleId>;
fn get_all_obstacles(&self) -> Vec<(ObstacleId, &Self::Obs)> {
self
.get_all_obstacle_ids()
.into_iter()
.filter_map(|obs_id| self.get_obstacle(obs_id).map(|obs| (obs_id, obs)))
.collect()
}
fn remove_obstacle(&mut self, id: ObstacleId) {
self.remove_obstacles(&[id; 1])
}
fn remove_obstacles(&mut self, obstacles: &[ObstacleId]);
fn count(&self) -> usize;
fn check_sensors<S>(
&mut self,
pose: &Vector<X, Const<N>, S>,
radius: X,
) -> Vec<ObstacleId>
where
S: Storage<X, Const<N>>;
}
pub trait Obstacle<X, CS, const N: usize>: FromParams + Clone
where
CS: CSpace<X, N>,
{
fn trajectory_free<FT, S1, S2>(&self, t: &FT) -> bool
where
FT: FullTrajectory<X, CS::Traj, S1, S2, N>,
S1: Storage<X, Const<N>>,
S2: Storage<X, Const<N>>;
fn is_free<S>(&self, x: &Vector<X, Const<N>, S>) -> bool
where
S: Storage<X, Const<N>>;
}
pub trait AppearingObstacle<X, CS, const N: usize>: Obstacle<X, CS, N>
where
CS: CSpace<X, N>,
{
fn can_sense<S>(&self, pose: &Vector<X, Const<N>, S>, radius: X) -> bool
where
S: Storage<X, Const<N>>;
}