-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gpui: Add move_to
method to Path
#22808
base: main
Are you sure you want to change the base?
Conversation
move_to
method to Path
.move_to
method to Path
Also see JakkuSakura/plotters-gpui#2 Previously, GPUI's Path did not have some algorithms for stroke, so we needed to do some complex calculations ourselves. As shown in the figure above, the calculations were actually wrong, and the lines in some directions were not drawn correctly. For example the let (Some(first), Some(last)) = (self.points.first().copied(), self.points.last().copied())
else {
return;
};
let mut angle = f32::atan2(first.y.0 - last.y.0, first.x.0 - last.x.0);
angle += std::f32::consts::FRAC_PI_2;
let shift = point(width * f32::cos(angle), width * f32::sin(angle));
let mut reversed_points = vec![first + shift];
let mut path = Path::new(first);
for &p in &self.points[1..] {
path.line_to(p);
reversed_points.push(p + shift);
}
// now do the reverse to close the path
for p in reversed_points.into_iter().rev() {
path.line_to(p);
}
cx.paint_path(path, self.color); If we can introduce something like tiny-skia, relying on the algorithms they provide, we can simplify this process. The new version by Of course, this is actually two things. First, GPUI's Path lacks cc @JakkuSakura |
After this merged, the next thing we can push to enable anti-aliasing. Recently Blade have this support: kvark/blade#213, cc @kvark |
Thanks for pointing out. The algorithm was written so for lacking such stroking algo and for performance consideration |
@huacnlee and @JakkuSakura : If we wanted to animate a graph showing the performance of a program, how much of an impact would it have on the Registrazione.schermo.2025-01-08.alle.09.33.56.mov |
NO! Animate is not have extract RAM, at least not a very noticeable difference. |
Release Notes:
Continue #20499
We need this to draw Path. Before this change, we only have
line_to
, but it is not enough.Show case
To draw a stroke line is not just to
line_to
, there need to consider the angle to get shift to draw next point. GPUI have not yet provided this things, but the 3rd-library are have.For example use tiny-skia:
Before version: