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
use fj_math::Point;
use crate::{
objects::{Curve, GlobalCurve, GlobalEdge, Surface, SurfaceVertex, Vertex},
stores::{Handle, Stores},
};
use super::{HasPartial, Partial};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum MaybePartial<T: HasPartial> {
Full(T),
Partial(T::Partial),
}
impl<T: HasPartial> MaybePartial<T> {
pub fn update_partial(
self,
f: impl FnOnce(T::Partial) -> T::Partial,
) -> Self {
match self {
Self::Partial(partial) => Self::Partial(f(partial)),
_ => self,
}
}
pub fn into_full(self, stores: &Stores) -> T {
match self {
Self::Partial(partial) => partial.build(stores),
Self::Full(full) => full,
}
}
pub fn into_partial(self) -> T::Partial {
match self {
Self::Partial(partial) => partial,
Self::Full(full) => full.to_partial(),
}
}
}
impl<T> From<T> for MaybePartial<T>
where
T: HasPartial,
{
fn from(full: T) -> Self {
Self::Full(full)
}
}
impl MaybePartial<Curve> {
pub fn global_form(&self) -> Option<Handle<GlobalCurve>> {
match self {
Self::Full(full) => Some(full.global_form().clone()),
Self::Partial(partial) => {
partial.global_form.clone().map(Into::into)
}
}
}
}
impl MaybePartial<GlobalEdge> {
pub fn curve(&self) -> Option<&Handle<GlobalCurve>> {
match self {
Self::Full(full) => Some(full.curve()),
Self::Partial(partial) => {
partial.curve.as_ref().map(|wrapper| &wrapper.0)
}
}
}
}
impl MaybePartial<SurfaceVertex> {
pub fn position(&self) -> Option<Point<2>> {
match self {
Self::Full(full) => Some(full.position()),
Self::Partial(partial) => partial.position,
}
}
pub fn surface(&self) -> Option<&Handle<Surface>> {
match self {
Self::Full(full) => Some(full.surface()),
Self::Partial(partial) => partial.surface.as_ref(),
}
}
}
impl MaybePartial<Vertex> {
pub fn surface_form(&self) -> Option<MaybePartial<SurfaceVertex>> {
match self {
Self::Full(full) => Some(full.surface_form().clone().into()),
Self::Partial(partial) => partial.surface_form.clone(),
}
}
}