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
use crate::{
geometry::path::SurfacePath,
objects::{Curve, GlobalCurve, Objects, Surface},
partial::{MaybePartial, MergeWith},
storage::Handle,
validate::ValidationError,
};
#[derive(Clone, Debug, Default)]
pub struct PartialCurve {
pub path: Option<SurfacePath>,
pub surface: Option<Handle<Surface>>,
pub global_form: MaybePartial<GlobalCurve>,
}
impl PartialCurve {
pub fn build(self, objects: &Objects) -> Result<Curve, ValidationError> {
let path = self.path.expect("Can't build `Curve` without path");
let surface =
self.surface.expect("Can't build `Curve` without surface");
let global_form = self.global_form.into_full(objects)?;
Ok(Curve::new(surface, path, global_form))
}
}
impl MergeWith for PartialCurve {
fn merge_with(self, other: impl Into<Self>) -> Self {
let other = other.into();
Self {
path: self.path.merge_with(other.path),
surface: self.surface.merge_with(other.surface),
global_form: self.global_form.merge_with(other.global_form),
}
}
}
impl From<&Curve> for PartialCurve {
fn from(curve: &Curve) -> Self {
Self {
path: Some(curve.path()),
surface: Some(curve.surface().clone()),
global_form: curve.global_form().clone().into(),
}
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct PartialGlobalCurve;
impl PartialGlobalCurve {
pub fn build(self, _: &Objects) -> Result<GlobalCurve, ValidationError> {
Ok(GlobalCurve)
}
}
impl MergeWith for PartialGlobalCurve {
fn merge_with(self, _: impl Into<Self>) -> Self {
Self
}
}
impl From<&GlobalCurve> for PartialGlobalCurve {
fn from(_: &GlobalCurve) -> Self {
Self
}
}