-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Plot refactor #331
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
Plot refactor #331
Conversation
Co-authored-by: ilya sheprut <[email protected]>
* add curve from function * move more functionality into ScreenTransform struct
|
Since I created some new files it's difficult to see what's changed, so here's a quick overview:
|
emilk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice improvements and cleanups!
I left some comments, mainly:
- keep the
plotname so we don't need to introduce a breaking change a - keep old functions with a deprecation notice
- remove
Parametrictype and compute its values right away
egui/src/widgets/plotting/items.rs
Outdated
| let range_union = |range1: &RangeInclusive<f64>, range2: &RangeInclusive<f64>| { | ||
| range1.start().max(*range2.start())..=range1.end().min(*range2.end()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the intersection; not the union
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would also be better as fn instead of a lambda, since it doesn't capture anything.
egui/src/widgets/plotting/plot.rs
Outdated
| /// ``` | ||
| /// # let ui = &mut egui::Ui::__test(); | ||
| /// use egui::plot::{Curve, Plot, Value}; | ||
| /// use egui::plotting::{Curve, Plot, Value}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rename will be a breaking change for users. I think we should just call the module plot instead to avoid this.
| pub fn include_y(mut self, y: impl Into<f64>) -> Self { | ||
| self.min_auto_bounds.extend_with_y(y.into()); | ||
| self | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the diff becomes harder to read when moving around code like this. what is the motivation?
|
|
||
| /// If true, the x-bounds will be symmetrical, so that the x=0 zero line | ||
| /// is always in the center. | ||
| pub fn symmetrical_x_bounds(mut self, symmetrical_x_bounds: bool) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the new name (center_x_axis) is better, but keep the old function with an added #[deprecated = "Renamed center_x_axis"]
egui/src/widgets/plotting/plot.rs
Outdated
| self.bounds.min[1]..=self.bounds.max[1], | ||
| (self.rect.bottom() as f64)..=(self.rect.top() as f64), // negated y axis! | ||
| // Initialize values from functions. | ||
| // TODO: Let the user pick a resolution? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The from_explicit_callback and from_parametric_callback already does, so this TODO is done?
| .center_x_axis(false) | ||
| .center_y_axis(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the default
| .center_x_axis(false) | |
| .center_y_axis(false) |
| let time = self.time; | ||
| Curve::from_explicit_callback( | ||
| move |x| 0.5 * (2.0 * x).sin() * time.sin(), | ||
| Some((-2.)..=2.), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be a good demo for sin to span -INF..=INF
egui/src/widgets/plotting/items.rs
Outdated
| /// Describes a function y = f(x) with an optional range for x and a number of points. | ||
| Explicit(Box<dyn Fn(f64) -> f64>, Option<RangeInclusive<f64>>, usize), | ||
| /// Describes a function (x,y) = f(t) with a range for t and a number of points. | ||
| Parametric(Box<dyn Fn(f64) -> (f64, f64)>, RangeInclusive<f64>, usize), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Describes a function y = f(x) with an optional range for x and a number of points. | |
| Explicit(Box<dyn Fn(f64) -> f64>, Option<RangeInclusive<f64>>, usize), | |
| /// Describes a function (x,y) = f(t) with a range for t and a number of points. | |
| Parametric(Box<dyn Fn(f64) -> (f64, f64)>, RangeInclusive<f64>, usize), | |
| /// Describes a function y = f(x) with a range for x and a number of points. | |
| Explicit{ | |
| y_from_x: Box<dyn Fn(f64) -> f64>, | |
| x_range: RangeInclusive<f64>, | |
| resolution: usize, | |
| }, | |
| /// Describes a function (x,y) = f(t) with a range for t and a number of points. | |
| Parametric{ | |
| xy_from_t: Box<dyn Fn(f64) -> (f64, f64)>, | |
| t_range: RangeInclusive<f64>, | |
| resolution: usize | |
| }, |
I see no difference between None range and an -INF..=INF range, so better to unify to the simpler type
egui/src/widgets/plotting/items.rs
Outdated
| t_range: RangeInclusive<f64>, | ||
| points: usize, | ||
| ) -> Self { | ||
| let generator = Generator::Parametric(Box::new(function), t_range, points); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parametric function always computes all the points, so there is not reason to defer that computation to later as far as I can tell.
If you compute values here instead and pass to Self::from_values we get default bounds and also a speedup, because function doesn't need to be boxed (and doesn't need to be 'static either)
|
Thanks for the review! I agree with your suggestions and made all the changes in 2abfb0f. The remaining commits are just the filename changes. |
Co-authored-by: Emil Ernerfeldt <[email protected]>
|
Thanks! |
Closes #330