diff --git a/examples/collision_avoid.rs b/examples/collision_avoid.rs index c1c6275..424921a 100644 --- a/examples/collision_avoid.rs +++ b/examples/collision_avoid.rs @@ -30,6 +30,7 @@ use ncollide::ncollide_geometry::query::Proximity; use rand::distributions::{IndependentSample, Range}; +use rrt::Trajectory; struct CollisionProblem { obstacle: Cuboid>, @@ -99,10 +100,10 @@ fn main() { cs.set_local_transformation(poss); cg.set_local_transformation(posg); - let mut path = vec![]; + let mut path = Trajectory{waypoints: vec![]}; let mut index = 0; while window.render() { - if index == path.len() { + if index == path.waypoints.len() { path = rrt::dual_rrt_connect( &start, &goal, @@ -111,10 +112,10 @@ fn main() { 0.05, 1000, ).unwrap(); - rrt::smooth_path(&mut path, |x: &[f64]| p.is_feasible(x), 0.05, 100); + rrt::smooth_path(&mut path.waypoints, |x: &[f64]| p.is_feasible(x), 0.05, 100); index = 0; } - let point = &path[index % path.len()]; + let point = &path.waypoints[index % path.waypoints.len()]; let pos = Isometry3::new( Vector3::new(point[0] as f32, point[1] as f32, point[2] as f32), na::zero(), diff --git a/src/lib.rs b/src/lib.rs index 8ca044f..5136055 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,8 +39,8 @@ //! 0.2, //! 1000) //! .unwrap(); -//! println!("{:?}", result); -//! assert!(result.len() >= 4); +//! println!("{:?}", result.waypoints); +//! assert!(result.waypoints.len() >= 4); //! } //! ``` extern crate kdtree; @@ -52,6 +52,10 @@ use kdtree::distance::squared_euclidean; use std::mem; use rand::distributions::{IndependentSample, Range}; +pub struct Trajectory { + pub waypoints: Vec>, +} + pub enum ExtendStatus { Reached(usize), Advanced(usize), @@ -180,7 +184,7 @@ pub fn dual_rrt_connect( random_sample: FR, extend_length: f64, num_max_try: usize, -) -> Result>, String> +) -> Result where FF: FnMut(&[f64]) -> bool, FR: Fn() -> Vec, @@ -209,7 +213,7 @@ where if tree_b.name == "start" { a_all.reverse(); } - return Ok(a_all); + return Ok(Trajectory{waypoints: a_all}); } } } @@ -288,14 +292,14 @@ fn it_works() { 0.2, 1000, ).unwrap(); - println!("{:?}", result); - assert!(result.len() >= 4); + println!("{:?}", result.waypoints); + assert!(result.waypoints.len() >= 4); smooth_path( - &mut result, + &mut result.waypoints, |p: &[f64]| !(p[0].abs() < 1.0 && p[1].abs() < 1.0), 0.2, 100, ); - println!("{:?}", result); - assert!(result.len() >= 3); + println!("{:?}", result.waypoints); + assert!(result.waypoints.len() >= 3); }