Struct 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§

Source§

impl<S> LOD<S>
where S: State,

Source

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);
Source

pub fn id(&self) -> ID

Gets LOD id.

Source

pub fn root(&self) -> ID

Gets LOD root level node id.

Source

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);
Source

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);
Source

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);
Source

pub fn level_exists(&self, id: ID) -> bool

Tells if space level with given id exists in LOD.

§Arguments
  • id - level id.
§Examples
use quantized_density_fields::LOD;

let lod = LOD::new(2, 1, 16);
assert!(lod.level_exists(lod.root()));
Source

pub fn try_get_level(&self, id: ID) -> Option<&Level<S>>

Try to get reference to given space level.

§Arguments
  • id - level id.
§Examples
use quantized_density_fields::LOD;

let lod = LOD::new(2, 1, 16);
if let Some(level) = lod.try_get_level(lod.root()) {
    assert_eq!(*level.state(), 16);
}
Source

pub fn get_level(&self, id: ID) -> Result<&Level<S>>

Gets reference to given space level and throws error if level does not exists.

§Arguments
  • id - level id.
§Examples
use quantized_density_fields::LOD;

let lod = LOD::new(2, 1, 16);
if let Ok(level) = lod.get_level(lod.root()) {
    assert_eq!(*level.state(), 16);
}
Source

pub fn level(&self, id: ID) -> &Level<S>

Gets reference to given space level and panics if level does not exists.

§Arguments
  • id - level id.
§Examples
use quantized_density_fields::LOD;

let lod = LOD::new(2, 1, 16);
assert_eq!(*lod.level(lod.root()).state(), 16);
Source

pub fn try_set_level_state(&mut self, id: ID, state: S) -> bool

Try to set given level state.

§Arguments
  • id - level id.
  • state - state.
§Examples
use quantized_density_fields::LOD;

let mut lod = LOD::new(2, 1, 9);
let id = lod.root();
assert!(lod.try_set_level_state(id, 3));
Source

pub fn set_level_state(&mut self, id: ID, state: S) -> Result<()>

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

§Arguments
  • id - level id.
  • state - state.
§Examples
use quantized_density_fields::LOD;

let mut lod = LOD::new(2, 1, 9);
let id = lod.root();
assert!(lod.set_level_state(id, 3).is_ok());
Source

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]]);
Source

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]]);
Source

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.

Source

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).

Source

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.

Source

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.

Trait Implementations§

Source§

impl<S> Debug for LOD<S>
where S: State + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for LOD<S>

§

impl<S> RefUnwindSafe for LOD<S>
where S: RefUnwindSafe,

§

impl<S> Send for LOD<S>

§

impl<S> Sync for LOD<S>

§

impl<S> Unpin for LOD<S>
where S: Unpin,

§

impl<S> UnwindSafe for LOD<S>
where S: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.