pub struct PenaltyMap { /* private fields */ }Expand description
Penalty-map metric – base distance plus per-cell penalty difference.
Cost = base_metric.delta_cost(from, to) + |penalty[from] - penalty[to]|.
The penalty map is a 2D array (row-major, height x width) of integer
penalties. This is useful for modeling terrain height, road quality, etc.
Mirrors Agents.jl PenaltyMap.
§Example
use rustsim_pathfinding::metrics::{PenaltyMap, DirectDistance};
// 5x5 grid with a hill in the center
let mut penalties = vec![0i32; 25];
penalties[2 * 5 + 2] = 100; // cell (2,2) is expensive
let metric = PenaltyMap::new(penalties, 5, 5, DirectDistance::new()).unwrap();Implementations§
Source§impl PenaltyMap
impl PenaltyMap
Sourcepub fn new(
penalties: Vec<i32>,
width: usize,
height: usize,
base: impl CostMetric + 'static,
) -> Result<Self, PenaltyMapError>
pub fn new( penalties: Vec<i32>, width: usize, height: usize, base: impl CostMetric + 'static, ) -> Result<Self, PenaltyMapError>
Create a penalty map metric.
Sourcepub fn penalties_mut(&mut self) -> &mut [i32]
pub fn penalties_mut(&mut self) -> &mut [i32]
Mutable access to the penalty values (e.g. for dynamic terrain).
Sourcepub fn penalty_at(&self, x: usize, y: usize) -> i32
pub fn penalty_at(&self, x: usize, y: usize) -> i32
Get the penalty at a grid cell.
Trait Implementations§
Source§impl CostMetric for PenaltyMap
impl CostMetric for PenaltyMap
Auto Trait Implementations§
impl Freeze for PenaltyMap
impl !RefUnwindSafe for PenaltyMap
impl !Send for PenaltyMap
impl !Sync for PenaltyMap
impl Unpin for PenaltyMap
impl UnsafeUnpin for PenaltyMap
impl !UnwindSafe for PenaltyMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more