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
use fj_math::{Circle, Line, Point, Scalar, Vector};
use crate::objects::{
Curve, CurveKind, Edge, GlobalCurve, GlobalVertex, Surface, Vertex,
VerticesOfEdge,
};
pub struct EdgeBuilder;
impl EdgeBuilder {
pub fn circle_from_radius(&self, radius: Scalar) -> Edge {
let curve_local = CurveKind::Circle(Circle::new(
Point::origin(),
Vector::from([radius, Scalar::ZERO]),
Vector::from([Scalar::ZERO, radius]),
));
let curve_global =
GlobalCurve::from_kind(CurveKind::Circle(Circle::new(
Point::origin(),
Vector::from([radius, Scalar::ZERO, Scalar::ZERO]),
Vector::from([Scalar::ZERO, radius, Scalar::ZERO]),
)));
Edge::from_curve_and_vertices(
Curve::new(curve_local, curve_global),
VerticesOfEdge::none(),
)
}
pub fn line_segment_from_points(
&self,
surface: &Surface,
points: [impl Into<Point<2>>; 2],
) -> Edge {
let points = points.map(Into::into);
let global_vertices = points.map(|position| {
let position = surface.point_from_surface_coords(position);
GlobalVertex::from_position(position)
});
let curve = {
let curve_local = CurveKind::Line(Line::from_points(points));
let curve_global = {
let points = global_vertices
.map(|global_vertex| global_vertex.position());
let kind = CurveKind::Line(Line::from_points(points));
GlobalCurve::from_kind(kind)
};
Curve::new(curve_local, curve_global)
};
let vertices = {
let [a, b] = global_vertices;
let vertices = [
Vertex::new(Point::from([0.]), a),
Vertex::new(Point::from([1.]), b),
];
VerticesOfEdge::from_vertices(vertices)
};
Edge::from_curve_and_vertices(curve, vertices)
}
}