use cgmath::InnerSpace;
use crate::*;
#[derive(Debug, Clone)]
pub struct RenderResolution {
pub linear: Scalar,
}
impl RenderResolution {
pub fn new(linear: Scalar) -> Self {
Self { linear }
}
pub fn coarse() -> Self {
Self { linear: 1.0 }
}
}
impl std::ops::Mul<Mat3> for RenderResolution {
type Output = RenderResolution;
fn mul(self, rhs: Mat3) -> Self::Output {
let scale = (rhs.x.magnitude() * rhs.y.magnitude()).sqrt();
Self {
linear: self.linear / scale,
}
}
}
impl std::ops::Mul<Mat4> for RenderResolution {
type Output = RenderResolution;
fn mul(self, rhs: Mat4) -> Self::Output {
let scale = (rhs.x.magnitude() * rhs.y.magnitude() * rhs.z.magnitude()).powf(1.0 / 3.0);
Self {
linear: self.linear / scale,
}
}
}
impl Default for RenderResolution {
fn default() -> Self {
RenderResolution { linear: 0.1 }
}
}
impl std::fmt::Display for RenderResolution {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "@{}mm", self.linear)
}
}