microcad_lang/model/
output_type.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Export attribute.
5
6/// The output type of the [`crate::model::Model`].
7#[derive(Clone, Copy, Default, PartialEq)]
8pub enum OutputType {
9    /// The output type has not yet been determined.
10    #[default]
11    NotDetermined,
12    /// The [`crate::model::Model`] outputs a 2d geometry.
13    Geometry2D,
14    /// The [`crate::model::Model`] outputs a 3d geometry.
15    Geometry3D,
16    /// The [`crate::model::Model`] is invalid, you cannot mix 2d and 3d geometry.
17    InvalidMixed,
18}
19
20impl OutputType {
21    /// Merge this output type with another.
22    pub fn merge(&self, other: &Self) -> OutputType {
23        match (self, other) {
24            (OutputType::NotDetermined, output_type) => *output_type,
25            (OutputType::Geometry2D, OutputType::NotDetermined)
26            | (OutputType::Geometry2D, OutputType::Geometry2D)
27            | (OutputType::Geometry3D, OutputType::NotDetermined)
28            | (OutputType::Geometry3D, OutputType::Geometry3D) => *self,
29            (OutputType::Geometry2D, OutputType::Geometry3D)
30            | (OutputType::Geometry3D, OutputType::Geometry2D)
31            | (OutputType::Geometry2D, OutputType::InvalidMixed)
32            | (OutputType::Geometry3D, OutputType::InvalidMixed)
33            | (OutputType::InvalidMixed, _) => OutputType::InvalidMixed,
34        }
35    }
36}
37
38impl std::fmt::Debug for OutputType {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        write!(
41            f,
42            "{}",
43            match &self {
44                Self::NotDetermined => crate::invalid!(UNKNOWN),
45                Self::Geometry2D => "2D",
46                Self::Geometry3D => "3D",
47                Self::InvalidMixed => crate::invalid_no_ansi!(OUTPUT),
48            }
49        )
50    }
51}
52
53impl std::fmt::Display for OutputType {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        write!(
56            f,
57            "{}",
58            match &self {
59                Self::NotDetermined => "Undetermined",
60                Self::Geometry2D => "2D",
61                Self::Geometry3D => "3D",
62                Self::InvalidMixed => crate::invalid_no_ansi!(OUTPUT),
63            }
64        )
65    }
66}