Struct quantized_density_fields::lod::LOD
source · pub struct LOD<S>where
S: State,{ /* private fields */ }
Expand description
Object that represents space level of details. This gives you the ability to sample space area states at different zoom levels (LOD mechanism).
Implementations
sourceimpl<S> LOD<S>where
S: State,
impl<S> LOD<S>where
S: State,
sourcepub fn new(dimensions: usize, count: usize, root_state: S) -> Self
pub fn new(dimensions: usize, count: usize, root_state: S) -> Self
Creates new LOD information universe.
Arguments
dimensions
- Number of dimensions which space contains.count
- Number of levels.root_state
- State of root level.
Examples
use quantized_density_fields::LOD;
// Create 2D space with 1 level of details and `16` as root space.
let lod = LOD::new(2, 1, 16);
assert_eq!(*lod.state(), 16);
// LOD has 4 children level objects.
assert_eq!(lod.level(lod.root()).sublevels().len(), 4);
// sampled state at level 1 equals to `4` (`16 / 4`).
assert_eq!(*lod.level(lod.level(lod.root()).sublevels()[0]).state(), 4);
sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Gets LOD dimensions number.
Examples
use quantized_density_fields::LOD;
let lod = LOD::new(2, 1, 16);
assert_eq!(lod.dimensions(), 2);
sourcepub fn levels_count(&self) -> usize
pub fn levels_count(&self) -> usize
Gets LOD zoom levels number.
Examples
use quantized_density_fields::LOD;
let lod = LOD::new(2, 1, 16);
assert_eq!(lod.levels_count(), 1);
sourcepub fn state(&self) -> &S
pub fn state(&self) -> &S
Gets LOD root level state.
Examples
use quantized_density_fields::LOD;
let lod = LOD::new(2, 1, 16);
assert_eq!(*lod.state(), 16);
sourcepub fn level_exists(&self, id: ID) -> bool
pub fn level_exists(&self, id: ID) -> bool
sourcepub fn try_get_level(&self, id: ID) -> Option<&Level<S>>
pub fn try_get_level(&self, id: ID) -> Option<&Level<S>>
sourcepub fn try_set_level_state(&mut self, id: ID, state: S) -> bool
pub fn try_set_level_state(&mut self, id: ID, state: S) -> bool
sourcepub fn set_level_state(&mut self, id: ID, state: S) -> Result<()>
pub fn set_level_state(&mut self, id: ID, state: S) -> Result<()>
sourcepub fn find_level_neighbors(&self, id: ID) -> Result<Vec<ID>>
pub fn find_level_neighbors(&self, id: ID) -> Result<Vec<ID>>
Gets list of space level neighbors IDs or throws error if level does not exists.
Arguments
id
- Level id.
Examples
use quantized_density_fields::LOD;
let lod = LOD::new(2, 1, 16);
let subs = lod.level(lod.root()).sublevels();
assert_eq!(lod.find_level_neighbors(subs[0]).unwrap(), vec![subs[1], subs[2], subs[3]]);
sourcepub fn find_path(&self, from: ID, to: ID) -> Result<Vec<ID>>
pub fn find_path(&self, from: ID, to: ID) -> Result<Vec<ID>>
Gets list of space level IDs that defines shortest path between two space levels, or throws error if level does not exists. Levels must lay on the same zoom level!
Arguments
from
- source level id.to
- target level id.
Examples
use quantized_density_fields::LOD;
let lod = LOD::new(2, 1, 16);
let subs = lod.level(lod.root()).sublevels();
assert_eq!(lod.find_path(subs[1], subs[3]).unwrap(), vec![subs[1], subs[0], subs[3]]);
sourcepub fn simulation_step<M>(&mut self)where
M: Simulate<S>,
pub fn simulation_step<M>(&mut self)where
M: Simulate<S>,
Performs simulation step (go through all platonic spaces and modifies its states based on
neighbor states). Actual state simulation is performed by your struct that implements
Simulation
trait.
sourcepub fn simulation_step_parallel<M>(&mut self)where
M: Simulate<S>,
pub fn simulation_step_parallel<M>(&mut self)where
M: Simulate<S>,
Does the same as simulation_step()
but in parallel manner (it may or may not increase
simulation performance if simulation is very complex).
sourcepub fn simulate_states<M>(&self) -> Vec<(ID, S)>where
M: Simulate<S>,
pub fn simulate_states<M>(&self) -> Vec<(ID, S)>where
M: Simulate<S>,
Performs simulation on LOD like simulation_step()
but instead of applying results to LOD,
it returns simulated platonic level states along with their level ID.
sourcepub fn simulate_states_parallel<M>(&self) -> Vec<(ID, S)>where
M: Simulate<S>,
pub fn simulate_states_parallel<M>(&self) -> Vec<(ID, S)>where
M: Simulate<S>,
Performs simulation on LOD like simulation_step_parallel()
but instead of applying
results to LOD, it returns simulated platonic level states along with their level ID.