pub struct QDF<S>where
    S: State,
{ /* private fields */ }
Expand description

Object that represents quantized density fields.

Concept

MOST IMPORTANT NODE: QDF does not exists in any space - it IS the space, it describes it, so there are no space coordinates. To sample specified region you have to know some space and gather the rest of information based on it neighbors. 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§

Creates new QDF information universe.

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 = QDF::new(2, 9);
assert_eq!(*qdf.state(), 9);

Gets QDF id.

Gets QDF root space node id.

Gets QDF dimensions number.

Examples
use quantized_density_fields::QDF;

let qdf = QDF::new(2, 9);
assert_eq!(qdf.dimensions(), 2);

Gets QDF dimensions number.

Examples
use quantized_density_fields::QDF;

let qdf = QDF::new(2, 9);
assert_eq!(*qdf.state(), 9);

Tells if space with given id exists in QDF.

Arguments
  • id - space id.
Examples
use quantized_density_fields::QDF;

let qdf = QDF::new(2, 9);
assert!(qdf.space_exists(qdf.root()));

Try to get given space.

Arguments
  • id - space id.
Examples
use quantized_density_fields::QDF;

let qdf = QDF::new(2, 9);
if let Some(space) = qdf.try_get_space(qdf.root()) {
    assert_eq!(*space.state(), 9);
}

Get given space or throw error if space does not exists.

Arguments
  • id - space id.
Examples
use quantized_density_fields::QDF;

let qdf = QDF::new(2, 9);
if let Ok(space) = qdf.get_space(qdf.root()) {
    assert_eq!(*space.state(), 9);
}

Get given space or panic if space does not exists.

Arguments
  • id - space id.
Examples
use quantized_density_fields::QDF;

let qdf = QDF::new(2, 9);
assert_eq!(*qdf.space(qdf.root()).state(), 9);

Try to set given space state.

Arguments
  • id - space id.
  • state - state.
Examples
use quantized_density_fields::QDF;

let mut qdf = QDF::new(2, 9);
let id = qdf.root();
assert!(qdf.try_set_space_state(id, 3));

Set given space state or throw error if space does not exists.

Arguments
  • id - space id.
  • state - state.
Examples
use quantized_density_fields::QDF;

let mut qdf = QDF::new(2, 9);
let id = qdf.root();
assert!(qdf.set_space_state(id, 3).is_ok());

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 = QDF::new(2, 9);
let id = qdf.root();
qdf.increase_space_density(id);
let subs = qdf.space(qdf.root()).subspace();
assert_eq!(qdf.find_space_neighbors(subs[0]).unwrap(), vec![subs[1], subs[2]]);

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 = QDF::new(2, 9);
let id = qdf.root();
qdf.increase_space_density(id);
let subs = qdf.space(qdf.root()).subspace().to_vec();
qdf.increase_space_density(subs[0]);
let subs2 = qdf.space(subs[0]).subspace();
assert_eq!(qdf.find_path(subs2[0], subs[2]).unwrap(), vec![subs2[0], subs2[1], subs[2]]);

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 = QDF::new(2, 9);
let id = qdf.root();
qdf.increase_space_density(id);
assert_eq!(qdf.space(qdf.root()).subspace().len(), 3);

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 = QDF::new(2, 9);
let id = qdf.root();
qdf.increase_space_density(id);
assert_eq!(qdf.space(qdf.root()).subspace().len(), 3);
qdf.decrease_space_density(id);
assert!(qdf.space(qdf.root()).is_platonic());

Decreases given space density (merge space children and rebind them properly to theirs neighbors), or throws error if space does not exists. Basically it works like Self::decrease_space_density() but merges space to make it completely platonic.

Arguments
  • id - space id.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.