microcad_core/geo2d/
size.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::Scalar;
5
6/// 2D size in millimeters.  
7#[derive(Clone, Default, Debug)]
8pub struct Size2 {
9    /// Width in mm.
10    pub width: Scalar,
11    /// Height in mm.
12    pub height: Scalar,
13}
14
15impl Size2 {
16    /// A4 sheet.
17    pub const A4: Size2 = Size2 {
18        width: 210.0,
19        height: 297.0,
20    };
21
22    /// Calculate transposed version of this size.
23    pub fn transposed(self) -> Self {
24        Self {
25            width: self.height,
26            height: self.width,
27        }
28    }
29}
30
31impl std::fmt::Display for Size2 {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        write!(f, "Size2({} mm x {} mm)", self.width, self.height)
34    }
35}