Skip to main content

PenaltyMap

Struct PenaltyMap 

Source
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

Source

pub fn new( penalties: Vec<i32>, width: usize, height: usize, base: impl CostMetric + 'static, ) -> Result<Self, PenaltyMapError>

Create a penalty map metric.

Source

pub fn penalties(&self) -> &[i32]

Read-only access to the penalty values.

Source

pub fn penalties_mut(&mut self) -> &mut [i32]

Mutable access to the penalty values (e.g. for dynamic terrain).

Source

pub fn penalty_at(&self, x: usize, y: usize) -> i32

Get the penalty at a grid cell.

Trait Implementations§

Source§

impl CostMetric for PenaltyMap

Source§

fn delta_cost( &self, from: (usize, usize), to: (usize, usize), periodic: bool, width: usize, height: usize, diagonal: bool, ) -> f64

Estimate the cost of traveling from from to to. Read more
Source§

impl Debug for PenaltyMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V