microcad_core/
render_resolution.rs1use cgmath::InnerSpace;
7
8use crate::*;
9
10#[derive(Debug, Clone)]
12pub struct RenderResolution {
13 pub linear: Scalar,
15}
16
17impl RenderResolution {
18 pub fn new(linear: Scalar) -> Self {
20 Self { linear }
21 }
22
23 pub fn coarse() -> Self {
25 Self { linear: 1.0 }
26 }
27}
28
29impl std::ops::Mul<Mat3> for RenderResolution {
30 type Output = RenderResolution;
31
32 fn mul(self, rhs: Mat3) -> Self::Output {
33 let scale = (rhs.x.magnitude() * rhs.y.magnitude()).sqrt();
34 Self {
35 linear: self.linear / scale,
36 }
37 }
38}
39
40impl std::ops::Mul<Mat4> for RenderResolution {
41 type Output = RenderResolution;
42
43 fn mul(self, rhs: Mat4) -> Self::Output {
44 let scale = (rhs.x.magnitude() * rhs.y.magnitude() * rhs.z.magnitude()).powf(1.0 / 3.0);
45 Self {
46 linear: self.linear / scale,
47 }
48 }
49}
50
51impl Default for RenderResolution {
52 fn default() -> Self {
53 RenderResolution { linear: 0.1 }
54 }
55}
56
57impl std::fmt::Display for RenderResolution {
58 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 write!(f, "@{}mm", self.linear)
60 }
61}