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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use crate::{
builder::GlobalEdgeBuilder,
objects::{
Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects,
Surface, Vertex,
},
partial::{MaybePartial, MergeWith, PartialCurve, PartialVertex, Replace},
services::Service,
storage::Handle,
};
#[derive(Clone, Debug, Default)]
pub struct PartialHalfEdge {
pub vertices: [MaybePartial<Vertex>; 2],
pub global_form: MaybePartial<GlobalEdge>,
}
impl PartialHalfEdge {
pub fn curve(&self) -> MaybePartial<Curve> {
let [a, b] = &self.vertices;
a.curve().merge_with(b.curve())
}
pub fn build(self, objects: &mut Service<Objects>) -> HalfEdge {
let global_curve = self
.curve()
.global_form()
.merge_with(self.global_form.curve());
let curve = self
.curve()
.merge_with(PartialCurve {
global_form: global_curve,
..Default::default()
})
.into_full(objects);
let vertices = self.vertices.map(|vertex| {
vertex
.merge_with(PartialVertex {
curve: curve.clone().into(),
..Default::default()
})
.into_full(objects)
});
let global_form = self
.global_form
.update_partial(|partial| {
partial.update_from_curve_and_vertices(&curve, &vertices)
})
.into_full(objects);
HalfEdge::new(vertices, global_form)
}
}
impl MergeWith for PartialHalfEdge {
fn merge_with(self, other: impl Into<Self>) -> Self {
let other = other.into();
Self {
vertices: self.vertices.merge_with(other.vertices),
global_form: self.global_form.merge_with(other.global_form),
}
}
}
impl Replace<Surface> for PartialHalfEdge {
fn replace(&mut self, surface: Handle<Surface>) -> &mut Self {
for vertex in &mut self.vertices {
vertex.replace(surface.clone());
}
self
}
}
impl From<&HalfEdge> for PartialHalfEdge {
fn from(half_edge: &HalfEdge) -> Self {
let [back_vertex, front_vertex] =
half_edge.vertices().clone().map(Into::into);
Self {
vertices: [back_vertex, front_vertex],
global_form: half_edge.global_form().clone().into(),
}
}
}
#[derive(Clone, Debug, Default)]
pub struct PartialGlobalEdge {
pub curve: MaybePartial<GlobalCurve>,
pub vertices: [MaybePartial<GlobalVertex>; 2],
}
impl PartialGlobalEdge {
pub fn build(self, objects: &mut Service<Objects>) -> GlobalEdge {
let curve = self.curve.into_full(objects);
let vertices = self
.vertices
.map(|global_vertex| global_vertex.into_full(objects));
GlobalEdge::new(curve, vertices)
}
}
impl MergeWith for PartialGlobalEdge {
fn merge_with(self, other: impl Into<Self>) -> Self {
let other = other.into();
Self {
curve: self.curve.merge_with(other.curve),
vertices: self.vertices.merge_with(other.vertices),
}
}
}
impl From<&GlobalEdge> for PartialGlobalEdge {
fn from(global_edge: &GlobalEdge) -> Self {
Self {
curve: global_edge.curve().clone().into(),
vertices: global_edge
.vertices()
.access_in_normalized_order()
.map(Into::into),
}
}
}