-
Notifications
You must be signed in to change notification settings - Fork 1
/
egui.rs
60 lines (47 loc) · 1.39 KB
/
egui.rs
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
use egui::{epaint, pos2, Color32, Shape, Stroke};
use crate::{drawing_primitives::CircleArc, math::Circle};
/// Draw arcs as Bezier curves using `kurbo`
pub fn egui_draw_arc(painter: &egui::Painter, arc: CircleArc, stroke: &Stroke) {
let CircleArc {
circle,
start: start_f,
lenght,
} = arc;
let Circle { center, radius } = circle;
let center = kurbo::Point {
x: center.x as f64,
y: center.y as f64,
};
let start = center
+ kurbo::Vec2 {
x: radius * start_f.0.cos(),
y: radius * start_f.0.sin(),
};
let p = kurbo::Arc {
center: center,
radii: kurbo::Vec2 {
x: radius,
y: radius,
},
start_angle: start_f.0,
sweep_angle: lenght.0,
x_rotation: 0.0,
};
let mut p_start = pos2(start.x as f32, start.y as f32);
p.to_cubic_beziers(0.01, |x, y, z| {
if x.is_nan() {
return;
// panic!("nan");
}
let p1 = pos2(x.x as f32, x.y as f32);
let p2 = pos2(y.x as f32, y.y as f32);
let p3 = pos2(z.x as f32, z.y as f32);
painter.add(Shape::CubicBezier(epaint::CubicBezierShape {
points: [p_start, p1, p2, p3],
closed: false,
fill: Color32::TRANSPARENT,
stroke: *stroke,
}));
p_start = p3;
});
}