use std::cell::RefCell;
use super::implementation::algorithm::Extractor;
use super::structs::*;
use super::{
density::*,
voxel_source::{VoxelSource, WorldMappingVoxelSource},
};
use crate::transition_sides::TransitionSides;
pub fn extract<D, S>(
source: S,
block: &Block<D::F>,
threshold: D,
transition_sides: TransitionSides,
) -> Mesh<D::F>
where
D: Density,
S: VoxelSource<D>,
{
Extractor::new(source, block, threshold, transition_sides).extract()
}
pub fn extract_from_field<D, FIELD>(
field: FIELD,
block: &Block<D::F>,
threshold: D,
transition_sides: TransitionSides,
) -> Mesh<D::F>
where
D: Density,
FIELD: ScalarField<D, D::F>, {
let mut source = WorldMappingVoxelSource { field, block };
Extractor::new(&mut source, block, threshold, transition_sides).extract()
}
pub fn extract_from_fn<D, FUN>(
f: FUN,
block: &Block<D::F>,
threshold: D,
transition_sides: TransitionSides,
) -> Mesh<D::F>
where
D: Density,
FUN: Fn(D::F, D::F, D::F) -> D,
{
let field = ScalarFieldForFn(f);
let mut source = WorldMappingVoxelSource { field, block };
Extractor::new(&mut source, block, threshold, transition_sides).extract()
}
pub fn extract_from_fnmut<D, FUN>(
f: FUN,
block: &Block<D::F>,
threshold: D,
transition_sides: TransitionSides,
) -> Mesh<D::F>
where
D: Density,
FUN: FnMut(D::F, D::F, D::F) -> D,
{
let field = ScalarFieldForFnMut(RefCell::new(f));
let mut source = WorldMappingVoxelSource { field, block };
Extractor::new(&mut source, block, threshold, transition_sides).extract()
}