Skip to content

Commit

Permalink
Use optimized output points for graph display
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Jul 24, 2024
1 parent 84ae0ed commit 75aed84
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl eframe::App for RawaccelConvertGui {

egui::CentralPanel::default().show(ctx, |ui| {
let plot_accel_args = self.accel_args.clone();
let plot_max_range = (plot_accel_args.dpi.clone() / 20) as f64;
let plot_points = self.curvegen.points.clone();
let mut plot = egui_plot::Plot::new("lines_demo")
.legend(egui_plot::Legend::default())
.show_axes(true)
Expand All @@ -363,16 +363,7 @@ impl eframe::App for RawaccelConvertGui {
let bounds = get_bounds(&plot_accel_args);
plot_ui.set_plot_bounds(egui_plot::PlotBounds::from_min_max(bounds.0, bounds.1));
plot_ui.line(
egui_plot::Line::new(egui_plot::PlotPoints::from_explicit_callback(
move |x| {
if x < 0.0 {
return 0.0;
}
get_point(x, &plot_accel_args)
},
0.0..plot_max_range,
self.accel_args.point_count as usize,
))
egui_plot::Line::new(egui_plot::PlotPoints::new(convert_points(plot_points)))
.color(egui::Color32::from_rgb(100, 100, 200))
.style(egui_plot::LineStyle::Solid),
);
Expand All @@ -382,6 +373,14 @@ impl eframe::App for RawaccelConvertGui {
}
}

fn convert_points(points: Vec<rawaccel_convert::types::Point>) -> Vec<[f64; 2]> {
let mut egui_points = vec![];
for point in points {
egui_points.push([point.x, point.y]);
}
return egui_points;
}

fn get_point(x: f64, args: &AccelArgs) -> f64 {
let y = args.sens_multiplier
* match &args.mode {
Expand Down

0 comments on commit 75aed84

Please sign in to comment.