Struct quantized_density_fields::qdf::QDF
source · pub struct QDF<S>where
S: State,{ /* private fields */ }Expand description
Object that represents quantized density fields.
Concept
QDF does not exists in any space - it IS the space, it defines it, it describes it so there are no space coordinates and it is your responsibility to deliver it. In future releases this crate will have module for projecting QDF into Euclidean space and will have a satelite crate to easlyy traverse and visualize space.
To sample specified region you have to know some space ID and gather the rest of information based on it neighbors spaces. It gives the ability to cotrol space density at specified locations, which can be used for example to simulate space curvature based on gravity.
Implementations§
source§impl<S> QDF<S>where
S: State,
impl<S> QDF<S>where
S: State,
sourcepub fn new(dimensions: usize, root_state: S) -> (Self, ID)
pub fn new(dimensions: usize, root_state: S) -> (Self, ID)
Creates new QDF information universe along with root space ID.
Arguments
dimensions- Number of dimensions which space contains.root_state- State of root space.
Examples
use quantized_density_fields::QDF;
// Creates 2d space with `16` as root state.
let (qdf, root) = QDF::new(2, 9);
assert_eq!(*qdf.space(root).state(), 9);sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Gets QDF dimensions number.
Examples
use quantized_density_fields::QDF;
let (qdf, _) = QDF::new(2, 9);
assert_eq!(qdf.dimensions(), 2);sourcepub fn space_exists(&self, id: ID) -> bool
pub fn space_exists(&self, id: ID) -> bool
sourcepub fn spaces(&self) -> Iter<'_, ID>
pub fn spaces(&self) -> Iter<'_, ID>
Gets iterator over all spaces IDs.
Examples
use quantized_density_fields::{QDF, ID};
let (mut qdf, root) = QDF::new(2, 9);
assert_eq!(qdf.spaces().count(), 1);
assert_eq!(*qdf.spaces().nth(0).unwrap(), root);
let mut subs = qdf.increase_space_density(root).unwrap();
subs.sort();
assert_eq!(qdf.spaces().count(), 3);
let mut spaces = qdf.spaces().cloned().collect::<Vec<ID>>();
spaces.sort();
assert_eq!(spaces, subs);sourcepub fn try_get_space(&self, id: ID) -> Option<&Space<S>>
pub fn try_get_space(&self, id: ID) -> Option<&Space<S>>
sourcepub fn try_set_space_state(&mut self, id: ID, state: S) -> bool
pub fn try_set_space_state(&mut self, id: ID, state: S) -> bool
sourcepub fn set_space_state(&mut self, id: ID, state: S) -> Result<()>
pub fn set_space_state(&mut self, id: ID, state: S) -> Result<()>
sourcepub fn find_space_neighbors(&self, id: ID) -> Result<Vec<ID>>
pub fn find_space_neighbors(&self, id: ID) -> Result<Vec<ID>>
Get list of IDs of given space neighbors or throws error if space does not exists.
Arguments
id- space id.
Examples
use quantized_density_fields::QDF;
let (mut qdf, root) = QDF::new(2, 9);
let subs = qdf.increase_space_density(root).unwrap();
assert_eq!(qdf.find_space_neighbors(subs[0]).unwrap(), vec![subs[1], subs[2]]);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 IDs that defines shortest path between two spaces, or throws error if space does not exists.
Arguments
from- source space id.to- target space id.
Examples
use quantized_density_fields::QDF;
let (mut qdf, root) = QDF::new(2, 9);
let subs = qdf.increase_space_density(root).unwrap();
let subs2 = qdf.increase_space_density(subs[0]).unwrap();
assert_eq!(qdf.find_path(subs2[0], subs[2]).unwrap(), vec![subs2[0], subs2[1], subs[2]]);sourcepub fn increase_space_density(&mut self, id: ID) -> Result<Vec<ID>>
pub fn increase_space_density(&mut self, id: ID) -> Result<Vec<ID>>
Increases given space density (subdivide space and rebind it properly to its neighbors), or throws error if space does not exists.
Arguments
id- space id.
Examples
use quantized_density_fields::QDF;
let (mut qdf, root) = QDF::new(2, 9);
let subs = qdf.increase_space_density(root).unwrap();
assert_eq!(subs.len(), 3);sourcepub fn decrease_space_density(&mut self, id: ID) -> Result<Option<ID>>
pub fn decrease_space_density(&mut self, id: ID) -> Result<Option<ID>>
Decreases given space density (merge space children and rebind them properly to theirs neighbors if space has 1 level of subdivision, otherwise perform this operation on its subspaces), or throws error if space does not exists.
Arguments
id- space id.
Examples
use quantized_density_fields::QDF;
let (mut qdf, root) = QDF::new(2, 9);
let subs = qdf.increase_space_density(root).unwrap();
assert_eq!(subs.len(), 3);
let root = qdf.decrease_space_density(subs[0]).unwrap().unwrap();
assert_eq!(qdf.spaces().len(), 1);
assert_eq!(*qdf.spaces().nth(0).unwrap(), root);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 QDF like simulation_step() but instead of applying results to QDF,
it returns simulated platonic space states along with their space 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 QDF like simulation_step_parallel() but instead of applying
results to QDF, it returns simulated platonic space states along with their space ID.