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
use fj_math::Scalar;
use crate::{
geometry::path::SurfacePath,
objects::{Curve, GlobalCurve, Objects, Surface},
partial::{FullToPartialCache, Partial, PartialObject},
services::Service,
};
#[derive(Clone, Debug, Default)]
pub struct PartialCurve {
pub path: Option<MaybeSurfacePath>,
pub surface: Partial<Surface>,
pub global_form: Partial<GlobalCurve>,
}
impl PartialObject for PartialCurve {
type Full = Curve;
fn from_full(curve: &Self::Full, cache: &mut FullToPartialCache) -> Self {
Self {
path: Some(curve.path().into()),
surface: Partial::from_full(curve.surface().clone(), cache),
global_form: Partial::from_full(curve.global_form().clone(), cache),
}
}
fn build(self, objects: &mut Service<Objects>) -> Self::Full {
let path = match self.path.expect("Need path to build curve") {
MaybeSurfacePath::Defined(path) => path,
undefined => {
panic!(
"Trying to build curve with undefined path: {undefined:?}"
)
}
};
let surface = self.surface.build(objects);
let global_form = self.global_form.build(objects);
Curve::new(surface, path, global_form)
}
}
#[derive(Clone, Debug)]
pub enum MaybeSurfacePath {
Defined(SurfacePath),
UndefinedCircle {
radius: Scalar,
},
UndefinedLine,
}
impl From<SurfacePath> for MaybeSurfacePath {
fn from(path: SurfacePath) -> Self {
Self::Defined(path)
}
}
#[derive(Clone, Debug, Default)]
pub struct PartialGlobalCurve;
impl PartialObject for PartialGlobalCurve {
type Full = GlobalCurve;
fn from_full(_: &Self::Full, _: &mut FullToPartialCache) -> Self {
Self
}
fn build(self, _: &mut Service<Objects>) -> Self::Full {
GlobalCurve
}
}