Skip to content

Commit

Permalink
Use Polyanya for path finding
Browse files Browse the repository at this point in the history
  • Loading branch information
Indy2222 committed Oct 5, 2023
1 parent ab3ba9b commit 7befb3e
Show file tree
Hide file tree
Showing 10 changed files with 1,208 additions and 741 deletions.
35 changes: 1 addition & 34 deletions crates/pathing/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use std::rc::Rc;
use de_types::path::Path;
use parry2d::math::Point;

use crate::geometry::{which_side, Side};

/// A linked list of points which keeps track of its length in meters.
#[derive(Clone)]
pub(crate) struct PointChain {
prev: Option<Rc<Self>>,
point: Point<f32>,
Expand Down Expand Up @@ -58,26 +57,6 @@ impl PointChain {
self.length
}

/// Returns true if the point has no predecessor.
pub(crate) fn is_first(&self) -> bool {
self.prev.is_none()
}

/// Returns relative side of a point to `self` from the perspective of the
/// parent point. Returns `None` if `self` has no parent.
///
/// See [`crate::geometry::which_side`].
///
/// # Panics
///
/// May panic if self is a degenerate point chain or of `point` coincides
/// with last but one point in self.
pub(crate) fn which_side(&self, point: Point<f32>) -> Option<Side> {
self.prev
.as_ref()
.map(|p| which_side(p.point(), self.point, point))
}

/// Returns an iterator over points in this linked list. The iterator
/// starts at `self` and traverses all predecessors.
pub(crate) fn iter(&self) -> Predecessors {
Expand Down Expand Up @@ -123,31 +102,19 @@ mod tests {
fn test_chain() {
let chain = PointChain::first(Point::new(1., 2.));
assert!(chain.prev().is_none());
assert!(chain.is_first());
assert_eq!(chain.point(), Point::new(1., 2.));
assert_eq!(chain.length(), 0.);
let collected: Vec<Point<f32>> = chain.iter().map(|p| p.point()).collect();
assert_eq!(collected, vec![Point::new(1., 2.)]);

let chain = PointChain::extended(&Rc::new(chain), Point::new(3., 2.));
assert!(chain.prev().is_some());
assert!(!chain.is_first());
assert_eq!(chain.point(), Point::new(3., 2.));
assert_eq!(chain.length(), 2.);
let collected: Vec<Point<f32>> = chain.iter().map(|p| p.point()).collect();
assert_eq!(collected, vec![Point::new(3., 2.), Point::new(1., 2.)]);
}

#[test]
fn test_which_side() {
let chain = PointChain::first(Point::new(1., 2.));
assert!(chain.which_side(Point::new(2., 1.)).is_none());

let chain = PointChain::extended(&Rc::new(chain), Point::new(3., 2.));
assert_eq!(chain.which_side(Point::new(2., 1.)).unwrap(), Side::Left);
assert_eq!(chain.which_side(Point::new(2., 3.)).unwrap(), Side::Right);
}

#[test]
fn test_to_path() {
let chain = PointChain::extended(
Expand Down
270 changes: 0 additions & 270 deletions crates/pathing/src/dijkstra.rs

This file was deleted.

Loading

0 comments on commit 7befb3e

Please sign in to comment.