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
use fj_math::{Point, Scalar, Vector};
use crate::{
objects::{Curve, GlobalCurve, Surface},
path::SurfacePath,
stores::{Handle, HandleWrapper, Stores},
};
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct PartialCurve {
pub path: Option<SurfacePath>,
pub surface: Option<Handle<Surface>>,
pub global_form: Option<HandleWrapper<GlobalCurve>>,
}
impl PartialCurve {
pub fn with_path(mut self, path: SurfacePath) -> Self {
self.path = Some(path);
self
}
pub fn with_surface(mut self, surface: Handle<Surface>) -> Self {
self.surface = Some(surface);
self
}
pub fn with_global_form(
mut self,
global_form: impl Into<HandleWrapper<GlobalCurve>>,
) -> Self {
self.global_form = Some(global_form.into());
self
}
pub fn as_u_axis(self) -> Self {
let a = Point::origin();
let b = a + Vector::unit_u();
self.as_line_from_points([a, b])
}
pub fn as_v_axis(self) -> Self {
let a = Point::origin();
let b = a + Vector::unit_v();
self.as_line_from_points([a, b])
}
pub fn as_circle_from_radius(self, radius: impl Into<Scalar>) -> Self {
self.with_path(SurfacePath::circle_from_radius(radius))
}
pub fn as_line_from_points(self, points: [impl Into<Point<2>>; 2]) -> Self {
self.with_path(SurfacePath::line_from_points(points))
}
pub fn build(self, stores: &Stores) -> Curve {
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
.unwrap_or_else(|| GlobalCurve::new(stores).into());
Curve::new(surface, path, global_form)
}
}
impl From<&Curve> for PartialCurve {
fn from(curve: &Curve) -> Self {
Self {
path: Some(curve.path()),
surface: Some(curve.surface().clone()),
global_form: Some(curve.global_form().clone().into()),
}
}
}