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
use crate::{
    geometry::path::SurfacePath,
    objects::{Curve, GlobalCurve, Objects, Surface},
    partial::{FullToPartialCache, Partial, PartialObject},
    services::Service,
};

/// A partial [`Curve`]
#[derive(Clone, Debug)]
pub struct PartialCurve {
    /// The path that defines the curve
    pub path: Option<SurfacePath>,

    /// The surface the curve is defined in
    pub surface: Partial<Surface>,

    /// The global form of the curve
    pub global_form: Partial<GlobalCurve>,
}

impl PartialCurve {
    /// Construct an instance of `PartialCurve`
    pub fn new(
        path: Option<SurfacePath>,
        surface: Option<Partial<Surface>>,
        global_form: Option<Partial<GlobalCurve>>,
    ) -> Self {
        let surface = surface.unwrap_or_default();
        let global_form = global_form.unwrap_or_default();

        Self {
            path,
            surface,
            global_form,
        }
    }
}

impl PartialObject for PartialCurve {
    type Full = Curve;

    fn from_full(curve: &Self::Full, cache: &mut FullToPartialCache) -> Self {
        Self::new(
            Some(curve.path()),
            Some(Partial::from_full(curve.surface().clone(), cache)),
            Some(Partial::from_full(curve.global_form().clone(), cache)),
        )
    }

    fn build(self, objects: &mut Service<Objects>) -> Self::Full {
        let path = self.path.expect("Need path to build curve");
        let surface = self.surface.build(objects);
        let global_form = self.global_form.build(objects);

        Curve::new(surface, path, global_form)
    }
}

impl Default for PartialCurve {
    fn default() -> Self {
        Self::new(None, None, None)
    }
}

/// A partial [`GlobalCurve`]
#[derive(Clone, Debug)]
pub struct PartialGlobalCurve;

impl PartialGlobalCurve {
    /// Construct an instance of `PartialGlobalCurve`
    pub fn new() -> Self {
        Self
    }
}

impl PartialObject for PartialGlobalCurve {
    type Full = GlobalCurve;

    fn from_full(_: &Self::Full, _: &mut FullToPartialCache) -> Self {
        Self::new()
    }

    fn build(self, _: &mut Service<Objects>) -> Self::Full {
        GlobalCurve
    }
}

impl Default for PartialGlobalCurve {
    fn default() -> Self {
        Self::new()
    }
}