Slightly improve stability by using smaller values

This commit is contained in:
ClementTsang 2025-04-14 01:10:52 -04:00
parent a73e21d617
commit 8defa968e6
No known key found for this signature in database
GPG Key ID: DC3B7867D8D97095
2 changed files with 2 additions and 35 deletions

View File

@ -230,7 +230,7 @@ mod test {
fn create_time_graph() -> TimeGraph<'static> {
TimeGraph {
title: " Network ".into(),
x_min: -15000.0,
x_min: -15.0,
hide_x_labels: false,
y_bounds: AxisBound::Max(100.5),
y_labels: &Y_LABELS,
@ -254,7 +254,7 @@ mod test {
let x_axis = tg.generate_x_axis();
let actual = Axis::default()
.bounds(AxisBound::Min(-15000.0))
.bounds(AxisBound::Min(-15.0))
.labels(vec![Span::styled("15s", style), Span::styled("0s", style)])
.style(style);
assert_eq!(x_axis.bounds, actual.bounds);

View File

@ -71,39 +71,6 @@ impl Shape for CanvasLine {
} else {
draw_line_high(painter, x1, y1, x2, y2, self.color);
}
draw_line(painter, x1, y1, x2, y2, self.color);
}
}
/// Based on <https://github.com/gizak/termui/blob/master/drawille/drawille.go>
fn draw_line(
painter: &mut Painter<'_, '_>, x1: usize, y1: usize, x2: usize, y2: usize, colour: Color,
) {
let (left_point, right_point) = if x1 < x2 {
((x1, y1), (x2, y2))
} else {
((x2, y2), (x1, y1))
};
let dx = (left_point.0 as isize - right_point.0 as isize).abs();
let dy = (left_point.1 as isize - right_point.1 as isize).abs();
let slope = dy as f64 / dx as f64;
let slope_sign: isize = if left_point.1 < right_point.1 { 1 } else { -1 };
let mut target_y = left_point.1 as f64;
let mut current_y = left_point.1 as isize;
for current_x in (left_point.0)..(right_point.0) {
painter.paint(current_x, current_y as usize, colour);
target_y += slope * slope_sign as f64;
while current_y != target_y as isize && current_y >= 0 {
painter.paint(current_x, current_y as usize, colour);
current_y += slope_sign;
}
}
}