Skip to content

Commit

Permalink
Make sure base_step_size is always positive
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 26, 2024
1 parent e38b477 commit 51a49e3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/egui_plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,15 +1147,15 @@ impl Plot {
let x_steps = Arc::new({
let input = GridInput {
bounds: (bounds.min[0], bounds.max[0]),
base_step_size: transform.dvalue_dpos()[0] * MIN_LINE_SPACING_IN_POINTS * 2.0,
base_step_size: transform.dvalue_dpos()[0].abs() * MIN_LINE_SPACING_IN_POINTS * 2.0,
};
(grid_spacers[0])(input)
});
let y_axis_range = bounds.range_y();
let y_steps = Arc::new({
let input = GridInput {
bounds: (bounds.min[1], bounds.max[1]),
base_step_size: transform.dvalue_dpos()[1] * MIN_LINE_SPACING_IN_POINTS * 2.0,
base_step_size: transform.dvalue_dpos()[1].abs() * MIN_LINE_SPACING_IN_POINTS * 2.0,
};
(grid_spacers[1])(input)
});
Expand Down Expand Up @@ -1582,6 +1582,8 @@ pub struct GridInput {
///
/// Computed as the ratio between the diagram's bounds (in plot coordinates) and the viewport
/// (in frame/window coordinates), scaled up to represent the minimal possible step.
///
/// Always positive.
pub base_step_size: f64,
}

Expand Down Expand Up @@ -1764,7 +1766,7 @@ impl PreparedPlot {

let input = GridInput {
bounds: (bounds.min[iaxis], bounds.max[iaxis]),
base_step_size: transform.dvalue_dpos()[iaxis] * fade_range.min as f64,
base_step_size: transform.dvalue_dpos()[iaxis].abs() * fade_range.min as f64,
};
let steps = (grid_spacers[iaxis])(input);

Expand Down

0 comments on commit 51a49e3

Please sign in to comment.