coremem_types: IsomorphicConductor, AnisomorphicConductor are now used by both spirv and cpu impls

This commit is contained in:
2022-07-19 02:08:22 -07:00
parent 78f7e2be45
commit f8fccd957a
10 changed files with 215 additions and 148 deletions

View File

@@ -25,41 +25,5 @@ impl Material<f32> for FullyGenericMaterial {
}
}
/// Optimized material aimed at saving space for the common case of a simulation that contains
/// isomorphic conductors plus one exception material.
#[derive(Copy, Clone, Default, PartialEq)]
pub struct IsoConductorOr<M> {
/// conductivity, if >= 0, else ignored & used to signal the other material
pub value: f32,
pub mat: M,
}
impl<M: Default> IsoConductorOr<M> {
pub fn new_conductor(conductivity: f32) -> Self {
Self {
value: conductivity,
mat: Default::default(),
}
}
pub fn new_other() -> Self {
Self {
value: -1.0,
mat: Default::default()
}
}
}
impl<M: Material<f32> + Copy> Material<f32> for IsoConductorOr<M> {
fn conductivity(&self) -> Vec3<f32> {
Vec3::uniform(self.value.max(0.0))
}
fn move_b_vec(&self, m: Vec3<f32>, target_b: Vec3<f32>) -> Vec3<f32> {
if self.value < 0.0 {
let mat = self.mat; //< XXX hack for ZST
mat.move_b_vec(m, target_b)
} else {
m
}
}
}
pub type IsoConductorOr<M> = coremem_types::mat::IsoConductorOr<f32, M>;