microcad_lang/model/
operation.rs1use crate::{model::*, render::*};
7use microcad_core::*;
8
9pub trait Operation {
11 fn output_type(&self) -> OutputType {
15 OutputType::NotDetermined
16 }
17
18 fn process_2d(&self, _context: &mut RenderContext) -> RenderResult<Geometry2DOutput> {
20 unimplemented!()
21 }
22
23 fn process_3d(&self, _context: &mut RenderContext) -> RenderResult<Geometry3DOutput> {
25 unimplemented!()
26 }
27}
28
29#[derive(Clone, Debug)]
31pub enum AffineTransform {
32 Translation(Vec3),
34 Rotation(Mat3),
36 Scale(Vec3),
38 UniformScale(Scalar),
40}
41
42impl AffineTransform {
43 pub fn mat2d(&self) -> Mat3 {
45 match self {
46 AffineTransform::Translation(v) => Mat3::from_translation(Vec2::new(v.x, v.y)),
47 AffineTransform::Rotation(m) => Mat3::from_cols(
48 Vec3::new(m.x.x, m.x.y, 0.0),
49 Vec3::new(m.y.x, m.y.y, 0.0),
50 Vec3::new(0.0, 0.0, 1.0),
51 ),
52 AffineTransform::Scale(v) => Mat3::from_nonuniform_scale(v.x, v.y),
53 AffineTransform::UniformScale(s) => Mat3::from_scale(*s),
54 }
55 }
56
57 pub fn mat3d(&self) -> Mat4 {
59 match self {
60 AffineTransform::Translation(v) => Mat4::from_translation(*v),
61 AffineTransform::Rotation(a) => Mat4::from_cols(
62 a.x.extend(0.0),
63 a.y.extend(0.0),
64 a.z.extend(0.0),
65 Vec3::new(0.0, 0.0, 0.0).extend(1.0),
66 ),
67 AffineTransform::Scale(v) => Mat4::from_nonuniform_scale(v.x, v.y, v.z),
68 AffineTransform::UniformScale(s) => Mat4::from_scale(*s),
69 }
70 }
71}