1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: Apache-2.0
//! Canonical units and tolerances.
//!
//! Stored lengths and coordinates use millimeters. Angular quantities use
//! radians.
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// The canonical IR length unit.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum LengthUnit {
/// Millimeter, the IR canonical length unit.
Millimeter,
}
impl LengthUnit {
/// Scale factor to convert a length in `self` to millimeters.
pub fn to_millimeters(self) -> f64 {
1.0
}
}
/// Unit declaration for stored document coordinates.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct Units {
/// Unit the stored coordinate values are expressed in.
pub length: LengthUnit,
}
impl Default for Units {
fn default() -> Self {
Units {
length: LengthUnit::Millimeter,
}
}
}
/// Document-wide linear and angular tolerances.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct Tolerances {
/// Linear tolerance in millimeters.
pub linear: f64,
/// Angular tolerance in radians.
pub angular: f64,
}
impl Default for Tolerances {
fn default() -> Self {
Tolerances {
linear: 1e-6,
angular: 1e-10,
}
}
}