spirv: migrate Material trait to types, and parameterize by R

This commit is contained in:
2022-07-18 14:33:09 -07:00
parent 35251f5a7f
commit 7d2a3baadc
7 changed files with 38 additions and 34 deletions

View File

@@ -1,30 +1,19 @@
use crate::support::Optional;
use coremem_types::mat::Material;
use coremem_types::vec::Vec3;
pub trait Material: Sized {
fn conductivity(&self) -> Vec3<f32> {
Default::default()
}
/// returns the new M vector for this material
fn move_b_vec(&self, m: Vec3<f32>, _target_b: Vec3<f32>) -> Vec3<f32> {
// XXX could return either 0, or `m`. they should be the same, but one might be more
// optimizable than the other (untested).
m
}
}
#[derive(Copy, Clone, Default, PartialEq)]
pub struct Conductor<T>(pub T);
pub type AnisomorphicConductor = Conductor<Vec3<f32>>;
pub type IsomorphicConductor = Conductor<f32>;
impl Material for AnisomorphicConductor {
impl Material<f32> for AnisomorphicConductor {
fn conductivity(&self) -> Vec3<f32> {
self.0
}
}
impl Material for IsomorphicConductor {
impl Material<f32> for IsomorphicConductor {
fn conductivity(&self) -> Vec3<f32> {
Vec3::uniform(self.0)
}
@@ -79,7 +68,7 @@ impl MBPgram {
}
}
impl Material for MBPgram {
impl Material<f32> for MBPgram {
fn move_b_vec(&self, m: Vec3<f32>, target_b: Vec3<f32>) -> Vec3<f32> {
Vec3::new(
self.move_b(m.x(), target_b.x()),
@@ -167,7 +156,7 @@ impl MHPgram {
}
}
impl Material for MHPgram {
impl Material<f32> for MHPgram {
fn move_b_vec(&self, m: Vec3<f32>, target_b: Vec3<f32>) -> Vec3<f32> {
Vec3::new(
self.move_b(m.x(), target_b.x()),
@@ -184,7 +173,7 @@ pub struct FullyGenericMaterial {
pub m_h_curve: Optional<MHPgram>,
}
impl Material for FullyGenericMaterial {
impl Material<f32> for FullyGenericMaterial {
fn conductivity(&self) -> Vec3<f32> {
self.conductivity
}
@@ -210,7 +199,7 @@ impl Into<MHPgram> for Ferroxcube3R1MH {
}
}
impl Material for Ferroxcube3R1MH {
impl Material<f32> for Ferroxcube3R1MH {
fn move_b_vec(&self, m: Vec3<f32>, target_b: Vec3<f32>) -> Vec3<f32> {
let curve: MHPgram = (*self).into();
curve.move_b_vec(m, target_b)
@@ -241,7 +230,7 @@ impl<M: Default> IsoConductorOr<M> {
}
}
impl<M: Material + Copy> Material for IsoConductorOr<M> {
impl<M: Material<f32> + Copy> Material<f32> for IsoConductorOr<M> {
fn conductivity(&self) -> Vec3<f32> {
Vec3::uniform(self.value.max(0.0))
}