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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use fj_math::{Point, Scalar, Vector};
use crate::{
objects::{Curve, GlobalCurve, Surface},
path::{GlobalPath, SurfacePath},
stores::{Handle, Stores},
};
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct PartialCurve {
pub path: Option<SurfacePath>,
pub surface: Option<Surface>,
pub global_form: Option<Handle<GlobalCurve>>,
}
impl PartialCurve {
pub fn with_path(mut self, path: SurfacePath) -> Self {
self.path = Some(path);
self
}
pub fn with_surface(mut self, surface: Surface) -> Self {
self.surface = Some(surface);
self
}
pub fn with_global_form(
mut self,
global_form: Handle<GlobalCurve>,
) -> Self {
self.global_form = Some(global_form);
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(|| {
let path = match path {
SurfacePath::Circle(circle) => {
GlobalPath::circle_from_radius(circle.radius())
}
SurfacePath::Line(line) => GlobalPath::line_from_points(
[line.origin(), line.origin() + line.direction()]
.map(|point| surface.point_from_surface_coords(point)),
),
};
GlobalCurve::partial().with_path(path).build(stores)
});
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()),
global_form: Some(curve.global_form().clone()),
}
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct PartialGlobalCurve {
pub path: Option<GlobalPath>,
}
impl PartialGlobalCurve {
pub fn with_path(mut self, path: GlobalPath) -> Self {
self.path = Some(path);
self
}
pub fn as_x_axis(self) -> Self {
self.with_path(GlobalPath::x_axis())
}
pub fn as_y_axis(self) -> Self {
self.with_path(GlobalPath::y_axis())
}
pub fn as_z_axis(self) -> Self {
self.with_path(GlobalPath::z_axis())
}
pub fn as_circle_from_radius(self, radius: impl Into<Scalar>) -> Self {
self.with_path(GlobalPath::circle_from_radius(radius))
}
pub fn as_line_from_points(self, points: [impl Into<Point<3>>; 2]) -> Self {
self.with_path(GlobalPath::line_from_points(points))
}
pub fn build(self, stores: &Stores) -> Handle<GlobalCurve> {
let path = self.path.expect("Can't build `GlobalCurve` without a path");
stores.global_curves.insert(GlobalCurve::from_path(path))
}
}
impl From<Handle<GlobalCurve>> for PartialGlobalCurve {
fn from(global_curve: Handle<GlobalCurve>) -> Self {
Self {
path: Some(global_curve.path()),
}
}
}