Another project
1use serde::{Deserialize, Serialize};
2
3use crate::{FeatureId, SketchEntityId};
4
5#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
6pub struct LoopIndex(u16);
7
8impl LoopIndex {
9 pub const OUTER: Self = Self(0);
10
11 #[must_use]
12 pub const fn new(value: u16) -> Self {
13 Self(value)
14 }
15
16 #[must_use]
17 pub const fn value(self) -> u16 {
18 self.0
19 }
20}
21
22impl core::fmt::Display for LoopIndex {
23 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
24 write!(f, "loop#{}", self.0)
25 }
26}
27
28#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
29pub struct ImportOrdinal(u32);
30
31impl ImportOrdinal {
32 #[must_use]
33 pub const fn new(value: u32) -> Self {
34 Self(value)
35 }
36
37 #[must_use]
38 pub const fn value(self) -> u32 {
39 self.0
40 }
41}
42
43impl core::fmt::Display for ImportOrdinal {
44 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
45 write!(f, "import#{}", self.0)
46 }
47}
48
49#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
50pub enum SideKind {
51 Corner,
52 Seam,
53}
54
55impl SideKind {
56 #[must_use]
57 pub const fn label(self) -> &'static str {
58 match self {
59 Self::Corner => "corner",
60 Self::Seam => "seam",
61 }
62 }
63}
64
65impl core::fmt::Display for SideKind {
66 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67 f.write_str(self.label())
68 }
69}
70
71#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
72#[serde(deny_unknown_fields)]
73pub enum FaceRole {
74 StartCap,
75 Side {
76 loop_index: LoopIndex,
77 from: SketchEntityId,
78 },
79 EndCap,
80 Imported {
81 ordinal: ImportOrdinal,
82 },
83}
84
85impl core::fmt::Display for FaceRole {
86 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
87 match self {
88 Self::StartCap => f.write_str("start_cap"),
89 Self::Side { loop_index, from } => write!(f, "side({loop_index}, from={from:?})"),
90 Self::EndCap => f.write_str("end_cap"),
91 Self::Imported { ordinal } => write!(f, "imported({ordinal})"),
92 }
93 }
94}
95
96#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
97#[serde(deny_unknown_fields)]
98pub enum EdgeRole {
99 StartCapEdge {
100 from: SketchEntityId,
101 },
102 SideEdge {
103 from: SketchEntityId,
104 side: SideKind,
105 },
106 EndCapEdge {
107 from: SketchEntityId,
108 },
109 Imported {
110 ordinal: ImportOrdinal,
111 },
112}
113
114impl core::fmt::Display for EdgeRole {
115 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
116 match self {
117 Self::StartCapEdge { from } => write!(f, "start_cap_edge(from={from:?})"),
118 Self::SideEdge { from, side } => write!(f, "side_edge({side}, from={from:?})"),
119 Self::EndCapEdge { from } => write!(f, "end_cap_edge(from={from:?})"),
120 Self::Imported { ordinal } => write!(f, "imported({ordinal})"),
121 }
122 }
123}
124
125#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
126#[serde(deny_unknown_fields)]
127pub enum VertexRole {
128 StartCapVertex {
129 from: SketchEntityId,
130 side: SideKind,
131 },
132 EndCapVertex {
133 from: SketchEntityId,
134 side: SideKind,
135 },
136 Imported {
137 ordinal: ImportOrdinal,
138 },
139}
140
141impl core::fmt::Display for VertexRole {
142 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
143 match self {
144 Self::StartCapVertex { from, side } => {
145 write!(f, "start_cap_vertex({side}, from={from:?})")
146 }
147 Self::EndCapVertex { from, side } => {
148 write!(f, "end_cap_vertex({side}, from={from:?})")
149 }
150 Self::Imported { ordinal } => write!(f, "imported({ordinal})"),
151 }
152 }
153}
154
155#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
156#[serde(deny_unknown_fields)]
157pub struct FaceLabel {
158 pub feature: FeatureId,
159 pub role: FaceRole,
160}
161
162impl core::fmt::Display for FaceLabel {
163 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
164 write!(f, "face[{:?}]:{}", self.feature, self.role)
165 }
166}
167
168#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
169#[serde(deny_unknown_fields)]
170pub struct EdgeLabel {
171 pub feature: FeatureId,
172 pub role: EdgeRole,
173}
174
175impl core::fmt::Display for EdgeLabel {
176 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
177 write!(f, "edge[{:?}]:{}", self.feature, self.role)
178 }
179}
180
181#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
182#[serde(deny_unknown_fields)]
183pub struct VertexLabel {
184 pub feature: FeatureId,
185 pub role: VertexRole,
186}
187
188impl core::fmt::Display for VertexLabel {
189 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
190 write!(f, "vertex[{:?}]:{}", self.feature, self.role)
191 }
192}